Class: ActiveRecordHostPool::PoolProxy
- Inherits:
-
Delegator
- Object
- Delegator
- ActiveRecordHostPool::PoolProxy
- 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.
18 19 20 21 22 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 18 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.
34 35 36 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 34 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
24 25 26 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 24 def __getobj__ _connection_pool end |
#__setobj__(spec) ⇒ Object
28 29 30 31 32 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 28 def __setobj__(pool_config) @pool_config = pool_config @config = pool_config.db_config.configuration_hash @_pool_key = nil end |
#_unproxied_connection(*args) ⇒ Object
44 45 46 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 44 def _unproxied_connection(*args) _connection_pool.connection(*args) end |
#automatic_reconnect=(value) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 76 def automatic_reconnect=(value) p = _connection_pool(false) return unless p p.automatic_reconnect = value if p.respond_to?(:automatic_reconnect=) end |
#checkin(cx) ⇒ Object
55 56 57 58 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 55 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
50 51 52 53 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 50 def checkout(*args, &block) cx = _connection_pool.checkout(*args, &block) _connection_proxy_for(cx, @config[:database]) end |
#clear_reloadable_connections! ⇒ Object
83 84 85 86 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 83 def clear_reloadable_connections! _connection_pool.clear_reloadable_connections! _clear_connection_proxy_cache end |
#connection(*args) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 36 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
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 102 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
67 68 69 70 71 72 73 74 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 67 def disconnect! p = _connection_pool(false) return unless p p.disconnect! p.automatic_reconnect = true if p.respond_to?(:automatic_reconnect=) _clear_connection_proxy_cache end |
#flush! ⇒ Object
95 96 97 98 99 100 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 95 def flush! p = _connection_pool(false) return unless p p.flush! end |
#release_connection(*args) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 88 def release_connection(*args) p = _connection_pool(false) return unless p p.release_connection(*args) end |
#with_connection ⇒ Object
60 61 62 63 64 65 |
# File 'lib/active_record_host_pool/pool_proxy_6_1.rb', line 60 def with_connection cx = checkout yield cx ensure checkin cx end |