Class: Kudzu::Agent::Http::ConnectionPool
- Inherits:
-
Object
- Object
- Kudzu::Agent::Http::ConnectionPool
- Defined in:
- lib/kudzu/agent/http/connection_pool.rb
Instance Method Summary collapse
- #checkout(name) ⇒ Object
- #close ⇒ Object
-
#initialize(max_size = 10) ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
Constructor Details
#initialize(max_size = 10) ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
5 6 7 |
# File 'lib/kudzu/agent/http/connection_pool.rb', line 5 def initialize(max_size = 10) @max_size = max_size end |
Instance Method Details
#checkout(name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/kudzu/agent/http/connection_pool.rb', line 9 def checkout(name) pool[name] ||= Connection.new(name: name, http: yield) conn = pool[name] conn.last_used = Time.now if pool.size > @max_size reduce end conn.http end |
#close ⇒ Object
22 23 24 25 26 27 |
# File 'lib/kudzu/agent/http/connection_pool.rb', line 22 def close pool.values.each do |conn| finish_http(conn.http) end Thread.current[:kudzu_connection] = nil end |