Class: Makara::Strategies::ShardAware
- Inherits:
-
Abstract
- Object
- Abstract
- Makara::Strategies::ShardAware
show all
- Defined in:
- lib/makara/strategies/shard_aware.rb
Instance Attribute Summary
Attributes inherited from Abstract
#pool
Instance Method Summary
collapse
Methods inherited from Abstract
#initialize
Instance Method Details
#connection_added(wrapper) ⇒ Object
11
12
13
14
|
# File 'lib/makara/strategies/shard_aware.rb', line 11
def connection_added(wrapper)
id = wrapper._makara_shard_id
shard_strategy(id).connection_added(wrapper)
end
|
#current ⇒ Object
26
27
28
29
30
31
|
# File 'lib/makara/strategies/shard_aware.rb', line 26
def current
id = shard_id
raise Makara::Errors::InvalidShard.new(pool.role, id) unless id && @shards[id]
@shards[id].current
end
|
#init ⇒ Object
6
7
8
9
|
# File 'lib/makara/strategies/shard_aware.rb', line 6
def init
@shards = {}
@default_shard = pool.default_shard
end
|
#next ⇒ Object
33
34
35
36
37
38
|
# File 'lib/makara/strategies/shard_aware.rb', line 33
def next
id = shard_id
raise Makara::Errors::InvalidShard.new(pool.role, id) unless id && @shards[id]
@shards[id].next
end
|
#shard_id ⇒ Object
40
41
42
|
# File 'lib/makara/strategies/shard_aware.rb', line 40
def shard_id
Thread.current['makara_shard_id'] || pool.default_shard
end
|
#shard_strategy(shard_id) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/makara/strategies/shard_aware.rb', line 16
def shard_strategy(shard_id)
id = shard_id
shard_strategy = @shards[id]
unless shard_strategy
shard_strategy = pool.shard_strategy_class.new(pool)
@shards[id] = shard_strategy
end
shard_strategy
end
|