Supervise collections of actors as a group
Actors or sub-applications to be supervised
# File lib/celluloid/supervision_group.rb, line 10 def blocks @blocks ||= [] end
Start the group
# File lib/celluloid/supervision_group.rb, line 62 def initialize(registry = nil) @members = [] @registry = registry || Celluloid.actor_system.registry 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 52 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 25 def run(registry = nil) loop do supervisor = run!(registry) # 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 15 def run!(registry = nil) group = new(registry) 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 41 def supervise(klass, options = {}) blocks << lambda do |group| group.add klass, options end end
# File lib/celluloid/supervision_group.rb, line 94 def [](actor_name) @registry[actor_name] end
# File lib/celluloid/supervision_group.rb, line 90 def actors @members.map(&:actor) end
# File lib/celluloid/supervision_group.rb, line 84 def add(klass, options) member = Member.new(@registry, klass, options) @members << member member.actor end
# File lib/celluloid/supervision_group.rb, line 79 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 if reason member.restart else member.cleanup @members.delete(member) end end
Generated with the Darkfish Rdoc Generator 2.