Class: Swift::FiberConnectionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/swift/fiber_connection_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts, &block) ⇒ FiberConnectionPool

Returns a new instance of FiberConnectionPool.



8
9
10
11
12
13
14
15
16
17
# File 'lib/swift/fiber_connection_pool.rb', line 8

def initialize opts, &block
  @reserved  = {}   # map of in-progress connections
  @available = []   # pool of free connections
  @pending   = []   # pending reservations (FIFO)
  @trace     = nil

  opts[:size].times do
    @available.push(block.call)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object (private)

Allow the pool to behave as the underlying connection



69
70
71
72
73
74
75
76
77
# File 'lib/swift/fiber_connection_pool.rb', line 69

def method_missing method, *args, &blk
  __reserve__ do |conn|
    if @trace
      conn.trace(@trace) {conn.__send__(method, *args, &blk)}
    else
      conn.__send__(method, *args, &blk)
    end
  end
end

Instance Method Details

#trace(io = $stdout) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/swift/fiber_connection_pool.rb', line 19

def trace io = $stdout
  if block_given?
    begin
      _io, @trace = @trace, io
      yield
    ensure
      @trace = _io
    end
  else
    @trace = io
  end
end