Module: Celluloid::ClassMethods

Defined in:
lib/celluloid.rb

Overview

Class methods added to classes which include Celluloid

Instance Method Summary (collapse)

Instance Method Details

- (Object) ===(other)



241
242
243
# File 'lib/celluloid.rb', line 241

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

- (Object) actor_options

Configuration options for Actor#new



221
222
223
224
225
226
227
228
229
# File 'lib/celluloid.rb', line 221

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

- (Object) actor_system



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

def actor_system
  Celluloid.actor_system
end

- (Object) behavior_options



231
232
233
234
235
236
237
238
239
# File 'lib/celluloid.rb', line 231

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

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

Create a new actor



167
168
169
170
171
# File 'lib/celluloid.rb', line 167

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:



175
176
177
178
179
180
181
182
# File 'lib/celluloid.rb', line 175

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

- (Object) pool(options = {})

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



202
203
204
# File 'lib/celluloid.rb', line 202

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

Same as pool, but links to the pool manager



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

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

- (Object) run(*args, &block)

Run an actor in the foreground



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

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

- (Object) supervise(*args, &block)

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



187
188
189
# File 'lib/celluloid.rb', line 187

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

- (Object) supervise_as(name, *args, &block)

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



193
194
195
# File 'lib/celluloid.rb', line 193

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