Class: Switchman::ConnectionPoolProxy
- Inherits:
-
Object
- Object
- Switchman::ConnectionPoolProxy
- Defined in:
- lib/switchman/connection_pool_proxy.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#schema_cache ⇒ Object
readonly
Returns the value of attribute schema_cache.
Instance Method Summary collapse
- #active_shackles_environment ⇒ Object
- #active_shard ⇒ Object
- #automatic_reconnect=(value) ⇒ Object
- #clear_idle_connections!(since_when) ⇒ Object
- #connection ⇒ Object
- #connections ⇒ Object
- #current_pool ⇒ Object
- #default_pool ⇒ Object
- #discard! ⇒ Object
-
#initialize(category, default_pool, shard_connection_pools) ⇒ ConnectionPoolProxy
constructor
A new instance of ConnectionPoolProxy.
Constructor Details
#initialize(category, default_pool, shard_connection_pools) ⇒ ConnectionPoolProxy
Returns a new instance of ConnectionPoolProxy.
22 23 24 25 26 27 |
# File 'lib/switchman/connection_pool_proxy.rb', line 22 def initialize(category, default_pool, shard_connection_pools) @category = category @default_pool = default_pool @connection_pools = shard_connection_pools @schema_cache = SchemaCache.new(self) end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
16 17 18 |
# File 'lib/switchman/connection_pool_proxy.rb', line 16 def category @category end |
#schema_cache ⇒ Object (readonly)
Returns the value of attribute schema_cache.
16 17 18 |
# File 'lib/switchman/connection_pool_proxy.rb', line 16 def schema_cache @schema_cache end |
Instance Method Details
#active_shackles_environment ⇒ Object
33 34 35 |
# File 'lib/switchman/connection_pool_proxy.rb', line 33 def active_shackles_environment ::Rails.env.test? ? :master : active_shard.database_server.shackles_environment end |
#active_shard ⇒ Object
29 30 31 |
# File 'lib/switchman/connection_pool_proxy.rb', line 29 def active_shard Shard.current(@category) end |
#automatic_reconnect=(value) ⇒ Object
93 94 95 |
# File 'lib/switchman/connection_pool_proxy.rb', line 93 def automatic_reconnect=(value) connection_pools.each { |pool| pool.automatic_reconnect = value } end |
#clear_idle_connections!(since_when) ⇒ Object
97 98 99 |
# File 'lib/switchman/connection_pool_proxy.rb', line 97 def clear_idle_connections!(since_when) connection_pools.each { |pool| pool.clear_idle_connections!(since_when) } end |
#connection ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/switchman/connection_pool_proxy.rb', line 49 def connection pool = current_pool begin connection = pool.connection connection.instance_variable_set(:@schema_cache, @schema_cache) connection rescue ConnectionError raise if active_shard.database_server == Shard.default.database_server && active_shackles_environment == :master configs = active_shard.database_server.config(active_shackles_environment) raise unless configs.is_a?(Array) configs.each_with_index do |config, idx| pool = create_pool(config.dup) begin connection = pool.connection connection.instance_variable_set(:@schema_cache, @schema_cache) rescue ConnectionError raise if idx == configs.length - 1 next end @connection_pools[pool_key] = pool break connection end end end |
#connections ⇒ Object
45 46 47 |
# File 'lib/switchman/connection_pool_proxy.rb', line 45 def connections connection_pools.map(&:connections).inject([], &:+) end |
#current_pool ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/switchman/connection_pool_proxy.rb', line 37 def current_pool current_active_shard = active_shard pool = self.default_pool if current_active_shard.database_server == Shard.default.database_server && active_shackles_environment == :master && (current_active_shard.default? || current_active_shard.database_server.shareable?) pool = @connection_pools[pool_key] ||= create_pool unless pool pool.shard = current_active_shard pool end |
#default_pool ⇒ Object
18 19 20 |
# File 'lib/switchman/connection_pool_proxy.rb', line 18 def default_pool @default_pool end |
#discard! ⇒ Object
89 90 91 |
# File 'lib/switchman/connection_pool_proxy.rb', line 89 def discard! # this breaks everything if i try to pass it onto the pools and i'm not sure why end |