Class: Vedeu::Distributed::Client
- Inherits:
-
Object
- Object
- Vedeu::Distributed::Client
- Defined in:
- lib/vedeu/distributed/client.rb
Overview
A class for the client side of the DRb server/client relationship.
Instance Attribute Summary collapse
- #uri ⇒ String readonly protected
Class Method Summary collapse
Instance Method Summary collapse
-
#connect ⇒ Symbol
Simulate connecting to the DRb server by requesting its status.
- #drb_connection_error ⇒ Symbol private
-
#initialize(uri) ⇒ Vedeu::Distributed::Client
constructor
Returns a new instance of Vedeu::Distributed::Client.
-
#input(data) ⇒ void|Symbol
(also: #read)
Send input to the DRb server.
-
#output ⇒ void|Symbol
(also: #write)
Fetch output from the DRb server.
- #server ⇒ void private
-
#shutdown ⇒ void|Symbol
Shutdown the DRb server and the client application.
Constructor Details
#initialize(uri) ⇒ Vedeu::Distributed::Client
Returns a new instance of Vedeu::Distributed::Client.
27 28 29 |
# File 'lib/vedeu/distributed/client.rb', line 27 def initialize(uri) @uri = uri.to_s end |
Instance Attribute Details
#uri ⇒ String (readonly, protected)
98 99 100 |
# File 'lib/vedeu/distributed/client.rb', line 98 def uri @uri end |
Class Method Details
.connect(uri) ⇒ Object
19 20 21 |
# File 'lib/vedeu/distributed/client.rb', line 19 def self.connect(uri) new(uri).connect end |
Instance Method Details
#connect ⇒ Symbol
Simulate connecting to the DRb server by requesting its status.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vedeu/distributed/client.rb', line 35 def connect server.status rescue DRb::DRbConnError drb_connection_error rescue DRb::DRbBadURI Vedeu.log_stdout(message: 'Could not connect to DRb server, URI may ' \ 'be bad.'.freeze) :drb_bad_uri end |
#drb_connection_error ⇒ Symbol (private)
108 109 110 111 112 |
# File 'lib/vedeu/distributed/client.rb', line 108 def drb_connection_error Vedeu.log_stdout(message: 'Could not connect to DRb server.'.freeze) :drb_connection_error end |
#input(data) ⇒ void|Symbol Also known as: read
Send input to the DRb server.
52 53 54 55 56 57 |
# File 'lib/vedeu/distributed/client.rb', line 52 def input(data) server.input(data) rescue DRb::DRbConnError drb_connection_error end |
#output ⇒ void|Symbol Also known as: write
Fetch output from the DRb server.
63 64 65 66 67 68 |
# File 'lib/vedeu/distributed/client.rb', line 63 def output server.output rescue DRb::DRbConnError drb_connection_error end |
#server ⇒ void (private)
This method returns an undefined value.
103 104 105 |
# File 'lib/vedeu/distributed/client.rb', line 103 def server @server ||= DRbObject.new_with_uri(uri) end |
#shutdown ⇒ void|Symbol
Note:
Runtime::Application will raise StopIteration when its ‘.stop` method is called. Here we rescue that to give a clean client exit.
Shutdown the DRb server and the client application.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vedeu/distributed/client.rb', line 79 def shutdown server.shutdown Process.kill('KILL', server.pid) rescue DRb::DRbConnError drb_connection_error rescue Interrupt Vedeu.log_stdout(message: 'Client application exited.'.freeze) ensure :shutdown end |