Class: Switchman::ConnectionPoolProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/switchman/connection_pool_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(category, default_pool, shard_connection_pools) ⇒ ConnectionPoolProxy

Returns a new instance of ConnectionPoolProxy.



12
13
14
15
16
# File 'lib/switchman/connection_pool_proxy.rb', line 12

def initialize(category, default_pool, shard_connection_pools)
  @category = category
  @default_pool = default_pool
  @connection_pools = shard_connection_pools
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



6
7
8
# File 'lib/switchman/connection_pool_proxy.rb', line 6

def category
  @category
end

Instance Method Details

#active_shardObject



18
19
20
# File 'lib/switchman/connection_pool_proxy.rb', line 18

def active_shard
  Shard.current(@category)
end

#connectionObject



29
30
31
32
# File 'lib/switchman/connection_pool_proxy.rb', line 29

def connection
  pool = current_pool
  pool.connection
end

#current_poolObject



22
23
24
25
26
27
# File 'lib/switchman/connection_pool_proxy.rb', line 22

def current_pool
  pool = self.default_pool if active_shard.default?
  pool = @connection_pools[pool_key] ||= create_pool unless pool
  pool.shard = active_shard
  pool
end

#default_poolObject



8
9
10
# File 'lib/switchman/connection_pool_proxy.rb', line 8

def default_pool
  @default_pool
end