Class: Net::Hippie::ConnectionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/net/hippie/connection_pool.rb

Overview

Thread-safe connection pool with LRU eviction.

Instance Method Summary collapse

Constructor Details

#initialize(max_size: 100, dns_ttl: 300) ⇒ ConnectionPool

Returns a new instance of ConnectionPool.



7
8
9
10
11
12
# File 'lib/net/hippie/connection_pool.rb', line 7

def initialize(max_size: 100, dns_ttl: 300)
  @max_size = max_size
  @dns_ttl = dns_ttl
  @connections = {}
  @monitor = Monitor.new
end

Instance Method Details

#checkout(key, &block) ⇒ Object



14
15
16
# File 'lib/net/hippie/connection_pool.rb', line 14

def checkout(key, &block)
  reuse(key) || create(key, &block)
end

#close_allObject



18
19
20
21
22
23
# File 'lib/net/hippie/connection_pool.rb', line 18

def close_all
  @monitor.synchronize do
    @connections.each_value(&:close)
    @connections.clear
  end
end