Class: Tribe::Registry
- Inherits:
-
Object
- Object
- Tribe::Registry
- Defined in:
- lib/tribe/registry.rb
Instance Method Summary collapse
- #[](val) ⇒ Object
- #dispose ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #inspect ⇒ Object
- #register(actor) ⇒ Object
- #unregister(actor) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
3 4 5 6 7 |
# File 'lib/tribe/registry.rb', line 3 def initialize @mutex = Mutex.new @actors_by_name = {} @actors_by_oid = {} end |
Instance Method Details
#[](val) ⇒ Object
29 30 31 32 33 |
# File 'lib/tribe/registry.rb', line 29 def [](val) @mutex.synchronize do return @actors_by_name[val] end end |
#dispose ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/tribe/registry.rb', line 35 def dispose @mutex.synchronize do @actors_by_name.clear @actors_by_oid.clear return nil end end |
#inspect ⇒ Object
44 45 46 47 48 |
# File 'lib/tribe/registry.rb', line 44 def inspect @mutex.synchronize do return "#<#{self.class.to_s}:0x#{(object_id << 1).to_s(16)} oid_count=#{@actors_by_oid.count}, named_count=#{@actors_by_name.count}>" end end |
#register(actor) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tribe/registry.rb', line 9 def register(actor) @mutex.synchronize do raise Tribe::RegistryError.new("Actor already exists (#{actor.name}).") if @actors_by_name.key?(actor.name) @actors_by_name[actor.name] = actor if actor.name @actors_by_oid[actor.object_id] = actor return nil end end |
#unregister(actor) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/tribe/registry.rb', line 20 def unregister(actor) @mutex.synchronize do @actors_by_name.delete(actor.name) if actor.name @actors_by_oid.delete(actor.object_id) return nil end end |