class Celluloid::Registry
The Registry allows us to refer to specific actors by human-meaningful names
Attributes
root[R]
Public Class Methods
new()
click to toggle source
# File lib/celluloid/registry.rb, line 10 def initialize @registry = {} @registry_lock = Mutex.new end
Public Instance Methods
[](name)
click to toggle source
Retrieve an actor by name
# File lib/celluloid/registry.rb, line 30 def [](name) @registry_lock.synchronize do @registry[name.to_sym] end end
Also aliased as: get
[]=(name, actor)
click to toggle source
Register an Actor
# File lib/celluloid/registry.rb, line 16 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 << NamingRequest.new(name.to_sym) end
Also aliased as: set
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/registry.rb, line 52 def clear hash = nil @registry_lock.synchronize do hash = @registry.dup @registry.clear end hash end
delete(name)
click to toggle source
# File lib/celluloid/registry.rb, line 39 def delete(name) @registry_lock.synchronize do @registry.delete name.to_sym end end
names()
click to toggle source
List all registered actors by name
# File lib/celluloid/registry.rb, line 46 def names @registry_lock.synchronize { @registry.keys } end