Class: RedisRing::Client::RingMetaData
- Inherits:
-
Object
- Object
- RedisRing::Client::RingMetaData
- Defined in:
- lib/redis_ring/client/ring_meta_data.rb
Instance Attribute Summary collapse
-
#zookeeper ⇒ Object
readonly
Returns the value of attribute zookeeper.
-
#zookeeper_addr ⇒ Object
readonly
Returns the value of attribute zookeeper_addr.
Instance Method Summary collapse
-
#initialize(zookeeper_addr) ⇒ RingMetaData
constructor
A new instance of RingMetaData.
- #reload! ⇒ Object
- #ring_size ⇒ Object
- #shard(shard_number) ⇒ Object
Constructor Details
#initialize(zookeeper_addr) ⇒ RingMetaData
Returns a new instance of RingMetaData.
10 11 12 |
# File 'lib/redis_ring/client/ring_meta_data.rb', line 10 def initialize(zookeeper_addr) @zookeeper_addr = zookeeper_addr end |
Instance Attribute Details
#zookeeper ⇒ Object (readonly)
Returns the value of attribute zookeeper.
8 9 10 |
# File 'lib/redis_ring/client/ring_meta_data.rb', line 8 def zookeeper @zookeeper end |
#zookeeper_addr ⇒ Object (readonly)
Returns the value of attribute zookeeper_addr.
8 9 10 |
# File 'lib/redis_ring/client/ring_meta_data.rb', line 8 def zookeeper_addr @zookeeper_addr end |
Instance Method Details
#reload! ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/redis_ring/client/ring_meta_data.rb', line 14 def reload! json = get_shards_json_string hash = JSON.parse(json) @ring_size = hash['ring_size'] @shards = (0...@ring_size).map{|n| ShardMetaData.from_json(hash['shards'][n.to_s])} end |
#ring_size ⇒ Object
22 23 24 25 26 |
# File 'lib/redis_ring/client/ring_meta_data.rb', line 22 def ring_size reload! if should_reload? return @ring_size end |
#shard(shard_number) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/redis_ring/client/ring_meta_data.rb', line 28 def shard(shard_number) reload! if should_reload? unless shard_number >= 0 && shard_number < ring_size raise UnknownShardError.new("Shard number invalid: #{shard_number}. Ring size: #{ring_size}") end return @shards[shard_number] end |