Class: ActiveRecordHostPool::PoolProxy
- Inherits:
-
Delegator
- Object
- Delegator
- ActiveRecordHostPool::PoolProxy
- 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.
25 26 27 28 29 30 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 25 def initialize(pool_config) super @pool_config = pool_config @config = pool_config.db_config.configuration_hash @mutex = Mutex.new end |
Instance Attribute Details
#pool_config ⇒ Object (readonly)
Returns the value of attribute pool_config.
42 43 44 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 42 def pool_config @pool_config end |
Instance Method Details
#__getobj__ ⇒ Object
32 33 34 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 32 def __getobj__ _connection_pool end |
#__setobj__(pool_config) ⇒ Object
36 37 38 39 40 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 36 def __setobj__(pool_config) @pool_config = pool_config @config = pool_config.db_config.configuration_hash @_pool_key = nil end |
#automatic_reconnect=(value) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 141 def automatic_reconnect=(value) p = _connection_pool(false) return unless p p.automatic_reconnect = value end |
#checkin(cx) ⇒ Object
81 82 83 84 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 81 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
76 77 78 79 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 76 def checkout(*args, &block) cx = _connection_pool.checkout(*args, &block) _connection_proxy_for(cx, @config[:database]) end |
#clear_reloadable_connections! ⇒ Object
148 149 150 151 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 148 def clear_reloadable_connections! _connection_pool.clear_reloadable_connections! _clear_connection_proxy_cache end |
#discard! ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 167 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
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 130 def disconnect! p = _connection_pool(false) return unless p @mutex.synchronize do p.disconnect! p.automatic_reconnect = true _clear_connection_proxy_cache end end |
#flush! ⇒ Object
160 161 162 163 164 165 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 160 def flush! p = _connection_pool(false) return unless p p.flush! end |
#release_connection(*args) ⇒ Object
153 154 155 156 157 158 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 153 def release_connection(*args) p = _connection_pool(false) return unless p p.release_connection(*args) end |