Class: Celluloid::Supervision::Container::Instance

### Home Classes Methods

### In Files

- lib/celluloid/supervision/container/instance.rb

### Parent

Object

### Methods

- ::new
- #cleanup
- #restart
- #start
- #terminate

### 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::Instance

### Attributes

actor[R]
name[R]

### Public Class Methods

new(configuration = {}) click to toggle source

@option options [call, Object] :args ([]) arguments array for the

    actor's constructor (lazy evaluation if it responds to #call)

    # File lib/celluloid/supervision/container/instance.rb, line 10
    def initialize(configuration = {})
      @type = configuration.delete(:type)
      @registry = configuration.delete(:registry)
      @branch = configuration.delete(:branch) || :services
      @configuration = configuration

      # allows injections inside initialize, start, and restart
      @injections = configuration.delete(:injections) || {}
      invoke_injection(:before_initialize)

      # Stringify keys :/
      # de @configuration = configuration.each_with_object({}) { |(k,v), h| h[k.to_s] = v }

      @name = @configuration[:as]
      @block = @configuration[:block]
      @args = prepare_args(@configuration[:args])
      @method = @configuration[:method] || "new_link"
      add_accessors
      invoke_injection(:after_initialize)
      start
    end

### Public Instance Methods

cleanup() click to toggle source

    # File lib/celluloid/supervision/container/instance.rb, line 67
    def cleanup
      @registry.delete(@name) if @name
    end

restart() click to toggle source

    # File lib/celluloid/supervision/container/instance.rb, line 52
    def restart
      # no need to reset @actor, as this is called in an `exclusive {}` block
      # @actor = nil
      # cleanup
      invoke_injection(:before_restart)
      start
      invoke_injection(:after_restart)
    end

start() click to toggle source

    # File lib/celluloid/supervision/container/instance.rb, line 32
    def start
      invoke_injection(:before_start)
      @actor = @type.send(@method, *@args, &@block)
      @registry.add(@name, @actor, @branch) if @name
      invoke_injection(:after_start)
    rescue Celluloid::TaskTimeout => ex
      Internals::Logger.error("TaskTimeout at start of supervised instance of #{@type}")
      raise ex
      #           TODO: Implement timeout/retry.
      #           unless ( @retry += 1 ) <= INSTANCE_RETRY_LIMIT
      #             raise ex
      #           end
      #           Internals::Logger.warn("TaskTimeout at start of supervised actor. Retrying in #{INSTANCE_RETRY_WAIT} seconds. ( Attempt #{@retry} of #{INSTANCE_RETRY_LIMIT} )")
      #           sleep INSTANCE_RETRY_WAIT
      #           retry
    rescue => ex
      Internals::Logger.error("Error ( #{ex.class} ) at start of supervised instance of #{@type}")
      raise ex
    end

terminate() click to toggle source

    # File lib/celluloid/supervision/container/instance.rb, line 61
    def terminate
      @actor.terminate if @actor
      cleanup
    rescue DeadActorError
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.