Class: Celluloid::Actor::System
- Inherits:
-
Object
- Object
- Celluloid::Actor::System
- Extended by:
- Forwardable
- Defined in:
- lib/celluloid/actor/system.rb
Constant Summary collapse
- ROOT_SERVICES =
begin root_services = [ { as: :notifications_fanout, type: Celluloid::Notifications::Fanout, }, { as: :incident_reporter, type: Celluloid::IncidentReporter, args: [STDERR], }, { as: :public_services, type: Celluloid::Supervision::Service::Public, accessors: [:services], supervise: [], }, ] if $CELLULOID_MANAGED root_services << { as: :actor_manager, type: Celluloid::Actor::Manager, accessors: [:manager], } end root_services end
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #assert_inactive ⇒ Object
- #clear_registry ⇒ Object
- #get_thread ⇒ Object
-
#initialize ⇒ System
constructor
A new instance of System.
- #registered ⇒ Object
- #root_configuration ⇒ Object
-
#root_services ⇒ Object
the root of the supervisor tree is established at supervision/root.
- #running ⇒ Object
- #running? ⇒ Boolean
-
#shutdown ⇒ Object
Shut down all running actors.
- #shutdown_timeout ⇒ Object
- #stack_dump ⇒ Object
- #stack_summary ⇒ Object
-
#start ⇒ Object
Launch default services.
- #within ⇒ Object
Constructor Details
#initialize ⇒ System
Returns a new instance of System.
50 51 52 53 54 55 |
# 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 |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
38 39 40 |
# File 'lib/celluloid/actor/system.rb', line 38 def group @group end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
38 39 40 |
# File 'lib/celluloid/actor/system.rb', line 38 def registry @registry end |
Instance Method Details
#assert_inactive ⇒ Object
154 155 156 |
# File 'lib/celluloid/actor/system.rb', line 154 def assert_inactive @group.assert_inactive end |
#clear_registry ⇒ Object
94 95 96 |
# File 'lib/celluloid/actor/system.rb', line 94 def clear_registry @registry.clear end |
#get_thread ⇒ Object
75 76 77 78 79 80 |
# File 'lib/celluloid/actor/system.rb', line 75 def get_thread @group.get do Thread.current[:celluloid_actor_system] = self yield end end |
#registered ⇒ Object
90 91 92 |
# File 'lib/celluloid/actor/system.rb', line 90 def registered @registry.names end |
#root_configuration ⇒ Object
46 47 48 |
# File 'lib/celluloid/actor/system.rb', line 46 def root_configuration @root end |
#root_services ⇒ Object
the root of the supervisor tree is established at supervision/root
42 43 44 |
# File 'lib/celluloid/actor/system.rb', line 42 def root_services @tree end |
#running ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# 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? ⇒ Boolean
114 115 116 |
# File 'lib/celluloid/actor/system.rb', line 114 def running? @group.active? end |
#shutdown ⇒ Object
Shut down all running actors
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# 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 ⇒ Object
158 159 160 |
# File 'lib/celluloid/actor/system.rb', line 158 def shutdown_timeout Celluloid.shutdown_timeout end |
#stack_dump ⇒ Object
82 83 84 |
# File 'lib/celluloid/actor/system.rb', line 82 def stack_dump Internals::Stack::Dump.new(@group) end |
#stack_summary ⇒ Object
86 87 88 |
# File 'lib/celluloid/actor/system.rb', line 86 def stack_summary Internals::Stack::Summary.new(@group) end |
#start ⇒ Object
Launch default services
58 59 60 61 62 63 64 65 |
# 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 |