Class: Vault::ConnectionPool
- Inherits:
-
Object
- Object
- Vault::ConnectionPool
- Defined in:
- lib/vault/vendor/connection_pool.rb,
lib/vault/vendor/connection_pool/version.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Error, PoolShuttingDownError, TimedStack, Wrapper
Constant Summary collapse
- DEFAULTS =
{size: 5, timeout: 5}
- VERSION =
"2.2.0"
Class Method Summary collapse
Instance Method Summary collapse
- #checkin ⇒ Object
- #checkout(options = {}) ⇒ Object
-
#initialize(options = {}, &block) ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
- #shutdown(&block) ⇒ Object
-
#with(options = {}) ⇒ Object
jruby 1.7.x.
Constructor Details
#initialize(options = {}, &block) ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vault/vendor/connection_pool.rb', line 48 def initialize( = {}, &block) raise ArgumentError, 'Connection pool requires a block' unless block = DEFAULTS.merge() @size = .fetch(:size) @timeout = .fetch(:timeout) @available = TimedStack.new(@size, &block) @key = :"current-#{@available.object_id}" end |
Class Method Details
Instance Method Details
#checkin ⇒ Object
102 103 104 105 106 107 |
# File 'lib/vault/vendor/connection_pool.rb', line 102 def checkin conn = pop_connection # mutates stack, must be on its own line @available.push(conn) if stack.empty? nil end |
#checkout(options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/vault/vendor/connection_pool.rb', line 90 def checkout( = {}) conn = if stack.empty? timeout = [:timeout] || @timeout @available.pop(timeout: timeout) else stack.last end stack.push conn conn end |
#shutdown(&block) ⇒ Object
109 110 111 |
# File 'lib/vault/vendor/connection_pool.rb', line 109 def shutdown(&block) @available.shutdown(&block) end |
#with(options = {}) ⇒ Object
jruby 1.7.x
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vault/vendor/connection_pool.rb', line 63 def with( = {}) Thread.handle_interrupt(Exception => :never) do conn = checkout() begin Thread.handle_interrupt(Exception => :immediate) do yield conn end ensure checkin end end end |