Sha256: ce2ae58c0b3aa8b242722173b186dd6503eebca3a5116c0c54f7ba67c1a3e90a

Contents?: true

Size: 1.6 KB

Versions: 275

Compression:

Stored size: 1.6 KB

Contents

class Bundler::Persistent::Net::HTTP::Persistent::TimedStackMulti < Bundler::ConnectionPool::TimedStack # :nodoc:

  ##
  # Returns a new hash that has arrays for keys
  #
  # Using a class method to limit the bindings referenced by the hash's
  # default_proc

  def self.hash_of_arrays # :nodoc:
    Hash.new { |h,k| h[k] = [] }
  end

  def initialize(size = 0, &block)
    super

    @enqueued = 0
    @ques = self.class.hash_of_arrays
    @lru = {}
    @key = :"connection_args-#{object_id}"
  end

  def empty?
    (@created - @enqueued) >= @max
  end

  def length
    @max - @created + @enqueued
  end

  private

  def connection_stored? options = {} # :nodoc:
    !@ques[options[:connection_args]].empty?
  end

  def fetch_connection options = {} # :nodoc:
    connection_args = options[:connection_args]

    @enqueued -= 1
    lru_update connection_args
    @ques[connection_args].pop
  end

  def lru_update connection_args # :nodoc:
    @lru.delete connection_args
    @lru[connection_args] = true
  end

  def shutdown_connections # :nodoc:
    @ques.each_key do |key|
      super connection_args: key
    end
  end

  def store_connection obj, options = {} # :nodoc:
    @ques[options[:connection_args]].push obj
    @enqueued += 1
  end

  def try_create options = {} # :nodoc:
    connection_args = options[:connection_args]

    if @created >= @max && @enqueued >= 1
      oldest, = @lru.first
      @lru.delete oldest
      @ques[oldest].pop

      @created -= 1
    end

    if @created < @max
      @created += 1
      lru_update connection_args
      return @create_block.call(connection_args)
    end
  end

end

Version data entries

275 entries across 275 versions & 6 rubygems

Version Path
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb