Class: Pantry::Client
- Inherits:
-
Object
- Object
- Pantry::Client
- Extended by:
- Forwardable
- Includes:
- Celluloid
- Defined in:
- lib/pantry/client.rb
Overview
The Pantry Client. The Client runs on any server that needs provisioning, and communicates to the Server through various channels. Clients can be further configured to manage an application, for a given environment, and across any number of roles.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#last_received_message ⇒ Object
readonly
For testing / debugging purposes, keep hold of the last message this client received.
Instance Method Summary collapse
-
#initialize(application: nil, environment: nil, roles: [], identity: nil, network_stack_class: Communication::Client) ⇒ Client
constructor
A new instance of Client.
-
#receive_file(file_size, file_checksum) ⇒ Object
See Pantry::Server#receive_file.
-
#receive_message(message) ⇒ Object
Callback from Networking when a message is received.
-
#run ⇒ Object
Start up the Client.
-
#send_file(file_path, receiver_uuid, file_uuid) ⇒ Object
See Pantry::Server#send_file.
-
#send_message(message) ⇒ Object
Send a Pantry::Message directly to its intended recipient.
-
#send_request(message) ⇒ Object
Send a Pantry::Message but mark it as requiring a response.
- #shutdown ⇒ Object
Constructor Details
#initialize(application: nil, environment: nil, roles: [], identity: nil, network_stack_class: Communication::Client) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pantry/client.rb', line 19 def initialize(application: nil, environment: nil, roles: [], identity: nil, network_stack_class: Communication::Client) @info = Pantry::ClientInfo.new( application: application, environment: environment, roles: roles || [], identity: identity || current_hostname ) @commands = CommandHandler.new(self, Pantry.client_commands) @networking = network_stack_class.new_link(self) end |
Instance Attribute Details
#last_received_message ⇒ Object (readonly)
For testing / debugging purposes, keep hold of the last message this client received
17 18 19 |
# File 'lib/pantry/client.rb', line 17 def @last_received_message end |
Instance Method Details
#receive_file(file_size, file_checksum) ⇒ Object
See Pantry::Server#receive_file
82 83 84 |
# File 'lib/pantry/client.rb', line 82 def receive_file(file_size, file_checksum) @networking.receive_file(file_size, file_checksum) end |
#receive_message(message) ⇒ Object
Callback from Networking when a message is received
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pantry/client.rb', line 48 def () Pantry.logger.debug("[#{identity}] Received message #{.inspect}") if () @last_received_message = results = @commands.process() if .requires_response? Pantry.logger.debug("[#{identity}] Responding with #{results.inspect}") send_results_back_to_requester(, results) end else Pantry.logger.debug("[#{identity}] Message discarded, not for us") end end |
#run ⇒ Object
Start up the Client. This sets up the appropriate communication channels to the server, sends a registration message so the Server knows who just connected, and then waits for information to come.
35 36 37 38 39 40 |
# File 'lib/pantry/client.rb', line 35 def run Pantry.set_proc_title("pantry client #{Pantry::VERSION} :: #{identity}") @networking.run Pantry.logger.info("[#{identity}] Client registered and waiting for commands") end |
#send_file(file_path, receiver_uuid, file_uuid) ⇒ Object
See Pantry::Server#send_file
87 88 89 |
# File 'lib/pantry/client.rb', line 87 def send_file(file_path, receiver_uuid, file_uuid) @networking.send_file(file_path, receiver_uuid, file_uuid) end |
#send_message(message) ⇒ Object
Send a Pantry::Message directly to its intended recipient. For a Client this is almost always the Server.
66 67 68 |
# File 'lib/pantry/client.rb', line 66 def () @networking.() end |
#send_request(message) ⇒ Object
Send a Pantry::Message but mark it as requiring a response. This will set up and return a Celluloid::Future that will contain the response once it is available.
73 74 75 76 77 78 79 |
# File 'lib/pantry/client.rb', line 73 def send_request() .requires_response! Pantry.logger.debug("[#{identity}] Sending request #{.inspect}") @networking.send_request() end |