Class: ActiveRecordHostPool::PoolProxy
- Inherits:
-
Delegator
- Object
- Delegator
- ActiveRecordHostPool::PoolProxy
- Includes:
- Mutex_m
- Defined in:
- lib/active_record_host_pool/pool_proxy.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.
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #__setobj__(pool_config) ⇒ 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
- #discard! ⇒ Object
- #disconnect! ⇒ Object
- #flush! ⇒ Object
-
#initialize(pool_config) ⇒ PoolProxy
constructor
A new instance of PoolProxy.
- #release_connection(*args) ⇒ Object
Constructor Details
#initialize(pool_config) ⇒ PoolProxy
Returns a new instance of PoolProxy.
28 29 30 31 32 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 28 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.
44 45 46 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 44 def pool_config @pool_config end |
Instance Method Details
#__getobj__ ⇒ Object
34 35 36 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 34 def __getobj__ _connection_pool end |
#__setobj__(pool_config) ⇒ Object
38 39 40 41 42 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 38 def __setobj__(pool_config) @pool_config = pool_config @config = pool_config.db_config.configuration_hash @_pool_key = nil end |
#automatic_reconnect=(value) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 143 def automatic_reconnect=(value) p = _connection_pool(false) return unless p p.automatic_reconnect = value end |
#checkin(cx) ⇒ Object
83 84 85 86 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 83 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
78 79 80 81 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 78 def checkout(*args, &block) cx = _connection_pool.checkout(*args, &block) _connection_proxy_for(cx, @config[:database]) end |
#clear_reloadable_connections! ⇒ Object
150 151 152 153 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 150 def clear_reloadable_connections! _connection_pool.clear_reloadable_connections! _clear_connection_proxy_cache end |
#discard! ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 169 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
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 132 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
162 163 164 165 166 167 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 162 def flush! p = _connection_pool(false) return unless p p.flush! end |
#release_connection(*args) ⇒ Object
155 156 157 158 159 160 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 155 def release_connection(*args) p = _connection_pool(false) return unless p p.release_connection(*args) end |