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 =
[ { as: :notifications_fanout, type: Celluloid::Notifications::Fanout }, { as: :public_services, type: Celluloid::Supervision::Service::Public, accessors: [:services], supervise: [] } ].freeze
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.
35 36 37 38 39 40 |
# File 'lib/celluloid/actor/system.rb', line 35 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.
23 24 25 |
# File 'lib/celluloid/actor/system.rb', line 23 def group @group end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
23 24 25 |
# File 'lib/celluloid/actor/system.rb', line 23 def registry @registry end |
Instance Method Details
#assert_inactive ⇒ Object
138 139 140 |
# File 'lib/celluloid/actor/system.rb', line 138 def assert_inactive @group.assert_inactive end |
#clear_registry ⇒ Object
78 79 80 |
# File 'lib/celluloid/actor/system.rb', line 78 def clear_registry @registry.clear end |
#get_thread ⇒ Object
59 60 61 62 63 64 |
# File 'lib/celluloid/actor/system.rb', line 59 def get_thread @group.get do Thread.current[:celluloid_actor_system] = self yield end end |
#registered ⇒ Object
74 75 76 |
# File 'lib/celluloid/actor/system.rb', line 74 def registered @registry.names end |
#root_configuration ⇒ Object
31 32 33 |
# File 'lib/celluloid/actor/system.rb', line 31 def root_configuration @root end |
#root_services ⇒ Object
the root of the supervisor tree is established at supervision/root
27 28 29 |
# File 'lib/celluloid/actor/system.rb', line 27 def root_services @tree end |
#running ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/celluloid/actor/system.rb', line 82 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
98 99 100 |
# File 'lib/celluloid/actor/system.rb', line 98 def running? @group.active? end |
#shutdown ⇒ Object
Shut down all running actors
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/celluloid/actor/system.rb', line 103 def shutdown actors = running Timeout.timeout(shutdown_timeout) do Internals::Logger.debug "Terminating #{actors.size} #{actors.size > 1 ? 'actors' : 'actor'}..." unless actors.empty? # 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
142 143 144 |
# File 'lib/celluloid/actor/system.rb', line 142 def shutdown_timeout Celluloid.shutdown_timeout end |
#stack_dump ⇒ Object
66 67 68 |
# File 'lib/celluloid/actor/system.rb', line 66 def stack_dump Internals::Stack::Dump.new(@group) end |
#stack_summary ⇒ Object
70 71 72 |
# File 'lib/celluloid/actor/system.rb', line 70 def stack_summary Internals::Stack::Summary.new(@group) end |
#start ⇒ Object
Launch default services
43 44 45 46 47 48 49 |
# File 'lib/celluloid/actor/system.rb', line 43 def start within do @root = Supervision::Service::Root.define @tree = root_configuration.deploy end true end |