Namespace

Class/Module Index [+]

Quicksearch

Celluloid

Constants

BARE_OBJECT_WARNING_MESSAGE

Warning message added to Celluloid objects accessed outside their actors

LINKING_TIMEOUT
OWNER_IVAR
TIMER_QUANTUM

Timer accuracy enforced by the tests (50ms)

VERSION

Attributes

internal_pool[RW]
logger[RW]
shutdown_timeout[RW]
task_class[RW]

Public Class Methods

actor?() click to toggle source

Are we currently inside of an actor?

# File lib/celluloid.rb, line 24
def actor?
  !!Thread.current[:celluloid_actor]
end
boot() click to toggle source

Launch default services FIXME: We should set up the supervision hierarchy here

# File lib/celluloid.rb, line 68
def boot
  internal_pool.reset
  Celluloid::Notifications::Fanout.supervise_as :notifications_fanout
  Celluloid::IncidentReporter.supervise_as :default_incident_reporter, STDERR
end
cores() click to toggle source

Obtain the number of CPUs in the system

# File lib/celluloid.rb, line 39
def cores
 CPUCounter.cores
end
Also aliased as: cpus, ncpus
cpus() click to toggle source
Alias for: cores
dump(output = STDERR) click to toggle source
Alias for: stack_dump
exception_handler(&block) click to toggle source

Define an exception handler for actor crashes

# File lib/celluloid.rb, line 52
def exception_handler(&block)
  Logger.exception_handler(&block)
end
included(klass) click to toggle source
# File lib/celluloid.rb, line 18
def included(klass)
  klass.send :extend,  ClassMethods
  klass.send :include, InstanceMethods
end
mailbox() click to toggle source

Retrieve the mailbox for the current thread or lazily initialize it

# File lib/celluloid.rb, line 29
def mailbox
  Thread.current[:celluloid_mailbox] ||= Celluloid::Mailbox.new
end
ncpus() click to toggle source
Alias for: cores
register_shutdown() click to toggle source
# File lib/celluloid.rb, line 74
def register_shutdown
  return if @shutdown_registered
  # Terminate all actors at exit
  at_exit do
    if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9"
      # workaround for MRI bug losing exit status in at_exit block
      # http://bugs.ruby-lang.org/issues/5218
      exit_status = $!.status if $!.is_a?(SystemExit)
      Celluloid.shutdown
      exit exit_status if exit_status
    else
      Celluloid.shutdown
    end
  end
  @shutdown_registered = true
end
shutdown() click to toggle source

Shut down all running actors

# File lib/celluloid.rb, line 92
def shutdown
  Timeout.timeout(shutdown_timeout) do
    internal_pool.shutdown

    actors = Actor.all
    Logger.debug "Terminating #{actors.size} actors..." if actors.size > 0

    # Attempt to shut down the supervision tree, if available
    Supervisor.root.terminate if Supervisor.root

    # Actors cannot self-terminate, you must do it for them
    actors.each do |actor|
      begin
        actor.terminate!
      rescue DeadActorError, MailboxError
      end
    end

    actors.each do |actor|
      begin
        Actor.join(actor)
      rescue DeadActorError, MailboxError
      end
    end

    Logger.debug "Shutdown completed cleanly"
  end
rescue Timeout::Error
  Logger.error("Couldn't cleanly terminate all actors in #{shutdown_timeout} seconds!")
end
stack_dump(output = STDERR) click to toggle source

Perform a stack dump of all actors to the given output object

# File lib/celluloid.rb, line 46
def stack_dump(output = STDERR)
  Celluloid::StackDump.new.dump(output)
end
Also aliased as: dump
suspend(status, waiter) click to toggle source
# File lib/celluloid.rb, line 56
def suspend(status, waiter)
  task = Thread.current[:celluloid_task]
  if task && !Celluloid.exclusive?
    waiter.before_suspend(task) if waiter.respond_to?(:before_suspend)
    Task.suspend(status)
  else
    waiter.wait
  end
end
uuid() click to toggle source

Generate a Universally Unique Identifier

# File lib/celluloid.rb, line 34
def uuid
  UUID.generate
end
version() click to toggle source
# File lib/celluloid/version.rb, line 3
def self.version; VERSION; end

Public Instance Methods

abort(cause) click to toggle source

Raise an exception in sender context, but stay running

