Parent

Included Modules

Class/Module Index [+]

Quicksearch

Celluloid::SupervisionGroup

Supervise collections of actors as a group

Public Class Methods

blocks() click to toggle source

Actors or sub-applications to be supervised

# File lib/celluloid/supervision_group.rb, line 10
def blocks
  @blocks ||= []
end
new(registry = nil) click to toggle source

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
pool(klass, options = {}) click to toggle source

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(registry = nil) click to toggle source

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
run!(registry = nil) click to toggle source

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
supervise(klass, options = {}) click to toggle source

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

Public Instance Methods

[](actor_name) click to toggle source
# File lib/celluloid/supervision_group.rb, line 94
def [](actor_name)
  @registry[actor_name]
end
actors() click to toggle source
# File lib/celluloid/supervision_group.rb, line 90
def actors
  @members.map(&:actor)
end
add(klass, options) click to toggle source
# File lib/celluloid/supervision_group.rb, line 84
def add(klass, options)
  member = Member.new(@registry, klass, options)
  @members << member
  member.actor
end
pool(klass, options = {}) click to toggle source
# File lib/celluloid/supervision_group.rb, line 79
def pool(klass, options = {})
  options[:method] = 'pool_link'
  add(klass, options)
end
restart_actor(actor, reason) click to toggle source

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
supervise(klass, *args, &block) click to toggle source
# File lib/celluloid/supervision_group.rb, line 71
def supervise(klass, *args, &block)
  add(klass, :args => args, :block => block)
end
supervise_as(name, klass, *args, &block) click to toggle source
# File lib/celluloid/supervision_group.rb, line 75
def supervise_as(name, klass, *args, &block)
  add(klass, :args => args, :block => block, :as => name)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.