Class: Vault::PersistentHTTP::Pool

Inherits:
ConnectionPool show all
Defined in:
lib/vault/persistent/pool.rb

Overview

:nodoc:

Constant Summary

Constants inherited from ConnectionPool

ConnectionPool::DEFAULTS, ConnectionPool::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConnectionPool

#shutdown, #with, wrap

Constructor Details

#initialize(options = {}, &block) ⇒ Pool

Returns a new instance of Pool.



10
11
12
13
14
15
# File 'lib/vault/persistent/pool.rb', line 10

def initialize(options = {}, &block)
  super

  @available = PersistentHTTP::TimedStackMulti.new(@size, &block)
  @key = :"current-#{@available.object_id}"
end

Instance Attribute Details

#availableObject (readonly)

:nodoc:



7
8
9
# File 'lib/vault/persistent/pool.rb', line 7

def available
  @available
end

#keyObject (readonly)

:nodoc:



8
9
10
# File 'lib/vault/persistent/pool.rb', line 8

def key
  @key
end

Instance Method Details

#checkin(net_http_args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vault/persistent/pool.rb', line 17

def checkin net_http_args
  stack = Thread.current[@key][net_http_args]

  raise ConnectionPool::Error, 'no connections are checked out' if
    stack.empty?

  conn = stack.pop

  if stack.empty?
    @available.push conn, connection_args: net_http_args
  end

  nil
end

#checkout(net_http_args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vault/persistent/pool.rb', line 32

def checkout net_http_args
  stacks = Thread.current[@key] ||= Hash.new { |h, k| h[k] = [] }
  stack  = stacks[net_http_args]

  if stack.empty? then
    conn = @available.pop @timeout, connection_args: net_http_args
  else
    conn = stack.last
  end

  stack.push conn

  conn
end