Module: Celluloid::ClassMethods

Defined in:
lib/celluloid.rb

Overview

Class methods added to classes which include Celluloid

Instance Method Summary collapse

Instance Method Details

#===(other) ⇒ Object


245
246
247
# File 'lib/celluloid.rb', line 245

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

#actor_optionsObject

Configuration options for Actor#new


225
226
227
228
229
230
231
232
233
# File 'lib/celluloid.rb', line 225

def actor_options
  {
    :actor_system      => actor_system,
    :mailbox_class     => mailbox_class,
    :mailbox_size      => mailbox_size,
    :task_class        => task_class,
    :exclusive         => exclusive_actor,
  }
end

#actor_systemObject


220
221
222
# File 'lib/celluloid.rb', line 220

def actor_system
  Celluloid.actor_system
end

#behavior_optionsObject


235
236
237
238
239
240
241
242
243
# File 'lib/celluloid.rb', line 235

def behavior_options
  {
    :proxy_class               => proxy_class,
    :exclusive_methods         => exclusive_methods,
    :exit_handler_name         => exit_handler_name,
    :finalizer                 => finalizer,
    :receiver_block_executions => execute_block_on_receiver,
  }
end

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

Create a new actor


171
172
173
174
175
# File 'lib/celluloid.rb', line 171

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

Create a new actor and link to the current one

Raises:


179
180
181
182
183
184
185
186
# File 'lib/celluloid.rb', line 179

def new_link(*args, &block)
  raise NotActorError, "can't link outside actor context" unless Celluloid.actor?

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

#pool(options = {}) ⇒ Object

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


206
207
208
# File 'lib/celluloid.rb', line 206

def pool(options = {})
  PoolManager.new(self, options)
end

Same as pool, but links to the pool manager


211
212
213
# File 'lib/celluloid.rb', line 211

def pool_link(options = {})
  PoolManager.new_link(self, options)
end

#run(*args, &block) ⇒ Object

Run an actor in the foreground


216
217
218
# File 'lib/celluloid.rb', line 216

def run(*args, &block)
  Actor.join(new(*args, &block))
end

#supervise(*args, &block) ⇒ Object

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


191
192
193
# File 'lib/celluloid.rb', line 191

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


197
198
199
# File 'lib/celluloid.rb', line 197

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