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)



259
260
261
# File 'lib/celluloid.rb', line 259

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

- (Object) actor_options

Configuration options for Actor#new



247
248
249
250
251
252
253
254
255
256
257
# 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

- (Object) exclusive(*methods)

Mark methods as running exclusively



237
238
239
240
241
242
243
244
# 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

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

Create a new actor



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

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

Create a new actor and link to the current one

Raises:



195
196
197
198
199
200
201
202
# 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

- (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



222
223
224
# File 'lib/celluloid.rb', line 222

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

Same as pool, but links to the pool manager



227
228
229
# File 'lib/celluloid.rb', line 227

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

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

Run an actor in the foreground



232
233
234
# File 'lib/celluloid.rb', line 232

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



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

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



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

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