Class: Noah::Agent
Constant Summary collapse
Instance Method Summary collapse
- #broker(msg) ⇒ Object
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
- #reread_watchers ⇒ Object
- #watchers ⇒ Object
Constructor Details
#initialize ⇒ Agent
Returns a new instance of Agent.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/noah/agent.rb', line 26 def initialize @logger = Noah::Log.logger @logger.progname = self.class.name @logger.debug("Initializing with #{@@watchers.size} registered watches") @logger.debug("#{@@agents} agents registered") if EventMachine.reactor_running? #instantiate_agents! @logger.info("Started up!") else @logger.fatal("Must be inside a reactor!") end end |
Instance Method Details
#broker(msg) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/noah/agent.rb', line 50 def broker(msg) e,m = msg.split("|") EM::Iterator.new(@@agents, @@agents.size).each do |agent, iter| #a = agent.to_s.gsub(/::/,'_').downcase x = agent.send(:new) begin #self.instance_variable_get("@#{a}").send(:notify, e, m, @@watchers) x.notify(e, m, @@watchers.clone) iter.next rescue Exception => e @logger.error("#{agent.to_s} invocation failed with #{e.}") end end end |
#reread_watchers ⇒ Object
43 44 45 46 47 48 |
# File 'lib/noah/agent.rb', line 43 def reread_watchers @logger.info("Found new watches") @logger.debug("Current watch count: #{@@watchers.size}") @@watchers = Noah::Watcher.watch_list @logger.debug("New watch count: #{@@watchers.size}") end |
#watchers ⇒ Object
39 40 41 |
# File 'lib/noah/agent.rb', line 39 def watchers @@watchers.size end |