Class: Baykit::BayServer::Agent::CommandReceiver
- Inherits:
-
Object
- Object
- Baykit::BayServer::Agent::CommandReceiver
- Includes:
- Util
- Defined in:
- lib/baykit/bayserver/agent/command_receiver.rb
Overview
CommandReceiver receives commands from GrandAgentMonitor
Instance Attribute Summary collapse
-
#aborted ⇒ Object
readonly
Returns the value of attribute aborted.
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#communication_channel ⇒ Object
readonly
Returns the value of attribute communication_channel.
Instance Method Summary collapse
- #close ⇒ Object
- #end ⇒ Object
-
#initialize(agent, com_ch) ⇒ CommandReceiver
constructor
A new instance of CommandReceiver.
- #on_pipe_readable ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(agent, com_ch) ⇒ CommandReceiver
Returns a new instance of CommandReceiver.
16 17 18 19 20 |
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 16 def initialize(agent, com_ch) @agent = agent @communication_channel = com_ch @aborted = false end |
Instance Attribute Details
#aborted ⇒ Object (readonly)
Returns the value of attribute aborted.
14 15 16 |
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 14 def aborted @aborted end |
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
12 13 14 |
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 12 def agent @agent end |
#communication_channel ⇒ Object (readonly)
Returns the value of attribute communication_channel.
13 14 15 |
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 13 def communication_channel @communication_channel end |
Instance Method Details
#close ⇒ Object
68 69 70 |
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 68 def close() @communication_channel.close() end |
#end ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 58 def end() BayLog.debug("%s end", self) begin IOUtil.write_int32(@communication_channel, GrandAgent::CMD_CLOSE) rescue => e BayLog.error_e(e, "%s Write error", @agent); end close() end |
#on_pipe_readable ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 26 def on_pipe_readable() cmd = IOUtil.read_int32(@communication_channel) if cmd == nil BayLog.debug("%s pipe closed: %d", self, @communication_channel) @agent.abort_agent() else BayLog.debug("%s receive command %d pipe=%d", self, cmd, @communication_channel) begin case cmd when GrandAgent::CMD_RELOAD_CERT @agent.reload_cert() when GrandAgent::CMD_MEM_USAGE @agent.print_usage() when GrandAgent::CMD_SHUTDOWN @agent.shutdown() @aborted = true when GrandAgent::CMD_ABORT IOUtil.write_int32(@communication_channel, GrandAgent::CMD_OK) @agent.abort_agent() return else BayLog.error("Unknown command: %d", cmd) end IOUtil.write_int32(@communication_channel, GrandAgent::CMD_OK) rescue IOError => e BayLog.debug("%s Read failed (maybe agent shut down): %s", self, e) ensure BayLog.debug("%s Command ended", self) end end end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/baykit/bayserver/agent/command_receiver.rb', line 22 def to_s() return "ComReceiver##{@agent.agent_id}" end |