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.
7 8 9 |
# File 'lib/kudzu/agent/http/connection_pool.rb', line 7 def initialize(max_size = 10) @max_size = max_size end |
Instance Method Details
#checkout(name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kudzu/agent/http/connection_pool.rb', line 11 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
24 25 26 27 28 29 |
# File 'lib/kudzu/agent/http/connection_pool.rb', line 24 def close pool.values.each do |conn| finish_http(conn.http) end Thread.current[:kudzu_connection] = nil end |