class Supervision::Registry

A class responsible for registering/unregistering circuits

Public Class Methods

new() click to toggle source

Initialize a Registry

@api public

# File lib/supervision/registry.rb, line 9
def initialize
  @lock = Mutex.new
  @map = {}
end

Public Instance Methods

[](name) click to toggle source

Retrieve a circuit by name

@param [String] name

@api public

# File lib/supervision/registry.rb, line 40
def [](name)
  @lock.synchronize do
    @map[name.to_sym]
  end
end
Also aliased as: get
[]=(name, circuit) click to toggle source

Register a circuit

@param [String] name

the name under which to register

@param [Supervision::CircuitBreaker] circuit

the registered circuit breaker

@api public

# File lib/supervision/registry.rb, line 23
def []=(name, circuit)
  unless circuit.is_a?(CircuitBreaker)
    raise TypeError, 'not a type of circuit breaker'
  end
  if registered?(name)
    raise DuplicateEntryError, "`#{name}` is already registered"
  end
  @lock.synchronize do
    @map[name.to_sym] = circuit
  end
end
Also aliased as: register
clear() click to toggle source

Remove all registered circuits

@example

registry.clear

@return [Hash]

@api public

# File lib/supervision/registry.rb, line 94
def clear
  hash = nil
  @lock.synchronize do
    hash = @map.dup
    @map.clear
  end
  hash
end
delete(name) click to toggle source

Remove from registry

@api public

# File lib/supervision/registry.rb, line 49
def delete(name)
  @lock.synchronize do
    @map.delete name.to_sym
  end
end
Also aliased as: unregister
empty?() click to toggle source

Check if registry is empty or not

@return [Boolean]

@api public

# File lib/supervision/registry.rb, line 82
def empty?
  @lock.synchronize { @map.empty? }
end
get(name)
Alias for: []
names() click to toggle source

Retrieve registered circuits' names

@return [Array]

@api public

# File lib/supervision/registry.rb, line 73
def names
  @lock.synchronize { @map.keys }
end
register(name, circuit)
Alias for: []=
registered?(name) click to toggle source

Check if circuit is in registry

@return [Boolean]

@api public

# File lib/supervision/registry.rb, line 64
def registered?(name)
  names.include?(name) || names.include?(name.to_sym)
end
unregister(name)
Alias for: delete