Class: EbisuConnection::Replica
- Inherits:
-
Object
- Object
- EbisuConnection::Replica
- Defined in:
- lib/ebisu_connection/replica.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #active_connection? ⇒ Boolean
- #connection ⇒ Object
- #disconnect! ⇒ Object
-
#initialize(conf, spec_name) ⇒ Replica
constructor
A new instance of Replica.
- #put_aside! ⇒ Object
- #release_connection ⇒ Object
Constructor Details
#initialize(conf, spec_name) ⇒ Replica
Returns a new instance of Replica.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ebisu_connection/replica.rb', line 7 def initialize(conf, spec_name) case conf when String host, weight = conf.split(/\s*,\s*/) @hostname, @port = host.split(/\s*:\s*/) when Hash @hostname = conf["host"] || conf[:host] weight = conf["weight"] || conf[:weight] @port = conf["port"] || conf[:port] else raise ArgumentError, "replica config is invalid" end spec = FreshConnection::ConnectionSpecification.new( spec_name, modify_spec: modify_spec ).spec @pool = ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec) @weight = (weight || 1).to_i end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
5 6 7 |
# File 'lib/ebisu_connection/replica.rb', line 5 def hostname @hostname end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
5 6 7 |
# File 'lib/ebisu_connection/replica.rb', line 5 def weight @weight end |
Instance Method Details
#active_connection? ⇒ Boolean
39 40 41 |
# File 'lib/ebisu_connection/replica.rb', line 39 def active_connection? @pool.active_connection? end |
#connection ⇒ Object
28 29 30 |
# File 'lib/ebisu_connection/replica.rb', line 28 def connection @pool.connection end |
#disconnect! ⇒ Object
47 48 49 |
# File 'lib/ebisu_connection/replica.rb', line 47 def disconnect! @pool.disconnect! end |
#put_aside! ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ebisu_connection/replica.rb', line 32 def put_aside! return unless active_connection? return if connection.transaction_open? release_connection end |
#release_connection ⇒ Object
43 44 45 |
# File 'lib/ebisu_connection/replica.rb', line 43 def release_connection @pool.release_connection end |