Class: Simple::Sharding::ConnectionHandler
- Inherits:
-
Object
- Object
- Simple::Sharding::ConnectionHandler
show all
- Defined in:
- lib/simple/sharding/connection_handler.rb
Defined Under Namespace
Classes: ConnectionPoolOwner
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.connected?(shard_id) ⇒ Boolean
39
40
41
|
# File 'lib/simple/sharding/connection_handler.rb', line 39
def self.connected?(shard_id)
connection_handler.connected?(connection_pool_owner(shard_id))
end
|
.connection_handler ⇒ Object
26
27
28
29
|
# File 'lib/simple/sharding/connection_handler.rb', line 26
def self.connection_handler
raise 'Shards::ConnectionHandler was not setup' unless defined? @@connection_handler
@@connection_handler
end
|
.connection_pool(shard_id) ⇒ Object
31
32
33
|
# File 'lib/simple/sharding/connection_handler.rb', line 31
def self.connection_pool(shard_id)
connection_handler.retrieve_connection_pool(connection_pool_owner(shard_id))
end
|
.connection_pool_owner(shard_id) ⇒ Object
47
48
49
|
# File 'lib/simple/sharding/connection_handler.rb', line 47
def self.connection_pool_owner(shard_id)
@@connection_pool_owners[shard_id] ||= ConnectionPoolOwner.new(shard_id)
end
|
.remove_connection(shard_id) ⇒ Object
43
44
45
|
# File 'lib/simple/sharding/connection_handler.rb', line 43
def self.remove_connection(shard_id)
connection_handler.remove_connection(connection_pool_owner(shard_id))
end
|
.retrie_connection(shard_id) ⇒ Object
35
36
37
|
# File 'lib/simple/sharding/connection_handler.rb', line 35
def self.retrie_connection(shard_id)
connection_handler.retrieve_connection(connection_pool_owner(shard_id))
end
|
.setup ⇒ Object
21
22
23
24
|
# File 'lib/simple/sharding/connection_handler.rb', line 21
def self.setup
@@connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
@@connection_pool_owners = {}
end
|
Instance Method Details
#check(shard_id) ⇒ Object
4
5
6
|
# File 'lib/simple/sharding/connection_handler.rb', line 4
def check(shard_id)
shard_id.present?
end
|
#connect(shard_id) ⇒ Object
15
16
17
18
19
|
# File 'lib/simple/sharding/connection_handler.rb', line 15
def connect(shard_id)
resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(Config.config(shard_id))
connect_spec = resolver.spec(shard_id.to_sym)
connect_spec
end
|
#connect_all ⇒ Object
9
10
11
12
13
|
# File 'lib/simple/sharding/connection_handler.rb', line 9
def connect_all
Core.config.keys.each do |shard_id|
connect(shard_id)
end
end
|