Object
Supervise collections of actors as a group
Actors or sub-applications to be supervised
# File lib/celluloid/supervision_group.rb, line 9 def blocks @blocks ||= [] end
Start the group
# File lib/celluloid/supervision_group.rb, line 59 def initialize(registry = nil) @members = [] @registry = registry || Registry.root yield current_actor if block_given? end
Register a pool of actors to be launched on group startup Available options are:
as: register this application in the Celluloid::Actor[] directory
args: start the actor pool with the given arguments
# File lib/celluloid/supervision_group.rb, line 51 def pool(klass, options = {}) blocks << lambda do |group| group.pool klass, options end end
Run the application in the foreground with a simple watchdog
# File lib/celluloid/supervision_group.rb, line 24 def run loop do supervisor = run! # Take five, toplevel supervisor sleep 5 while supervisor.alive? Logger.error "!!! Celluloid::SupervisionGroup #{self} crashed. Restarting..." end end
Start this application (and watch it with a supervisor)
# File lib/celluloid/supervision_group.rb, line 14 def run! group = new do |_group| blocks.each do |block| block.call(_group) end end group end
Register an actor class or a sub-group to be launched and supervised Available options are:
as: register this application in the Celluloid::Actor[] directory
args: start the actor with the given arguments
# File lib/celluloid/supervision_group.rb, line 40 def supervise(klass, options = {}) blocks << lambda do |group| group.add klass, options end end
# File lib/celluloid/supervision_group.rb, line 87 def actors @members.map(&:actor) end
# File lib/celluloid/supervision_group.rb, line 81 def add(klass, options) member = Member.new(@registry, klass, options) @members << member member end
Terminate the group
# File lib/celluloid/supervision_group.rb, line 94 def finalize @members.reverse_each(&:terminate) end
# File lib/celluloid/supervision_group.rb, line 76 def pool(klass, options = {}) options[:method] = 'pool_link' add(klass, options) end
Restart a crashed actor
# File lib/celluloid/supervision_group.rb, line 99 def restart_actor(actor, reason) member = @members.find do |_member| _member.actor == actor end raise "a group member went missing. This shouldn't be!" unless member member.restart(reason) end
Generated with the Darkfish Rdoc Generator 2.