Class: Celluloid::Supervision::Container

### Home Classes Methods

### In Files

- lib/celluloid/supervision/container.rb
- lib/celluloid/supervision/container/behavior.rb
- lib/celluloid/supervision/container/behavior/tree.rb
- lib/celluloid/supervision/container/injections.rb
- lib/celluloid/supervision/container/instance.rb
- lib/celluloid/supervision/deprecate/supervise.rb
- lib/celluloid/supervision/supervise.rb

### Parent

Object

### Namespace

- MODULE Celluloid::Supervision::Container::Behavior
- CLASS Celluloid::Supervision::Container::Injection
- CLASS Celluloid::Supervision::Container::Instance
- CLASS Celluloid::Supervision::Container::Tree

### Methods

- ::blocks
- ::define
- ::deploy
- ::new
- ::run
- ::run!
- ::supervise
- ::supervise_as
- ::top
- #[]
- #actors
- #add
- #add_accessors
- #find
- #remove
- #remove_accessors
- #restart_actor
- #shutdown
- #supervise
- #supervise_as

### Included Modules

- Celluloid

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::ClassMethods
- Celluloid::Supervision
- Celluloid::Supervision::Configuration
- Celluloid::Supervision::Configuration::Error
- Celluloid::Supervision::Configuration::Error::AlreadyDefined
- Celluloid::Supervision::Configuration::Error::Incomplete
- Celluloid::Supervision::Configuration::Error::Invalid
- Celluloid::Supervision::Configuration::Error::InvalidSupervisor
- Celluloid::Supervision::Configuration::Error::InvalidValues
- Celluloid::Supervision::Configuration::Injection
- Celluloid::Supervision::Configuration::Instance
- Celluloid::Supervision::Container
- Celluloid::Supervision::Container::Behavior
- Celluloid::Supervision::Container::Behavior::ClassMethods
- Celluloid::Supervision::Container::Behavior::Error
- Celluloid::Supervision::Container::Behavior::Error::Mutant
- Celluloid::Supervision::Container::Injection
- Celluloid::Supervision::Container::Instance
- Celluloid::Supervision::Container::Tree
- Celluloid::Supervision::Error
- Celluloid::Supervision::Error::NoPublicService
- Celluloid::Supervision::Service
- Celluloid::Supervision::Service::Public
- Celluloid::Supervision::Service::Root
- Celluloid::Supervisor

No matching classes.

# Celluloid::Supervision::Container

### Attributes

registry[RW]

### Public Class Methods

blocks() click to toggle source

Actors or sub-applications to be supervised

    # File lib/celluloid/supervision/container.rb, line 28
    def blocks
      @blocks ||= []
    end

define(options) click to toggle source

    # File lib/celluloid/supervision/container.rb, line 10
    def define(options)
      Configuration.define(top(options))
    end

deploy(options) click to toggle source

    # File lib/celluloid/supervision/container.rb, line 14
    def deploy(options)
      Configuration.deploy(top(options))
    end

new(options={}) click to toggle source

Start the container.

    # File lib/celluloid/supervision/container.rb, line 60
    def initialize(options={})
      options = {registry: options} if options.is_a? Internals::Registry
      @state = :initializing
      @actors = [] # instances in the container
      @registry = options.delete(:registry) || Celluloid.actor_system.registry
      @branch = options.delete(:branch) || :services
      yield current_actor if block_given?
    end

run(options={}) click to toggle source

Run the application in the foreground with a simple watchdog

    # File lib/celluloid/supervision/container.rb, line 43
    def run(options={})
      loop do
        supervisor = run!(options)

        # Take five, toplevel supervisor
        sleep 5 while supervisor.alive? # Why 5?

        Internals::Logger.error "!!! Celluloid::Supervision::Container #{self} crashed. Restarting..."
      end
    end

run!(options={}) click to toggle source

Start this application (and watch it with a supervisor)

    # File lib/celluloid/supervision/container.rb, line 33
    def run!(options={})
      container = new(options) do |g|
        blocks.each do |block|
          block.call(g)
        end
      end
      container
    end

supervise(*args, &block) click to toggle source

    # File lib/celluloid/supervision/deprecate/supervise.rb, line 80
    def supervise(*args, &block)
      blocks << lambda do |container|
        container.supervise(*args, &block)
      end
    end

supervise_as(name, *args, &block) click to toggle source

    # File lib/celluloid/supervision/deprecate/supervise.rb, line 87
    def supervise_as(name, *args, &block)
      blocks << lambda do |container|
        container.supervise_as(name, *args, &block)
      end
    end

top(options) click to toggle source

    # File lib/celluloid/supervision/container.rb, line 18
    def top(options)
      {
        as: (options.delete(:as)),
        type: (options.delete(:type) || self),
        branch: (options.delete(:branch) || :services),
        supervise: options.delete(:supervise) || [],
      }
    end

### Public Instance Methods

[](actor_name) click to toggle source

    # File lib/celluloid/supervision/container.rb, line 110
    def [](actor_name)
      @registry[actor_name]
    end

actors() click to toggle source

    # File lib/celluloid/supervision/container.rb, line 100
    def actors
      @actors.map(&:actor)
    end

add(configuration) click to toggle source

    # File lib/celluloid/supervision/container.rb, line 71
    def add(configuration)
      Configuration.valid?(configuration, true)
      @actors << Instance.new(configuration.merge(registry: @registry, branch: @branch))
      @state = :running
      add_accessors configuration
      Actor.current
    end

add_accessors(configuration) click to toggle source

    # File lib/celluloid/supervision/container.rb, line 79
    def add_accessors(configuration)
      if configuration[:as]
        unless methods.include? configuration[:as]
          self.class.instance_eval do
            define_method(configuration[:as]) do
              @registry[configuration[:as]]
            end
          end
        end
      end
    end

find(actor) click to toggle source

    # File lib/celluloid/supervision/container.rb, line 104
    def find(actor)
      @actors.find do |instance|
        instance.actor == actor
      end
    end

remove(actor) click to toggle source

    # File lib/celluloid/supervision/container.rb, line 94
    def remove(actor)
      actor = Celluloid::Actor[actor] if actor.is_a? Symbol
      instance = find(actor)
      instance.terminate if instance
    end

remove_accessors() click to toggle source

    # File lib/celluloid/supervision/container.rb, line 91
    def remove_accessors
    end

restart_actor(actor, reason) click to toggle source

Restart a crashed actor

    # File lib/celluloid/supervision/container.rb, line 115
    def restart_actor(actor, reason)
      return if @state == :shutdown
      instance = find(actor)
      fail "a container instance went missing. This shouldn't be!" unless instance

      if reason
        exclusive { instance.restart }
      else
        instance.cleanup
        @actors.delete(instance)
      end
    end

shutdown() click to toggle source

    # File lib/celluloid/supervision/container.rb, line 128
    def shutdown
      @state = :shutdown
      finalize
    end

supervise(*args, &block) click to toggle source

    # File lib/celluloid/supervision/deprecate/supervise.rb, line 95
    def supervise(*args, &block)
      add(Configuration.options(args, block: block))
    end

supervise_as(name, *args, &block) click to toggle source

    # File lib/celluloid/supervision/deprecate/supervise.rb, line 100
    def supervise_as(name, *args, &block)
      add(Configuration.options(args, block: block, as: name))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.