Class: ConnectionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/thrift_client/pool.rb

Direct Known Subclasses

FiberConnectionPool, ThreadConnectionPool

Instance Method Summary collapse

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

#destroyObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/thrift_client/pool.rb', line 30

def destroy
  raise NotImplementedError
end

#executeObject

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/thrift_client/pool.rb', line 14

def execute
  raise NotImplementedError
end

#statusHash

Returns current pool utilization.

Returns:

  • (Hash)

    Current 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