class MixedGauge::ClusterConfig

Mapping of slot -> connection_name.

Attributes

connection_registry[R]
name[R]

Public Class Methods

new(name) click to toggle source

@param [Symbol] name

# File lib/mixed_gauge/cluster_config.rb, line 7
def initialize(name)
  @name = name
  @connection_registry = {}
end

Public Instance Methods

connections() click to toggle source

@return [Array<Symbol>] An array of connection name

# File lib/mixed_gauge/cluster_config.rb, line 41
def connections
  @connection_registry.values
end
define_slot_size(n) click to toggle source

@param [Integer] size The slot size of this cluster.

# File lib/mixed_gauge/cluster_config.rb, line 13
def define_slot_size(n)
  @slots = 0..(n - 1)
end
fetch(slot) click to toggle source

@param [Integer] slot @return [Symbol] registered connection name

# File lib/mixed_gauge/cluster_config.rb, line 36
def fetch(slot)
  @connection_registry.find { |slot_range, _name| slot_range.cover?(slot) }[1]
end
register(assigned_slots, connection) click to toggle source

@param [Range] assigned_slots The assigned range of slots of given

connection (shard).

@param [Symbol] connection connection name

# File lib/mixed_gauge/cluster_config.rb, line 20
def register(assigned_slots, connection)
  @connection_registry[assigned_slots] = connection
end
slot_size() click to toggle source

@return [Integer]

# File lib/mixed_gauge/cluster_config.rb, line 30
def slot_size
  defined?(@slot_size) ? @slot_size : @slot_size = @slots.size
end
validate_config!() click to toggle source

@raise [RuntimeError]

# File lib/mixed_gauge/cluster_config.rb, line 25
def validate_config!
  Validator.new(slot_size, @connection_registry).validate!
end