Class: FrenzyBunnies::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/frenzy_bunnies/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/frenzy_bunnies/context.rb', line 5

def env
  @env
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/frenzy_bunnies/context.rb', line 5

def logger
  @logger
end

#optsObject (readonly)

Returns the value of attribute opts.



5
6
7
# File 'lib/frenzy_bunnies/context.rb', line 5

def opts
  @opts
end

#queue_factoryObject (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

#stopObject



33
34
35
# File 'lib/frenzy_bunnies/context.rb', line 33

def stop
  @klasses.each{|klass| klass.stop }
end