Class: FrenzyBunnies::Context
- Inherits:
-
Object
- Object
- FrenzyBunnies::Context
- Defined in:
- lib/frenzy_bunnies/context.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#queue_factory ⇒ Object
readonly
Returns the value of attribute queue_factory.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Context
constructor
A new instance of Context.
- #run(*klasses) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Context
Returns a new instance of Context.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/frenzy_bunnies/context.rb', line 7 def initialize(opts={}) @opts = opts @opts[:host] ||= 'localhost' @opts[:exchange] ||= 'frenzy_bunnies' @opts[:heartbeat] ||= 5 @opts[:web_host] ||= 'localhost' @opts[:web_port] ||= 11333 @opts[:web_threadfilter] ||= /^pool-.*/ @opts[:env] ||= 'development' @env = @opts[:env] @logger = @opts[:logger] || Logger.new(STDOUT) @connection = HotBunnies.connect(:host => @opts[:host], :heartbeat_interval => @opts[:heartbeat]) @connection.add_shutdown_listener(lambda { |cause| @logger.error("Disconnected: #{cause}"); stop;}) @queue_factory = FrenzyBunnies::QueueFactory.new(@connection, @opts[:exchange]) end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/frenzy_bunnies/context.rb', line 5 def env @env end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/frenzy_bunnies/context.rb', line 5 def logger @logger end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
5 6 7 |
# File 'lib/frenzy_bunnies/context.rb', line 5 def opts @opts end |
#queue_factory ⇒ Object (readonly)
Returns the value of attribute queue_factory.
5 6 7 |
# File 'lib/frenzy_bunnies/context.rb', line 5 def queue_factory @queue_factory end |
Instance Method Details
#run(*klasses) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/frenzy_bunnies/context.rb', line 25 def run(*klasses) @klasses = [] klasses.each{|klass| klass.start(self); @klasses << klass} Thread.new do FrenzyBunnies::Web.run_with(@klasses, :host => @opts[:web_host], :port => @opts[:web_port], :threadfilter => @opts[:web_threadfilter], :logger => @logger) end end |
#stop ⇒ Object
33 34 35 |
# File 'lib/frenzy_bunnies/context.rb', line 33 def stop @klasses.each{|klass| klass.stop } end |