Class methods added to classes which include Celluloid
# File lib/celluloid.rb, line 264 def ===(other) other.kind_of? self end
Configuration options for Actor#new
# File lib/celluloid.rb, line 253 def actor_options { :mailbox => mailbox.build, :proxy_class => proxy_class, :task_class => task_class, :exit_handler => exit_handler, :exclusive_methods => defined?(@exclusive_methods) ? @exclusive_methods : nil, :receiver_block_executions => receiver_block_executions } end
Mark methods as running exclusively
# File lib/celluloid.rb, line 234 def exclusive(*methods) if methods.empty? @exclusive_methods = :all elsif !defined?(@exclusive_methods) || @exclusive_methods != :all @exclusive_methods ||= Set.new @exclusive_methods.merge methods.map(&:to_sym) end end
Mark methods as running blocks on the receiver
# File lib/celluloid.rb, line 244 def execute_block_on_receiver(*methods) receiver_block_executions.merge methods.map(&:to_sym) end
Trap errors from actors we're linked to when they exit
# File lib/celluloid.rb, line 177 def exit_handler(callback = nil) if callback @exit_handler = callback.to_sym elsif defined?(@exit_handler) @exit_handler elsif superclass.respond_to? :exit_handler superclass.exit_handler end end
Define a callback to run when the actor is finalized.
# File lib/celluloid.rb, line 189 def finalizer(callback = nil) if callback @finalizer = callback.to_sym elsif defined?(@finalizer) @finalizer elsif superclass.respond_to? :finalizer superclass.finalizer end end
# File lib/celluloid.rb, line 268 def mailbox @mailbox_factory ||= MailboxFactory.new(self) end
Define the mailbox class for this class
# File lib/celluloid.rb, line 200 def mailbox_class(klass = nil) if klass mailbox.class = klass else mailbox.class end end
Create a new actor
# File lib/celluloid.rb, line 127 def new(*args, &block) proxy = Actor.new(allocate, actor_options).proxy proxy._send_(:initialize, *args, &block) proxy end
Create a new actor and link to the current one
# File lib/celluloid.rb, line 135 def new_link(*args, &block) raise NotActorError, "can't link outside actor context" unless Celluloid.actor? proxy = Actor.new(allocate, actor_options).proxy Actor.link(proxy) proxy._send_(:initialize, *args, &block) proxy end
Create a new pool of workers. Accepts the following options:
size: how many workers to create. Default is worker per CPU core
args: array of arguments to pass when creating a worker
# File lib/celluloid.rb, line 162 def pool(options = {}) PoolManager.new(self, options) end
Same as pool, but links to the pool manager
# File lib/celluloid.rb, line 167 def pool_link(options = {}) PoolManager.new_link(self, options) end
# File lib/celluloid.rb, line 208 def proxy_class(klass = nil) if klass @proxy_class = klass elsif defined?(@proxy_class) @proxy_class elsif superclass.respond_to? :proxy_class superclass.proxy_class else Celluloid::ActorProxy end end
# File lib/celluloid.rb, line 248 def receiver_block_executions @receiver_block_executions ||= Set.new([:after, :every, :receive]) end
Run an actor in the foreground
# File lib/celluloid.rb, line 172 def run(*args, &block) Actor.join(new(*args, &block)) end
Create a supervisor which ensures an instance of an actor will restart an actor if it fails
# File lib/celluloid.rb, line 147 def supervise(*args, &block) Supervisor.supervise(self, *args, &block) end
Create a supervisor which ensures an instance of an actor will restart an actor if it fails, and keep the actor registered under a given name
# File lib/celluloid.rb, line 153 def supervise_as(name, *args, &block) Supervisor.supervise_as(name, self, *args, &block) end
Define the default task type for this class
# File lib/celluloid.rb, line 221 def task_class(klass = nil) if klass @task_class = klass elsif defined?(@task_class) @task_class elsif superclass.respond_to? :task_class superclass.task_class else Celluloid.task_class end end
Generated with the Darkfish Rdoc Generator 2.