Class: ConnectionPool
- Inherits:
-
Object
- Object
- ConnectionPool
- Defined in:
- lib/thrift_client/pool.rb
Direct Known Subclasses
Instance Method Summary collapse
- #destroy ⇒ Object
- #execute ⇒ Object
-
#initialize(opts, &block) ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
-
#status ⇒ Hash
Returns current pool utilization.
Constructor Details
#initialize(opts, &block) ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/thrift_client/pool.rb', line 3 def initialize(opts, &block) @idle = [] #空闲的连接 @active = {} #活动的连接 @pending = [] #等待的线程或纤程id opts[:size].times do @idle.push(block.call) if block_given? end @size = opts[:size] @state = true # mark this pool active end |
Instance Method Details
#destroy ⇒ Object
30 31 32 |
# File 'lib/thrift_client/pool.rb', line 30 def destroy raise NotImplementedError end |
#execute ⇒ Object
14 15 16 |
# File 'lib/thrift_client/pool.rb', line 14 def execute raise NotImplementedError end |
#status ⇒ Hash
Returns current pool utilization.
21 22 23 24 25 26 27 28 |
# File 'lib/thrift_client/pool.rb', line 21 def status { state: state, idle: @idle.size, active: @active.size, pending: @pending.size } end |