Parent

Class/Module Index [+]

Quicksearch

Bunny::ConsumerWorkPool

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

@private

Attributes

size[R]

API

Public Class Methods

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

Public Instance Methods

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

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

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

  @threads.each { |t| t.run }
end
running?() click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 37
def running?
  @running
end
shutdown() click to toggle source
# File lib/bunny/consumer_work_pool.rb, line 41
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 26
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 22
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 75
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.