Module: Celluloid::ClassMethods

Extended by:
Forwardable
Defined in:
lib/celluloid.rb,
lib/celluloid/supervision/supervise.rb,
lib/celluloid/supervision/container/behavior/pool.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



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

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:



205
206
207
208
209
210
211
212
# File 'lib/celluloid.rb', line 205

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(config = {}, &block) ⇒ 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



12
13
14
15
# File 'lib/celluloid/supervision/container/behavior/pool.rb', line 12

def pool(config = {}, &block)
  _ = Celluloid.supervise(pooling_options(config, block: block, actors: self))
  _.actors.last
end

Same as pool, but links to the pool manager



18
19
20
# File 'lib/celluloid/supervision/container/behavior/pool.rb', line 18

def pool_link(klass, config = {}, &block)
  Supervision::Container::Pool.new_link(pooling_options(config, block: block, actors: klass))
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(config = {}, &block) ⇒ Object



10
11
12
# File 'lib/celluloid/supervision/supervise.rb', line 10

def supervise(config = {}, &block)
  Celluloid.supervise(config.merge(type: self), &block)
end