Sha256: 561403421f06428d36214175be783c51f42fea31c348de8d42f52f04a5e1cda1

Contents?: true

Size: 749 Bytes

Versions: 38

Compression:

Stored size: 749 Bytes

Contents

require "net/https"

module Recurly
  class ConnectionPool
    def initialize
      @mutex = Mutex.new
      @pool = []
    end

    def with_connection
      http = nil
      @mutex.synchronize do
        http = @pool.pop
      end

      # create connection if the pool was empty
      http ||= init_http_connection

      response = yield http

      if http.started?
        @mutex.synchronize do
          @pool.push(http)
        end
      end

      response
    end

    def init_http_connection
      http = Net::HTTP.new(Client::BASE_HOST, Client::BASE_PORT)
      http.use_ssl = true
      http.ca_file = Client::CA_FILE
      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
      http.keep_alive_timeout = 600

      http
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
recurly-3.28.0 lib/recurly/connection_pool.rb
recurly-3.27.0 lib/recurly/connection_pool.rb
recurly-3.26.0 lib/recurly/connection_pool.rb
recurly-3.25.0 lib/recurly/connection_pool.rb
recurly-3.24.0 lib/recurly/connection_pool.rb
recurly-3.23.0 lib/recurly/connection_pool.rb
recurly-3.22.0 lib/recurly/connection_pool.rb
recurly-3.21.0 lib/recurly/connection_pool.rb
recurly-3.20.0 lib/recurly/connection_pool.rb
recurly-3.19.0 lib/recurly/connection_pool.rb
recurly-4.9.0 lib/recurly/connection_pool.rb
recurly-4.8.0 lib/recurly/connection_pool.rb
recurly-4.7.0 lib/recurly/connection_pool.rb
recurly-4.6.0 lib/recurly/connection_pool.rb
recurly-4.5.0 lib/recurly/connection_pool.rb
recurly-4.4.0 lib/recurly/connection_pool.rb
recurly-4.3.0 lib/recurly/connection_pool.rb
recurly-4.2.0 lib/recurly/connection_pool.rb
recurly-4.1.0 lib/recurly/connection_pool.rb
recurly-4.0.1 lib/recurly/connection_pool.rb