class Pools::Handler

Attributes

pools[R]

Public Class Methods

new(pools = {}) click to toggle source
# File lib/pools/handler.rb, line 9
def initialize(pools = {})
  @pools = pools
end

Public Instance Methods

add(pool, name = nil) click to toggle source

Add a new connection pool to the mix

# File lib/pools/handler.rb, line 14
def add(pool, name = nil)
  @pools[name || pool.object_id] = pool
end
clear_active_connections!() click to toggle source

Returns any connections in use by the current thread back to the pool, and also returns connections to the pool cached by threads that are no longer alive.

# File lib/pools/handler.rb, line 21
def clear_active_connections!
  @pools.each_value {|pool| pool.release_connection }
end
clear_all_connections!() click to toggle source
# File lib/pools/handler.rb, line 25
def clear_all_connections!
  @pools.each_value {|pool| pool.disconnect! }
end
connected?(name) click to toggle source

Returns true if a connection that's accessible to this class has already been opened.

# File lib/pools/handler.rb, line 36
def connected?(name)
  conn = retrieve_connection_pool(name)
  conn && conn.connected?
end
remove_connection(name) click to toggle source

Remove the connection for this class. This will close the active connection and the defined connection (if they exist). The result can be used as an argument for establish_connection, for easily re-establishing the connection.

# File lib/pools/handler.rb, line 45
def remove_connection(name)
  pool = retrieve_connection_pool(name)
  return nil unless pool

  @pools.delete_if { |key, value| value == pool }
  pool.disconnect!
end
retrieve_connection_pool(name) click to toggle source
# File lib/pools/handler.rb, line 53
def retrieve_connection_pool(name)
  pool = @pools[name]
  return pool if pool
end