Class: Smith::Agency
- Inherits:
-
Object
- Object
- Smith::Agency
- Includes:
- Logger
- Defined in:
- lib/smith/application/agency.rb
Instance Attribute Summary collapse
-
#agent_processes ⇒ Object
readonly
Returns the value of attribute agent_processes.
-
#agents ⇒ Object
readonly
Returns the value of attribute agents.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Agency
constructor
A new instance of Agency.
- #setup_queues ⇒ Object
- #start_monitoring ⇒ Object
-
#stop(&blk) ⇒ Object
Stop the agency.
Methods included from Logger
Constructor Details
#initialize(opts = {}) ⇒ Agency
Returns a new instance of Agency.
16 17 18 |
# File 'lib/smith/application/agency.rb', line 16 def initialize(opts={}) @agent_processes = AgentCache.new end |
Instance Attribute Details
#agent_processes ⇒ Object (readonly)
Returns the value of attribute agent_processes.
14 15 16 |
# File 'lib/smith/application/agency.rb', line 14 def agent_processes @agent_processes end |
#agents ⇒ Object (readonly)
Returns the value of attribute agents.
14 15 16 |
# File 'lib/smith/application/agency.rb', line 14 def agents @agents end |
Instance Method Details
#setup_queues ⇒ Object
20 21 22 23 24 25 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 57 58 59 |
# File 'lib/smith/application/agency.rb', line 20 def setup_queues Messaging::Receiver.new(QueueDefinitions::Agency_control, :auto_ack => false) do |receiver| receiver.subscribe do |payload, responder| completion = EM::Completion.new.tap do |c| c.completion do |value| responder.ack responder.reply(Smith::ACL::AgencyCommandResponse.new(:response => value)) end end begin Command.run(payload.command, payload.args, :agency => self, :agents => @agent_processes, :responder => completion) rescue Command::UnknownCommandError => e responder.reply("Unknown command: #{payload.command}") end end end Messaging::Receiver.new(QueueDefinitions::Agent_lifecycle) do |receiver| receiver.subscribe do |payload, r| case payload when Smith::ACL::AgentDead dead(payload) when Smith::ACL::AgentAcknowledgeStart acknowledge_start(payload) when Smith::ACL::AgentAcknowledgeStop acknowledge_stop(payload) else logger.warn { "Unknown command received on #{QueueDefinitions::Agent_lifecycle.name} queue: #{payload.state}" } end end end Messaging::Receiver.new(QueueDefinitions::Agent_keepalive) do |receiver| receiver.subscribe do |payload, r| keep_alive(payload) end end end |
#start_monitoring ⇒ Object
61 62 63 64 |
# File 'lib/smith/application/agency.rb', line 61 def start_monitoring # @agent_monitor = AgentMonitoring.new(@agent_processes) # @agent_monitor.start_monitoring end |