Class: FiberConnectionPool

Inherits:
ConnectionPool show all
Defined in:
lib/thrift_client/pool/fiber_connection_pool.rb

Instance Method Summary collapse

Methods inherited from ConnectionPool

#status

Constructor Details

#initialize(opts, &block) ⇒ FiberConnectionPool

Returns a new instance of FiberConnectionPool.



6
7
8
# File 'lib/thrift_client/pool/fiber_connection_pool.rb', line 6

def initialize(opts, &block)
   super
end

Instance Method Details

#destroyObject

Destroy all connections in this pool. It will waiting until all connections are idle and than close them one by one.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/thrift_client/pool/fiber_connection_pool.rb', line 25

def destroy
   while @idle.size < @size
   	fiber = Fiber.current
   	@pending.push fiber
   	Fiber.yield
   end
   @idle.each do | conn |
     begin
       conn.disconnect
     rescue Exception => e
       puts "close connection error! #{e.backtrace}"
     end
   end
end

#executeObject

Choose first idle connection and pass it to the supplied block. This will block indefinitely until there is an idle connection to service the request.



13
14
15
16
17
18
19
20
21
# File 'lib/thrift_client/pool/fiber_connection_pool.rb', line 13

def execute
	f = Fiber.current
	begin
	  conn = acquire(f)
	  yield conn
	ensure
	  release(f)
	end
end