Sha256: 490d6d35cc92d801342d53a053bc77e86d8c6c5d92716611f7cd707d9e9896ab

Contents?: true

Size: 667 Bytes

Versions: 3

Compression:

Stored size: 667 Bytes

Contents

require 'thread'

module Celluloid
  # The Registry allows us to refer to specific actors by human-meaningful names
  module Registry
    @@registry = {}
    @@registry_lock = Mutex.new
    
    # Register an Actor
    def []=(name, actor)
      actor_singleton = class << actor; self; end
      unless actor_singleton.ancestors.include?(Celluloid::ActorProxy)
        raise ArgumentError, "not an actor"
      end
      
      @@registry_lock.synchronize do
        @@registry[name.to_sym] = actor
      end
    end
    
    # Retrieve an actor by name
    def [](name)
      @@registry_lock.synchronize do
        @@registry[name.to_sym]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
celluloid-0.6.1 lib/celluloid/registry.rb
celluloid-0.6.0 lib/celluloid/registry.rb
celluloid-0.5.0 lib/celluloid/registry.rb