Class: ActiveRecordHostPool::PoolProxy
- Inherits:
-
Delegator
- Object
- Delegator
- ActiveRecordHostPool::PoolProxy
- Includes:
- Mutex_m
- Defined in:
- lib/active_record_host_pool/pool_proxy_6_1.rb,
lib/active_record_host_pool/pool_proxy_legacy.rb
Overview
Sits between ConnectionHandler and a bunch of different ConnectionPools (one per host).
Instance Attribute Summary collapse
-
#pool_config ⇒ Object
readonly
Returns the value of attribute pool_config.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #__setobj__(spec) ⇒ Object
- #_unproxied_connection(*args) ⇒ Object
- #automatic_reconnect=(value) ⇒ Object
- #checkin(cx) ⇒ Object
-
#checkout(*args, &block) ⇒ Object
by the time we are patched into ActiveRecord, the current thread has already established a connection.
- #clear_reloadable_connections! ⇒ Object
- #connection(*args) ⇒ Object
- #discard! ⇒ Object
- #disconnect! ⇒ Object
- #flush! ⇒ Object
-
#initialize(spec) ⇒ PoolProxy
constructor
A new instance of PoolProxy.
- #release_connection(*args) ⇒ Object
- #with_connection ⇒ Object
Constructor Details
#initialize(spec) ⇒ PoolProxy
Returns a new instance of PoolProxy.
21 22 23 24 25 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 21 def initialize(pool_config) super(pool_config) @pool_config = pool_config @config = pool_config.db_config.configuration_hash end |
Instance Attribute Details
#pool_config ⇒ Object (readonly)
Returns the value of attribute pool_config.
37 38 39 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 37 def pool_config @pool_config end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
36 37 38 |
# File 'lib/active_record_host_pool/pool_proxy_legacy.rb', line 36 def spec @spec end |
Instance Method Details
#__getobj__ ⇒ Object
27 28 29 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 27 def __getobj__ _connection_pool end |
#__setobj__(spec) ⇒ Object
31 32 33 34 35 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 31 def __setobj__(pool_config) @pool_config = pool_config @config = pool_config.db_config.configuration_hash @_pool_key = nil end |
#_unproxied_connection(*args) ⇒ Object
47 48 49 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 47 def _unproxied_connection(*args) _connection_pool.connection(*args) end |
#automatic_reconnect=(value) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 81 def automatic_reconnect=(value) p = _connection_pool(false) return unless p p.automatic_reconnect = value end |
#checkin(cx) ⇒ Object
58 59 60 61 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 58 def checkin(cx) cx = cx.unproxied _connection_pool.checkin(cx) end |
#checkout(*args, &block) ⇒ Object
by the time we are patched into ActiveRecord, the current thread has already established a connection. thus we need to patch both connection and checkout/checkin
53 54 55 56 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 53 def checkout(*args, &block) cx = _connection_pool.checkout(*args, &block) _connection_proxy_for(cx, @config[:database]) end |
#clear_reloadable_connections! ⇒ Object
88 89 90 91 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 88 def clear_reloadable_connections! _connection_pool.clear_reloadable_connections! _clear_connection_proxy_cache end |
#connection(*args) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 39 def connection(*args) real_connection = _unproxied_connection(*args) _connection_proxy_for(real_connection, @config[:database]) rescue Mysql2::Error, ActiveRecord::NoDatabaseError _connection_pools.delete(_pool_key) Kernel.raise end |
#discard! ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 107 def discard! p = _connection_pool(false) return unless p p.discard! # All connections in the pool (even if they're currently # leased!) have just been discarded, along with the pool itself. # Any further interaction with the pool (except #pool_config and #schema_cache) # is undefined. # Remove the connection for the given key so a new one can be created in its place _connection_pools.delete(_pool_key) end |
#disconnect! ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 70 def disconnect! p = _connection_pool(false) return unless p synchronize do p.disconnect! p.automatic_reconnect = true _clear_connection_proxy_cache end end |
#flush! ⇒ Object
100 101 102 103 104 105 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 100 def flush! p = _connection_pool(false) return unless p p.flush! end |
#release_connection(*args) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 93 def release_connection(*args) p = _connection_pool(false) return unless p p.release_connection(*args) end |
#with_connection ⇒ Object
63 64 65 66 67 68 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 63 def with_connection cx = checkout yield cx ensure checkin cx end |