lib/celluloid/pool_manager.rb in celluloid-0.12.4 vs lib/celluloid/pool_manager.rb in celluloid-0.13.0.pre

- old
+ new

@@ -4,11 +4,12 @@ # Manages a fixed-size pool of workers # Delegates work (i.e. methods) and supervises workers # Don't use this class directly. Instead use MyKlass.pool class PoolManager include Celluloid - trap_exit :crash_handler + trap_exit :__crash_handler__ + finalizer :__shutdown__ def initialize(worker_class, options = {}) @size = options[:size] || [Celluloid.cores, 2].max raise ArgumentError, "minimum pool size is 2" if @size < 2 @@ -20,11 +21,11 @@ # FIXME: Another data structure (e.g. Set) would be more appropriate # here except it causes MRI to crash :o @busy = [] end - def finalize + def __shutdown__ terminators = (@idle + @busy).each do |actor| begin actor.future(:terminate) rescue DeadActorError, MailboxError end @@ -32,17 +33,17 @@ terminators.compact.each { |terminator| terminator.value rescue nil } end def _send_(method, *args, &block) - worker = __provision_worker + worker = __provision_worker__ begin worker._send_ method, *args, &block rescue DeadActorError # if we get a dead actor out of the pool wait :respawn_complete - worker = __provision_worker + worker = __provision_worker__ retry rescue Exception => ex abort ex ensure if worker.alive? @@ -87,24 +88,24 @@ def idle_size @idle.length end # Provision a new worker - def __provision_worker + def __provision_worker__ while @idle.empty? # Wait for responses from one of the busy workers response = exclusive { receive { |msg| msg.is_a?(Response) } } - Thread.current[:actor].handle_message(response) + Thread.current[:celluloid_actor].handle_message(response) end worker = @idle.shift @busy << worker worker end # Spawn a new worker for every crashed one - def crash_handler(actor, reason) + def __crash_handler__(actor, reason) @busy.delete actor @idle.delete actor return unless reason @idle << @worker_class.new_link(*@args)