Class: MixedGauge::ClusterConfig
- Inherits:
-
Object
- Object
- MixedGauge::ClusterConfig
- Defined in:
- lib/mixed_gauge/cluster_config.rb
Overview
Mapping of slot -> connection_name.
Defined Under Namespace
Classes: Validator
Instance Attribute Summary collapse
-
#connection_registry ⇒ Object
readonly
Returns the value of attribute connection_registry.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#connections ⇒ Array<Symbol>
An array of connection name.
- #define_slot_size(n) ⇒ Object
-
#fetch(slot) ⇒ Symbol
Registered connection name.
-
#initialize(name) ⇒ ClusterConfig
constructor
A new instance of ClusterConfig.
- #register(assigned_slots, connection) ⇒ Object
- #slot_size ⇒ Integer
- #validate_config! ⇒ Object
Constructor Details
#initialize(name) ⇒ ClusterConfig
Returns a new instance of ClusterConfig.
7 8 9 10 |
# File 'lib/mixed_gauge/cluster_config.rb', line 7 def initialize(name) @name = name @connection_registry = {} end |
Instance Attribute Details
#connection_registry ⇒ Object (readonly)
Returns the value of attribute connection_registry.
4 5 6 |
# File 'lib/mixed_gauge/cluster_config.rb', line 4 def connection_registry @connection_registry end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/mixed_gauge/cluster_config.rb', line 4 def name @name end |
Instance Method Details
#connections ⇒ Array<Symbol>
Returns An array of connection name.
41 42 43 |
# File 'lib/mixed_gauge/cluster_config.rb', line 41 def connections @connection_registry.values end |
#define_slot_size(n) ⇒ Object
13 14 15 |
# File 'lib/mixed_gauge/cluster_config.rb', line 13 def define_slot_size(n) @slots = 0..(n - 1) end |
#fetch(slot) ⇒ Symbol
Returns registered connection name.
36 37 38 |
# 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) ⇒ Object
20 21 22 |
# File 'lib/mixed_gauge/cluster_config.rb', line 20 def register(assigned_slots, connection) @connection_registry[assigned_slots] = connection end |
#slot_size ⇒ Integer
30 31 32 |
# File 'lib/mixed_gauge/cluster_config.rb', line 30 def slot_size defined?(@slot_size) ? @slot_size : @slot_size = @slots.size end |