# File lib/celluloid.rb, line 355
def abort(cause)
  cause = case cause
    when String then RuntimeError.new(cause)
    when Exception then cause
    else raise TypeError, "Exception object/String expected, but #{cause.class} received"
  end
  raise AbortError.new(cause)
end
after(interval, &block) click to toggle source

Call a block after a given interval, returning a Celluloid::Timer object

# File lib/celluloid.rb, line 462
def after(interval, &block)
  Thread.current[:celluloid_actor].after(interval, &block)
end
async(meth = nil, *args, &block) click to toggle source

Handle async calls within an actor itself

# File lib/celluloid.rb, line 481
def async(meth = nil, *args, &block)
  Thread.current[:celluloid_actor].proxy.async meth, *args, &block
end
call_chain_id() click to toggle source

Obtain the UUID of the current call chain

# File lib/celluloid.rb, line 385
def call_chain_id
  Thread.current[:celluloid_chain_id]
end
current_actor() click to toggle source

Obtain the current_actor

# File lib/celluloid.rb, line 380
def current_actor
  Actor.current
end
defer(&block) click to toggle source

Perform a blocking or computationally intensive action inside an asynchronous thread pool, allowing the sender to continue processing other messages in its mailbox in the meantime

# File lib/celluloid.rb, line 474
def defer(&block)
  # This implementation relies on the present implementation of
  # Celluloid::Future, which uses a thread from InternalPool to run the block
  Future.new(&block).value
end
every(interval, &block) click to toggle source

Call a block every given interval, returning a Celluloid::Timer object

# File lib/celluloid.rb, line 467
def every(interval, &block)
  Thread.current[:celluloid_actor].every(interval, &block)
end
exclusive(&block) click to toggle source

Run given block in an exclusive mode: all synchronous calls block the whole actor, not only current message processing.

# File lib/celluloid.rb, line 451
def exclusive(&block)
  Thread.current[:celluloid_actor].exclusive(&block)
end
exclusive?() click to toggle source

Are we currently exclusive

# File lib/celluloid.rb, line 456
def exclusive?
  actor = Thread.current[:celluloid_actor]
  actor && actor.exclusive?
end
future(meth = nil, *args, &block) click to toggle source

Handle calls to future within an actor itself

# File lib/celluloid.rb, line 486
def future(meth = nil, *args, &block)
  Thread.current[:celluloid_actor].proxy.future meth, *args, &block
end
linked_to?(actor) click to toggle source

Is this actor linked to another?

# File lib/celluloid.rb, line 425
def linked_to?(actor)
  Actor.linked_to?(actor)
end
monitor(actor) click to toggle source

Watch for exit events from another actor

# File lib/celluloid.rb, line 400
def monitor(actor)
  Actor.monitor(actor)
end
monitoring?(actor) click to toggle source

Are we monitoring another actor?

# File lib/celluloid.rb, line 420
def monitoring?(actor)
  Actor.monitoring?(actor)
end
receive(timeout = nil, &block) click to toggle source

Receive an asynchronous message via the actor protocol

# File lib/celluloid.rb, line 430
def receive(timeout = nil, &block)
  actor = Thread.current[:celluloid_actor]
  if actor
    actor.receive(timeout, &block)
  else
    Celluloid.mailbox.receive(timeout, &block)
  end
end
signal(name, value = nil) click to toggle source

Send a signal with the given name to all waiting methods

# File lib/celluloid.rb, line 370
def signal(name, value = nil)
  Thread.current[:celluloid_actor].signal name, value
end
sleep(interval) click to toggle source

Sleep letting the actor continue processing messages

# File lib/celluloid.rb, line 440
def sleep(interval)
  actor = Thread.current[:celluloid_actor]
  if actor
    actor.sleep(interval)
  else
    Kernel.sleep interval
  end
end
tasks() click to toggle source

Obtain the running tasks for this actor

# File lib/celluloid.rb, line 390
def tasks
  Thread.current[:celluloid_actor].tasks.to_a
end
terminate() click to toggle source

Terminate this actor

# File lib/celluloid.rb, line 365
def terminate
  Thread.current[:celluloid_actor].terminate
end
unmonitor(actor) click to toggle source

Stop waiting for exit events from another actor

# File lib/celluloid.rb, line 405
def unmonitor(actor)
  Actor.unmonitor(actor)
end
wait(name) click to toggle source

Wait for the given signal

# File lib/celluloid.rb, line 375
def wait(name)
  Thread.current[:celluloid_actor].wait name
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.