Class: ActiveReplicas::Rails4::ConnectionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/active_replicas/rails4/connection_handler.rb

Overview

Wraps around Rails’ ActiveRecord::ConnectionAdapters::ConnectionHandler to provide proxy wrappers around requested connections.

This is the process-safe handler; it creates instances of ThreadLocalConnectionHandler to provide proxy wrappers for each thread.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proxy_configuration:, delegate: nil, overrides: nil) ⇒ ConnectionHandler



16
17
18
19
20
21
22
23
# File 'lib/active_replicas/rails4/connection_handler.rb', line 16

def initialize(proxy_configuration:, delegate: nil, overrides: nil)
  @proxy_configuration = proxy_configuration
  # @delegate          = delegate
  # @overrides         = Set.new(overrides || [])

  # Each process will get its own thread-safe handler.
  @process_to_handler = Concurrent::Map.new
end

Instance Attribute Details

#proxy_configurationObject

Returns the value of attribute proxy_configuration.



14
15
16
# File 'lib/active_replicas/rails4/connection_handler.rb', line 14

def proxy_configuration
  @proxy_configuration
end

Instance Method Details

#clear_all_connections!Object



31
32
33
34
35
36
37
# File 'lib/active_replicas/rails4/connection_handler.rb', line 31

def clear_all_connections!
  # We also want to clear the process's connection handler in case our
  # configuration has been changed.
  if handler = @process_to_handler.delete(Process.pid)
    handler.clear_all_connections!
  end
end

#retrieve_handlerObject

Returns a ProcessLocalConnectionHandler which is local to the current process.



41
42
43
# File 'lib/active_replicas/rails4/connection_handler.rb', line 41

def retrieve_handler
  @process_to_handler[Process.pid] ||= ProcessLocalConnectionHandler.new(@proxy_configuration)
end