Sha256: 4d150aa884ed786dbb94e572f7f0d63de5fef6481baa2e098426e136a5b71f5f

Contents?: true

Size: 765 Bytes

Versions: 6

Compression:

Stored size: 765 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
  
  # Extend the actor module with the registry methods
  module Actor
    extend Registry
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
celluloid-0.2.2 lib/celluloid/registry.rb
celluloid-0.2.1 lib/celluloid/registry.rb
celluloid-0.2.0 lib/celluloid/registry.rb
celluloid-0.1.0 lib/celluloid/registry.rb
celluloid-0.0.3 lib/celluloid/registry.rb
celluloid-0.0.1 lib/celluloid/registry.rb