Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/connection_pool.rb
Class Method Summary collapse
- .clear_active_connections! ⇒ Object
-
.close_all_connections ⇒ Object
closing all is pretty final, you don’t want to do this unless you are really all done.
-
.establish_connection(spec = nil) ⇒ Object
remove_connection.
- .no_cp_clear_active_connections! ⇒ Object
- .no_cp_establish_connection ⇒ Object
- .no_cp_remove_connection ⇒ Object
- .pooled_connections ⇒ Object
- .remove_connection(klass = self) ⇒ Object
Class Method Details
.clear_active_connections! ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/connection_pool.rb', line 15 def clear_active_connections! active_connections.each do |name, conn| conn_key = nil pooled_connections.each { |key, value| conn_key = key if value != nil && value[:connection] == conn } pooled_connections.delete(conn_key) if not conn_key.nil? end no_cp_clear_active_connections! end |
.close_all_connections ⇒ Object
closing all is pretty final, you don’t want to do this unless you are really all done
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/connection_pool.rb', line 48 def close_all_connections ar_konn = nil pooled_connections.each do | key, value | pooled_connections.delete(key) active_connections.select do |klass, konn| if konn == value[:connection] result = no_cp_remove_connection(klass.constantize) ar_konn = result if klass.constantize == ActiveRecord::Base end end end ar_konn end |
.establish_connection(spec = nil) ⇒ Object
remove_connection
41 42 43 44 |
# File 'lib/connection_pool.rb', line 41 def establish_connection(spec = nil) pool_connection(spec) if spec != nil and spec.kind_of?(ActiveRecord::Base::ConnectionSpecification) no_cp_establish_connection(spec) end |
.no_cp_clear_active_connections! ⇒ Object
8 |
# File 'lib/connection_pool.rb', line 8 alias_method :no_cp_clear_active_connections!, :clear_active_connections! |
.no_cp_establish_connection ⇒ Object
7 |
# File 'lib/connection_pool.rb', line 7 alias_method :no_cp_establish_connection, :establish_connection |
.no_cp_remove_connection ⇒ Object
6 |
# File 'lib/connection_pool.rb', line 6 alias_method :no_cp_remove_connection, :remove_connection |
.pooled_connections ⇒ Object
11 12 13 |
# File 'lib/connection_pool.rb', line 11 def pooled_connections @@pooled_connections[Thread.current.object_id] ||= {} end |
.remove_connection(klass = self) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/connection_pool.rb', line 24 def remove_connection(klass=self) konn = active_connections[klass.name] conn_key = nil pooled_connections.each { |key, value| conn_key = key if value != nil && value[:connection] == konn } if conn_key != nil pooled_connections[conn_key][:count] -= 1 if pooled_connections[conn_key][:count] > 0 # remove it from the active list so that AR wont disconnect until 0 references active_connections.delete(klass.name) else # must be time to clean up. pooled_connections.delete(conn_key) end end no_cp_remove_connection(klass) end |