Module: RightScale::CommandClient::ConnectionHandler
- Defined in:
- lib/right_agent/command/command_client.rb
Overview
EventMachine connection handler which sends command to agent and waits for response
Instance Method Summary collapse
-
#initialize(command, client, callback) ⇒ Object
Initialize command.
-
#post_init ⇒ Object
Send command to agent Called by EventMachine after connection with agent has been established.
-
#receive_data(data) ⇒ Object
Handle agent response.
Instance Method Details
#initialize(command, client, callback) ⇒ Object
Initialize command
Parameters
- command(Hash)
-
Command to be sent
- client(RightScale::CommandClient)
-
Client whose response field should be initialized
- callback(Proc)
-
Called back after response has been set
110 111 112 113 114 115 116 117 |
# File 'lib/right_agent/command/command_client.rb', line 110 def initialize(command, client, callback) @command = command @parser = CommandParser.new do |data| close_connection client.response = data callback.call end end |
#post_init ⇒ Object
Send command to agent Called by EventMachine after connection with agent has been established
Return
- true
-
Always return true
124 125 126 127 128 |
# File 'lib/right_agent/command/command_client.rb', line 124 def post_init puts "Sending command #{@command.inspect}" if @command[:verbose] send_data(CommandSerializer.dump(@command)) true end |
#receive_data(data) ⇒ Object
Handle agent response
131 132 133 |
# File 'lib/right_agent/command/command_client.rb', line 131 def receive_data(data) @parser.parse_chunk(data) end |