Class: FreshConnection::ReplicaConnectionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/fresh_connection/replica_connection_handler.rb

Instance Method Summary collapse

Constructor Details

#initializeReplicaConnectionHandler

Returns a new instance of ReplicaConnectionHandler.



5
6
7
8
# File 'lib/fresh_connection/replica_connection_handler.rb', line 5

def initialize
  @replica_group_to_pool = Concurrent::Map.new
  @class_to_pool = Concurrent::Map.new
end

Instance Method Details

#clear_all_connections!Object



23
24
25
26
27
# File 'lib/fresh_connection/replica_connection_handler.rb', line 23

def clear_all_connections!
  all_connection_managers do |connection_manager|
    connection_manager.clear_all_connections!
  end
end

#connection(klass) ⇒ Object



19
20
21
# File 'lib/fresh_connection/replica_connection_handler.rb', line 19

def connection(klass)
  detect_connection_manager(klass).replica_connection
end

#establish_connection(name, replica_group) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/fresh_connection/replica_connection_handler.rb', line 10

def establish_connection(name, replica_group)
  if cm = @class_to_pool[name]
    cm.put_aside!
    @class_to_pool.delete(name)
  end

  @replica_group_to_pool[name] = replica_group
end

#put_aside!Object



33
34
35
36
37
# File 'lib/fresh_connection/replica_connection_handler.rb', line 33

def put_aside!
  all_connection_managers do |connection_manager|
    connection_manager.put_aside!
  end
end

#recovery?(klass) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fresh_connection/replica_connection_handler.rb', line 29

def recovery?(klass)
  detect_connection_manager(klass).recovery?
end

#replica_group(klass) ⇒ Object



39
40
41
# File 'lib/fresh_connection/replica_connection_handler.rb', line 39

def replica_group(klass)
  detect_connection_manager(klass).replica_group
end