Module: Celluloid::ClassMethods

Defined in:
lib/celluloid.rb

Overview

Class methods added to classes which include Celluloid

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exit_handlerObject (readonly)

Obtain the exit handler for this actor



142
143
144
# File 'lib/celluloid.rb', line 142

def exit_handler
  @exit_handler
end

Instance Method Details

#===(other) ⇒ Object



164
165
166
# File 'lib/celluloid.rb', line 164

def ===(other)
  other.kind_of? self
end

#mailbox_factoryObject

Create a mailbox for this actor



154
155
156
157
158
159
160
161
162
# File 'lib/celluloid.rb', line 154

def mailbox_factory
  if defined?(@mailbox_factory)
    @mailbox_factory.call
  elsif defined?(super)
    super
  else
    Mailbox.new
  end
end

#new(*args, &block) ⇒ Object Also known as: spawn

Create a new actor



105
106
107
108
109
# File 'lib/celluloid.rb', line 105

def new(*args, &block)
  proxy = Actor.new(allocate).proxy
  proxy._send_(:initialize, *args, &block)
  proxy
end

Create a new actor and link to the current one

Raises:



113
114
115
116
117
118
119
120
121
# File 'lib/celluloid.rb', line 113

def new_link(*args, &block)
  current_actor = Actor.current
  raise NotActorError, "can't link outside actor context" unless current_actor

  proxy = Actor.new(allocate).proxy
  current_actor.link proxy
  proxy._send_(:initialize, *args, &block)
  proxy
end

#supervise(*args, &block) ⇒ Object

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



126
127
128
# File 'lib/celluloid.rb', line 126

def supervise(*args, &block)
  Supervisor.supervise(self, *args, &block)
end

#supervise_as(name, *args, &block) ⇒ Object

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



132
133
134
# File 'lib/celluloid.rb', line 132

def supervise_as(name, *args, &block)
  Supervisor.supervise_as(name, self, *args, &block)
end

#trap_exit(callback) ⇒ Object

Trap errors from actors we’re linked to when they exit



137
138
139
# File 'lib/celluloid.rb', line 137

def trap_exit(callback)
  @exit_handler = callback.to_sym
end

#use_mailbox(klass = nil, &block) ⇒ Object

Configure a custom mailbox factory



145
146
147
148
149
150
151
# File 'lib/celluloid.rb', line 145

def use_mailbox(klass = nil, &block)
  if block
    @mailbox_factory = block
  else
    @mailbox_factory = proc { klass.new }
  end
end