class Keymap::ConnectionAdapters::ConnectionHandler

ConnectionHandler is a collection of ConnectionPool objects. It is used for keeping separate connection pools for Keymap objects stored in different databases.

Normally there is only a single ConnectionHandler instance, accessible via Keymap::Base.connection_handler.

Attributes

connection_pools[R]

Public Class Methods

new(pools = {}) click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_pool.rb, line 315
def initialize(pools = {})
  @connection_pools = pools
  @class_to_pool = {}
end

Public Instance Methods

active_connections?() click to toggle source

Returns true if there are any active connections among the connection pools that the ConnectionHandler is managing.

# File lib/keymap/connection_adapters/abstract/connection_pool.rb, line 327
def active_connections?
  connection_pools.values.any? { |pool| pool.active_connection? }
end
clear_active_connections!() click to toggle source

Returns any connections in use by the current thread back to the pool.

# File lib/keymap/connection_adapters/abstract/connection_pool.rb, line 332
def clear_active_connections!
  @connection_pools.each_value { |pool| pool.release_connection }
end
clear_all_connections!() click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_pool.rb, line 341
def clear_all_connections!
  @connection_pools.each_value { |pool| pool.disconnect! }
end
clear_reloadable_connections!() click to toggle source

Clears the cache which maps classes.

# File lib/keymap/connection_adapters/abstract/connection_pool.rb, line 337
def clear_reloadable_connections!
  @connection_pools.each_value { |pool| pool.clear_reloadable_connections! }
end
connected?(klass) click to toggle source

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

# File lib/keymap/connection_adapters/abstract/connection_pool.rb, line 361
def connected?(klass)
  conn = retrieve_connection_pool(klass)
  conn && conn.connected?
end
establish_connection(name, spec) click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_pool.rb, line 320
def establish_connection(name, spec)
  @connection_pools[spec] ||= ConnectionAdapters::ConnectionPool.new(spec)
  @class_to_pool[name] = @connection_pools[spec]
end
remove_connection(klass) 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/keymap/connection_adapters/abstract/connection_pool.rb, line 370
def remove_connection(klass)
  pool = @class_to_pool.delete(klass.name)
  return nil unless pool

  @connection_pools.delete pool.spec
  pool.automatic_reconnect = false
  pool.disconnect!
  pool.spec.config
end
retrieve_connection_pool(klass) click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_pool.rb, line 380
def retrieve_connection_pool(klass)
  pool = @class_to_pool[klass.name]
  return pool if pool
  return nil if Keymap::Base == klass
  retrieve_connection_pool klass.superclass
end