Home » Ruby-3.3.6 » bundler » Index (P) » Gem » Net » HTTP » Persistent » Pool ▲
123456789_123456789_123456789_123456789_123456789_

Class: Gem::Net::HTTP::Persistent::Pool

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Bundler::ConnectionPool
Defined in: lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb

Constant Summary

::Bundler::ConnectionPool - Inherited

DEFAULTS, INSTANCES, VERSION

Class Method Summary

::Bundler::ConnectionPool - Inherited

.after_fork

See additional method definition at line 52.

.new, .wrap

Instance Attribute Summary

::Bundler::ConnectionPool - Inherited

#auto_reload_after_fork

Automatically drop all connections after fork.

#size

Size of this connection pool.

Instance Method Summary

::Bundler::ConnectionPool - Inherited

#available

Number of pool entries available for checkout at this instant.

#checkin, #checkout,
#reload

Reloads the ::Bundler::ConnectionPool by passing each connection to block and then removing it the pool.

#shutdown

Shuts down the ::Bundler::ConnectionPool by passing each connection to block and then removing it from the pool.

#then
#with

::Bundler::ConnectionPool::ForkTracker - Included

Constructor Details

.new(options = {}, &block) ⇒ Pool

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb', line 6

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

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

Instance Attribute Details

#available (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb', line 3

attr_reader :available # :nodoc:

#key (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb', line 4

attr_reader :key # :nodoc:

Instance Method Details

#checkin(net_http_args)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb', line 13

def checkin net_http_args
  if net_http_args.is_a?(Hash) && net_http_args.size == 1 && net_http_args[:force]
    # Bundler::ConnectionPool 2.4+ calls `checkin(force: true)` after fork.
    # When this happens, we should remove all connections from Thread.current
    if stacks = Thread.current[@key]
      stacks.each do |http_args, connections|
        connections.each do |conn|
          @available.push conn, connection_args: http_args
        end
        connections.clear
      end
    end
  else
    stack = Thread.current[@key][net_http_args] ||= []

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

    conn = stack.pop

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

      Thread.current[@key].delete(net_http_args)
      Thread.current[@key] = nil if Thread.current[@key].empty?
    end
  end
  nil
end

#checkout(net_http_args)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb', line 43

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

#shutdown

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb', line 58

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