Sha256: 2a9724d0b06d7f3c4cea08059914be9a73ed8e7847429a59cf761a97b7cf6d35

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

require 'logger'
require 'frenzy_bunnies/web'

class FrenzyBunnies::Context
  attr_reader :connection, :queue_factory, :logger, :env, :opts

  def initialize(opts={})
    @opts = opts
    @opts[:host]     ||= 'localhost'
    @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)
    params = {:host => @opts[:host], :heartbeat_interval => @opts[:heartbeat]}
    (params[:username], params[:password] = @opts[:username], @opts[:password]) if @opts[:username] && @opts[:password]
    (params[:port] = @opts[:port]) if @opts[:port]
    @connection = MarchHare.connect(params)
    @connection.add_shutdown_listener(lambda { |cause| @logger.error("Disconnected: #{cause}"); stop;})

    @queue_factory = FrenzyBunnies::QueueFactory.new(@connection)
  end

  def run(*klasses)
    @klasses = []
    klasses.each{|klass| klass.start(self); @klasses << klass}
    return nil if @opts[:disable_web_stats]
    Thread.new do
      FrenzyBunnies::Web.run_with(@klasses, :host => @opts[:web_host], :port => @opts[:web_port], :threadfilter => @opts[:web_threadfilter], :logger => @logger)
    end
  end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
boardintel_frenzy_bunnies-0.0.17-java lib/frenzy_bunnies/context.rb
boardintel_frenzy_bunnies-0.0.16 lib/frenzy_bunnies/context.rb
boardintel_frenzy_bunnies-0.0.15 lib/frenzy_bunnies/context.rb
boardintel_frenzy_bunnies-0.0.14 lib/frenzy_bunnies/context.rb
boardintel_frenzy_bunnies-0.0.13 lib/frenzy_bunnies/context.rb
boardintel_frenzy_bunnies-0.0.12 lib/frenzy_bunnies/context.rb