module Celluloid::ClassMethods - celluloid-0.15.2 Documentation

# module Celluloid::ClassMethods

Class methods added to classes which include Celluloid

### Public Instance Methods

===(other) click to toggle source

    # File lib/celluloid.rb, line 259
    def ===(other)
      other.kind_of? self
    end

actor_options() click to toggle source

Configuration options for Actor#new

    # File lib/celluloid.rb, line 247
    def actor_options
      {
        :mailbox_class     => mailbox_class,
        :mailbox_size      => mailbox_size,
        :proxy_class       => proxy_class,
        :task_class        => task_class,
        :exit_handler      => exit_handler,
        :exclusive_methods => defined?(@exclusive_methods) ? @exclusive_methods : nil,
        :receiver_block_executions => execute_block_on_receiver
      }
    end

exclusive(*methods) click to toggle source

Mark methods as running exclusively

    # File lib/celluloid.rb, line 237
    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

new(*args, &block) click to toggle source

Create a new actor

    # File lib/celluloid.rb, line 187
    def new(*args, &block)
      proxy = Actor.new(allocate, actor_options).proxy
      proxy._send_(:initialize, *args, &block)
      proxy
    end

Also aliased as: spawn
new_link(*args, &block) click to toggle source

Create a new actor and link to the current one

    # File lib/celluloid.rb, line 195
    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

Also aliased as: spawn_link
pool(options = {}) click to toggle source

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 222
    def pool(options = {})
      PoolManager.new(self, options)
    end

pool_link(options = {}) click to toggle source

Same as pool, but links to the pool manager

    # File lib/celluloid.rb, line 227
    def pool_link(options = {})
      PoolManager.new_link(self, options)
    end

run(*args, &block) click to toggle source

Run an actor in the foreground

    # File lib/celluloid.rb, line 232
    def run(*args, &block)
      Actor.join(new(*args, &block))
    end

spawn(*args, &block)
Alias for: new
spawn_link(*args, &block)
Alias for: new_link
supervise(*args, &block) click to toggle source

Create a supervisor which ensures an instance of an actor will restart an actor if it fails

    # File lib/celluloid.rb, line 207
    def supervise(*args, &block)
      Supervisor.supervise(self, *args, &block)
    end

supervise_as(name, *args, &block) click to toggle source

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 213
    def supervise_as(name, *args, &block)
      Supervisor.supervise_as(name, self, *args, &block)
    end