Sha256: a839665f0a32bf059d47a999e8931595102db5d0413b282cdea140a1b132dd8b

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

require 'thread'

module Celluloid
  # The Registry allows us to refer to specific actors by human-meaningful names
  class Registry
    def initialize
      @registry = {}
      @registry_lock = Mutex.new
    end

    # Register an Actor
    def []=(name, actor)
      actor_singleton = class << actor; self; end
      unless actor_singleton.ancestors.include? AbstractProxy
        raise TypeError, "not an actor"
      end

      @registry_lock.synchronize do
        @registry[name.to_sym] = actor
      end

      actor.mailbox << NamingRequest.new(name.to_sym)
    end

    # Retrieve an actor by name
    def [](name)
      @registry_lock.synchronize do
        @registry[name.to_sym]
      end
    end

    alias_method :get, :[]
    alias_method :set, :[]=

    def delete(name)
      @registry_lock.synchronize do
        @registry.delete name.to_sym
      end
    end

    # List all registered actors by name
    def names
      @registry_lock.synchronize { @registry.keys }
    end

    # removes and returns all registered actors as a hash of `name => actor`
    # can be used in testing to clear the registry
    def clear
      hash = nil
      @registry_lock.synchronize do
        hash = @registry.dup
        @registry.clear
      end
      hash
    end
  end
end

Version data entries

9 entries across 7 versions & 4 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/celluloid-0.16.0/lib/celluloid/registry.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/registry.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/registry.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/registry.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/celluloid-0.16.0/lib/celluloid/registry.rb
celluloid-0.16.0 lib/celluloid/registry.rb
celluloid-0.16.0.pre3 lib/celluloid/registry.rb
celluloid-0.16.0.pre2 lib/celluloid/registry.rb
celluloid-0.16.0.pre lib/celluloid/registry.rb