class Makara::Strategies::ShardAware

Public Instance Methods

connection_added(wrapper) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/makara/strategies/shard_aware.rb, line 6
def init
  @shards = {}
  @default_shard = pool.default_shard
end
next() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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