Class: Celluloid::Internals::Registry

### Home Classes Methods

### In Files

- lib/celluloid/internals/registry.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #add
- #branch
- #clear
- #delete
- #get
- #include?
- #index
- #names
- #set

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::Incident
- Celluloid::IncidentLogger
- Celluloid::IncidentLogger::Severity
- Celluloid::IncidentReporter
- Celluloid::IncidentReporter::Formatter
- Celluloid::Internals
- Celluloid::Internals::CPUCounter
- Celluloid::Internals::CallChain
- Celluloid::Internals::Handler
- Celluloid::Internals::Handlers
- Celluloid::Internals::Links
- Celluloid::Internals::Logger
- Celluloid::Internals::Logger::WithBacktrace
- Celluloid::Internals::Method
- Celluloid::Internals::Properties
- Celluloid::Internals::Receiver
- Celluloid::Internals::Receivers
- Celluloid::Internals::Registry
- Celluloid::Internals::Response
- Celluloid::Internals::Response::Block
- Celluloid::Internals::Response::Error
- Celluloid::Internals::Response::Success
- Celluloid::Internals::Signals
- Celluloid::Internals::Stack
- Celluloid::Internals::Stack::ActorState
- Celluloid::Internals::Stack::CellState
- Celluloid::Internals::Stack::DisplayBacktrace
- Celluloid::Internals::Stack::Dump
- Celluloid::Internals::Stack::Summary
- Celluloid::Internals::Stack::TaskState
- Celluloid::Internals::Stack::ThreadState
- Celluloid::Internals::TaskSet
- Celluloid::Internals::ThreadHandle
- Celluloid::Internals::UUID
- Celluloid::LogEvent
- Celluloid::Notifications
- Celluloid::Notifications::Fanout
- Celluloid::Notifications::Subscriber
- Celluloid::Probe
- Celluloid::RingBuffer

No matching classes.

# Celluloid::Internals::Registry

The Registry allows us to refer to specific actors by human-meaningful names

### Public Class Methods

new() click to toggle source

    # File lib/celluloid/internals/registry.rb, line 7
    def initialize
      @root = nil     # keep root out of the standard list of registered names
      @actors = {}    # hash of name => actor
      @index = {}     # hash of name => branch
      @branches = {}  # hash of branch => [ actors ]
      @registry = Mutex.new
    end

### Public Instance Methods

[](name) click to toggle source

Retrieve an actor by name

    # File lib/celluloid/internals/registry.rb, line 53
    def [](name)
      return @root if name == :root
      @registry.synchronize do
        @actors[name.to_sym]
      end
    end

Also aliased as: get
[]=(name, actor) click to toggle source

Register an Actor

    # File lib/celluloid/internals/registry.rb, line 16
    def []=(name, actor)
      if name == :root
        @registry.synchronize do
          @root = actor
        end
      else
        actor_singleton = class << actor; self; end
        unless actor_singleton.ancestors.include? Proxy::Abstract
          fail TypeError, "not an actor"
        end

        #           if actor.class.ancestors.include? Supervision::Container
        #             puts "Supervisor: #{actor.links.inspect}"
        #           end
        @registry.synchronize do
          @actors[name.to_sym] = actor
        end
        actor.mailbox << NamingRequest.new(name.to_sym)
      end
    end

Also aliased as: set
add(name, actor, branch=:services) click to toggle source

    # File lib/celluloid/internals/registry.rb, line 37
    def add(name, actor, branch=:services)
      set(name, actor)
      @registry.synchronize do
        unless @branches.key? branch
          @branches[branch] = []
          self.class.instance_eval do
            remove_method(branch) rescue nil
            define_method(branch) { @branches[branch] }
          end
          @branches[branch] << name
        end
        @index[name.to_sym] = branch
      end
    end

branch(name) click to toggle source

    # File lib/celluloid/internals/registry.rb, line 60
    def branch(name)
      @registry.synchronize do
        @index.select { |a, b| b == name }
      end
    end

clear() click to toggle source

removes and returns all registered actors as a hash of `name => actor` can be used in testing to clear the registry

    # File lib/celluloid/internals/registry.rb, line 91
    def clear
      hash = nil
      @registry.synchronize do
        hash = @actors.dup
        @actors.clear
        @index.clear
      end
      hash
    end

delete(name) click to toggle source

    # File lib/celluloid/internals/registry.rb, line 69
    def delete(name)
      @registry.synchronize do
        @index.delete name.to_sym
        @actors.delete name.to_sym
      end
    end

get(name) click to toggle source
Alias for: []
include?(name) click to toggle source

    # File lib/celluloid/internals/registry.rb, line 76
    def include?(name)
      names.include? name
    end

index() click to toggle source

    # File lib/celluloid/internals/registry.rb, line 85
    def index
      @registry.synchronize { @index }
    end

names() click to toggle source

List all registered actors by name

    # File lib/celluloid/internals/registry.rb, line 81
    def names
      @registry.synchronize { @actors.keys }
    end

set(name, actor) click to toggle source
Alias for: []=

[Validate]

Generated with the Darkfish Rdoc Generator 2.