Commit c8153fcf authored by John E. Vincent's avatar John E. Vincent

more modularization on agent framework

parent c546fc73
require 'rubygems' require 'rubygems'
require File.join('.', 'lib','noah') require File.join('.', 'lib','noah')
## Uncomment the following to hardcode a redis url ## Uncomment the following to hardcode a redis url
ENV['REDIS_URL'] = "redis://localhost:6379/1" ENV['REDIS_URL'] = "redis://localhost:6379/0"
noah = Noah::App.new noah = Noah::App.new
run noah run noah
...@@ -9,9 +9,6 @@ module Noah ...@@ -9,9 +9,6 @@ module Noah
class Agent class Agent
include EM::Deferrable include EM::Deferrable
Noah::Agents::HttpAgent.register
Noah::Agents::DummyAgent.register
@@watchers = Noah::Watcher.watch_list @@watchers = Noah::Watcher.watch_list
@@agents = Noah::Watchers.agents @@agents = Noah::Watchers.agents
......
require 'logger'
require 'logger'
module Noah::Agents
module Base
class << self
include EM::Deferrable
PREFIX = "base"
NAME = "base-agent"
end
def self.included(base)
Noah::Watchers.register_agent(base)
end
end
end
require File.join(File.dirname(__FILE__), 'base_agent')
module Noah::Agents module Noah::Agents
class DummyAgent class DummyAgent
include EM::Deferrable include Noah::Agents::Base
PREFIX = "dummy" PREFIX = "dummy"
NAME = "dummy" NAME = "dummy"
def self.register
Noah::Watchers.register_agent(self)
end
def self.notify(event, message, watch_list) def self.notify(event, message, watch_list)
logger = LOGGER logger = LOGGER
logger.info("#{NAME}: Worker initiated") logger.info("#{NAME}: Worker initiated")
...@@ -21,8 +19,8 @@ module Noah::Agents ...@@ -21,8 +19,8 @@ module Noah::Agents
logger.info("#{NAME}: Sending message to: #{ep} for pattern: #{p}") logger.info("#{NAME}: Sending message to: #{ep} for pattern: #{p}")
logger.debug("#{NAME}: message received: #{message}") logger.debug("#{NAME}: message received: #{message}")
end end
iter.next
end end
iter.next
end end
end end
......
require 'logger' require File.join(File.dirname(__FILE__), 'base_agent')
module Noah::Agents module Noah::Agents
class HttpAgent class HttpAgent
include EM::Deferrable include Noah::Agents::Base
PREFIX = "http" PREFIX = "http"
NAME = "http" NAME = "http"
def self.register
Noah::Watchers.register_agent(self)
end
def self.notify(event, message, watch_list) def self.notify(event, message, watch_list)
logger = LOGGER logger = LOGGER
logger.info("#{NAME}: Worker initiated") logger.info("#{NAME}: Worker initiated")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment