Class: ThreadConnectionPool
- Inherits:
-
ConnectionPool
- Object
- ConnectionPool
- ThreadConnectionPool
- Defined in:
- lib/thrift_client/pool/thread_connection_pool.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy all connections in this pool.
-
#execute ⇒ Object
block.
-
#initialize(opts, &block) ⇒ ThreadConnectionPool
constructor
A new instance of ThreadConnectionPool.
Methods inherited from ConnectionPool
Constructor Details
#initialize(opts, &block) ⇒ ThreadConnectionPool
Returns a new instance of ThreadConnectionPool.
5 6 7 8 9 |
# File 'lib/thrift_client/pool/thread_connection_pool.rb', line 5 def initialize(opts, &block) super @mutex = Mutex.new @condition = ConditionVariable.new end |
Instance Method Details
#destroy ⇒ Object
Destroy all connections in this pool. It will waiting until all connections are idle and than close them one by one.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/thrift_client/pool/thread_connection_pool.rb', line 26 def destroy while @idle.size < @size @mutex.synchronize do @condition.wait(@mutex) end end @idle.each do | conn | begin conn.disconnect rescue Exception => e puts "close connection error! #{e.backtrace}" end end end |
#execute ⇒ Object
block. This will block indefinitely until there is an idle connection to service the request.
14 15 16 17 18 19 20 21 22 |
# File 'lib/thrift_client/pool/thread_connection_pool.rb', line 14 def execute t = Thread.current begin conn = acquire(t) yield conn ensure release(t) end end |