Module: Rmega::ConnPool

Extended by:
MonitorMixin
Includes:
Loggable, Options
Defined in:
lib/rmega/conn_pool.rb

Defined Under Namespace

Classes: ConnectionManager

Class Method Summary collapse

Methods included from Options

included, #options

Methods included from Loggable

included, #logger

Class Method Details

.connection_managerObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rmega/conn_pool.rb', line 14

def self.connection_manager
  synchronize do
    @connection_managers ||= []

    # we first clear all old ones
    removed = @connection_managers.reject!(&:stale?)
    (removed || []).each(&:close_connections!)
    
    # get the manager
    Thread.current[:http_connection_manager] ||= self.synchronize do
      manager = ConnectionManager.new
      @connection_managers << manager
      manager
    end
  end
end

.get(url, options = {}) ⇒ Object

url: URI / String options: any options that Net::HTTP.new accepts



9
10
11
12
# File 'lib/rmega/conn_pool.rb', line 9

def self.get(url, options = {})
  uri = url.is_a?(URI) ? url : URI(url)
  connection_manager.get_client(uri, options)
end