Class: Influxdb::Api::Client::ConnectionPool
- Inherits:
-
Object
- Object
- Influxdb::Api::Client::ConnectionPool
- Defined in:
- lib/influxdb/api/client/connection_pool.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #all ⇒ Object
- #build_connections ⇒ Object
- #connections ⇒ Object (also: #alive)
- #dead ⇒ Object
- #each(&block) ⇒ Object
- #get_connection ⇒ Object
-
#initialize(config = Influxdb::Api.config) ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
Constructor Details
#initialize(config = Influxdb::Api.config) ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
7 8 9 10 |
# File 'lib/influxdb/api/client/connection_pool.rb', line 7 def initialize(config = Influxdb::Api.config) @config = config @connections = build_connections end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/influxdb/api/client/connection_pool.rb', line 5 def config @config end |
Instance Method Details
#all ⇒ Object
21 22 23 |
# File 'lib/influxdb/api/client/connection_pool.rb', line 21 def all @connections end |
#build_connections ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/influxdb/api/client/connection_pool.rb', line 36 def build_connections config.hosts.map do |host| Connection.new( host, ::Faraday::Connection.new( host, config., &config.connection_block ), config ) end end |
#connections ⇒ Object Also known as: alive
12 13 14 |
# File 'lib/influxdb/api/client/connection_pool.rb', line 12 def connections @connections.reject{|c| c.dead? } end |
#dead ⇒ Object
17 18 19 |
# File 'lib/influxdb/api/client/connection_pool.rb', line 17 def dead @connections.select{|c| c.dead? } end |
#each(&block) ⇒ Object
25 26 27 |
# File 'lib/influxdb/api/client/connection_pool.rb', line 25 def each(&block) connections.each(&block) end |
#get_connection ⇒ Object
29 30 31 32 33 34 |
# File 'lib/influxdb/api/client/connection_pool.rb', line 29 def get_connection if connections.empty? && dead_connection = dead.sort{|a, b| a.failures <=> b.failures }.first dead_connection.alive! end config.selector.select_from(alive) end |