class Recurly::ConnectionPool
Public Class Methods
Source
# File lib/recurly/connection_pool.rb, line 7 def initialize @mutex = Mutex.new @pool = Hash.new { |h, k| h[k] = [] } end
Public Instance Methods
Source
# File lib/recurly/connection_pool.rb, line 32 def init_http_connection(uri, keep_alive_timeout, ca_file) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" http.ca_file = ca_file http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.keep_alive_timeout = keep_alive_timeout http end
Source
# File lib/recurly/connection_pool.rb, line 12 def with_connection(uri:, keep_alive_timeout:, ca_file: nil) http = nil @mutex.synchronize do http = @pool[[uri.host, uri.port]].pop end # create connection if the pool was empty http ||= init_http_connection(uri, keep_alive_timeout, ca_file) response = yield http if http.started? @mutex.synchronize do @pool[[uri.host, uri.port]].push(http) end end response end