Module: Celluloid::Registry

Included in:
Actor
Defined in:
lib/vendor/celluloid/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



22
23
24
25
26
# File 'lib/vendor/celluloid/lib/celluloid/registry.rb', line 22

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
# File 'lib/vendor/celluloid/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
end

#registeredObject

List all registered actors by name



29
30
31
# File 'lib/vendor/celluloid/lib/celluloid/registry.rb', line 29

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