class 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)
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)
Alias for: []=