Parent

Class/Module Index [+]

Quicksearch

Bunny::ConsumerWorkPool

Thread pool that dispatches consumer deliveries. Not supposed to be shared between channels or threads.

Every channel its own consumer pool.

@private

Attributes

size[R]
threads[R]

API

Public Class Methods

new(size = 1) click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 19
def initialize(size = 1)
  @size  = size
  @queue = ::Queue.new
end

Public Instance Methods

join(timeout = nil) click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 54
def join(timeout = nil)
  @threads.each { |t| t.join(timeout) }
end
kill() click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 70
def kill
  @running = false

  @threads.each { |t| t.kill }
end
pause() click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 58
def pause
  @running = false

  @threads.each { |t| t.stop }
end
resume() click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 64
def resume
  @running = true

  @threads.each { |t| t.run }
end
running?() click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 40
def running?
  @running
end
shutdown() click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 44
def shutdown
  @running = false

  @size.times do
    submit do |*args|
      throw :terminate
    end
  end
end
start() click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 29
def start
  @threads = []

  @size.times do
    t = Thread.new(&method(:run_loop))
    @threads << t
  end

  @running = true
end
submit(callable = nil, &block) click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 25
def submit(callable = nil, &block)
  @queue.push(callable || block)
end

Protected Instance Methods

run_loop() click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 78
def run_loop
  catch(:terminate) do
    loop do
      callable = @queue.pop

      begin
        callable.call
      rescue Exception => e
        # TODO
        puts e.class.name
        puts e.message
      end
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.