Module: Celluloid::Registry

Included in:
Actor
Defined in:
lib/celluloid/registry.rb

Overview

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

Constant Summary collapse

@@registry =
{}
@@registry_lock =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object

Retrieve an actor by name



24
25
26
27
28
# File 'lib/celluloid/registry.rb', line 24

def [](name)
  @@registry_lock.synchronize do
    @@registry[name.to_sym]
  end
end

#[]=(name, actor) ⇒ Object

Register an Actor



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/celluloid/registry.rb', line 10

def []=(name, actor)
  actor_singleton = class << actor; self; end
  unless actor_singleton.ancestors.include? ActorProxy
    raise TypeError, "not an actor"
  end

  @@registry_lock.synchronize do
    @@registry[name.to_sym] = actor
  end
  
  actor.mailbox.system_event NamingRequest.new(name.to_sym)
end

#registeredObject

List all registered actors by name



31
32
33
# File 'lib/celluloid/registry.rb', line 31

def registered
  @@registry_lock.synchronize { @@registry.keys }
end