Sha256: 4156b0a2f39d55b3cbbc2ffcfb7e06481c5764a9e0fc008705fef0c0904f313d

Contents?: true

Size: 994 Bytes

Versions: 6

Compression:

Stored size: 994 Bytes

Contents

class Net::HTTP::Persistent::Pool < ConnectionPool # :nodoc:

  attr_reader :available # :nodoc:
  attr_reader :key # :nodoc:

  def initialize(options = {}, &block)
    super

    @available = Net::HTTP::Persistent::TimedStackMulti.new(@size, &block)
    @key = "current-#{@available.object_id}"
  end

  def checkin net_http_args
    stack = Thread.current[@key][net_http_args] ||= []

    raise ConnectionPool::Error, 'no connections are checked out' if
      stack.empty?

    conn = stack.pop

    if stack.empty?
      @available.push conn, connection_args: net_http_args
    end

    nil
  end

  def checkout net_http_args
    stacks = Thread.current[@key] ||= {}
    stack  = stacks[net_http_args] ||= []

    if stack.empty? then
      conn = @available.pop connection_args: net_http_args
    else
      conn = stack.last
    end

    stack.push conn

    conn
  end

  def shutdown
    Thread.current[@key] = nil
    super
  end
end

require 'net/http/persistent/timed_stack_multi'

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/net-http-persistent-3.0.1/lib/net/http/persistent/pool.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/net-http-persistent-3.0.1/lib/net/http/persistent/pool.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/net-http-persistent-3.0.1/lib/net/http/persistent/pool.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/net-http-persistent-3.0.1/lib/net/http/persistent/pool.rb
net-http-persistent-retry-3.0.1 lib/net/http/persistent/pool.rb
net-http-persistent-3.0.1 lib/net/http/persistent/pool.rb