class Celluloid::Actor::System

Constants

ROOT_SERVICES

Attributes

group[R]
registry[R]

Public Class Methods

new() click to toggle source
# File lib/celluloid/actor/system.rb, line 50
def initialize
  @tree = nil
  @group = Celluloid.group_class.new
  @registry = Internals::Registry.new
  @root = ROOT_SERVICES
end

Public Instance Methods

assert_inactive() click to toggle source
# File lib/celluloid/actor/system.rb, line 154
def assert_inactive
  @group.assert_inactive
end
clear_registry() click to toggle source
# File lib/celluloid/actor/system.rb, line 94
def clear_registry
  @registry.clear
end
get_thread() { || ... } click to toggle source
# File lib/celluloid/actor/system.rb, line 75
def get_thread
  @group.get do
    Thread.current[:celluloid_actor_system] = self
    yield
  end
end
registered() click to toggle source
# File lib/celluloid/actor/system.rb, line 90
def registered
  @registry.names
end
root_configuration() click to toggle source
# File lib/celluloid/actor/system.rb, line 46
def root_configuration
  @root
end
root_services() click to toggle source

the root of the supervisor tree is established at supervision/root

# File lib/celluloid/actor/system.rb, line 42
def root_services
  @tree
end
running() click to toggle source
# File lib/celluloid/actor/system.rb, line 98
def running
  actors = []
  @group.each do |t|
    next unless t.role == :actor
    actor = t.actor

    # NOTE - these are in separate statements, since on JRuby t.actor may
    # become nil befor .behavior_proxy() is called
    next unless actor
    next unless actor.respond_to?(:behavior_proxy)
    proxy = actor.behavior_proxy
    actors << proxy
  end
  actors
end
running?() click to toggle source
# File lib/celluloid/actor/system.rb, line 114
def running?
  @group.active?
end
shutdown() click to toggle source

Shut down all running actors

# File lib/celluloid/actor/system.rb, line 119
def shutdown
  actors = running
  Timeout.timeout(shutdown_timeout) do
    Internals::Logger.debug "Terminating #{actors.size} #{(actors.size > 1) ? 'actors' : 'actor'}..." if actors.size > 0

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

    actors.each do |actor|
      begin
        Actor.join(actor)
      rescue DeadActorError
      end
    end
  end
rescue Timeout::Error
  Internals::Logger.error("Couldn't cleanly terminate all actors in #{shutdown_timeout} seconds!")
  unless RUBY_PLATFORM == "java" || RUBY_ENGINE == "rbx"
    actors.each do |actor|
      begin
        Actor.kill(actor)
      rescue DeadActorError, MailboxDead
      end
    end
  end
ensure
  @group.shutdown
  clear_registry
end
shutdown_timeout() click to toggle source
# File lib/celluloid/actor/system.rb, line 158
def shutdown_timeout
  Celluloid.shutdown_timeout
end
stack_dump() click to toggle source
# File lib/celluloid/actor/system.rb, line 82
def stack_dump
  Internals::Stack::Dump.new(@group)
end
stack_summary() click to toggle source
# File lib/celluloid/actor/system.rb, line 86
def stack_summary
  Internals::Stack::Summary.new(@group)
end
start() click to toggle source

Launch default services

# File lib/celluloid/actor/system.rb, line 58
def start
  within do
    @root = Supervision::Service::Root.define
    @tree = root_configuration.deploy
    # de root_services[:group_manager].manage! @group
  end
  true
end
within() { || ... } click to toggle source
# File lib/celluloid/actor/system.rb, line 67
def within
  old = Thread.current[:celluloid_actor_system]
  Thread.current[:celluloid_actor_system] = self
  yield
ensure
  Thread.current[:celluloid_actor_system] = old
end