lib/celluloid/pool_manager.rb in celluloid-0.11.0 vs lib/celluloid/pool_manager.rb in celluloid-0.11.1
- old
+ new
@@ -1,8 +1,9 @@
module Celluloid
# 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
def initialize(worker_class, options = {})
@@ -14,25 +15,48 @@
@worker_class = worker_class
@idle = @size.times.map { worker_class.new_link(*@args) }
end
- # Execute the given method within a worker
- def execute(method, *args, &block)
- worker = provision_worker
+ def _send_(method, *args, &block)
+ worker = __provision_worker
begin
worker._send_ method, *args, &block
- rescue => ex
+ rescue Exception => ex
abort ex
ensure
@idle << worker if worker.alive?
end
end
+ def name
+ _send_ @mailbox, :name
+ end
+
+ def is_a?(klass)
+ _send_ :is_a?, klass
+ end
+
+ def kind_of?(klass)
+ _send_ :kind_of?, klass
+ end
+
+ def methods(include_ancestors = true)
+ _send_ :methods, include_ancestors
+ end
+
+ def to_s
+ _send_ :to_s
+ end
+
+ def inspect
+ _send_ :inspect
+ end
+
# Provision a new worker
- def provision_worker
+ def __provision_worker
while @idle.empty?
# Using exclusive mode blocks incoming messages, so they don't pile
# up as waiting Celluloid::Tasks
response = exclusive { receive { |msg| msg.is_a? Response } }
Thread.current[:actor].handle_message(response)
@@ -51,10 +75,10 @@
super || (@worker_class ? @worker_class.instance_methods.include?(method.to_sym) : false)
end
def method_missing(method, *args, &block)
if respond_to?(method)
- execute method, *args, &block
+ _send_ method, *args, &block
else
super
end
end
end