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.



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

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



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

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



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

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