Home » Ruby-master » bundler » Index (T) » Gem » Net » HTTP » Persistent » TimedStackMulti ▲
123456789_123456789_123456789_123456789_123456789_

Class: Gem::Net::HTTP::Persistent::TimedStackMulti

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::TimedStack
Defined in: lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb

Class Method Summary

::Bundler::ConnectionPool::TimedStack - Inherited

.new

Creates a new pool with size connections that are created from the given block.

Instance Attribute Summary

::Bundler::ConnectionPool::TimedStack - Inherited

#empty?

Returns true if there are no available connections.

#max

Instance Method Summary

::Bundler::ConnectionPool::TimedStack - Inherited

#<<
#length

The number of connections available on the stack.

#pop

Retrieves a connection from the stack.

#push

Returns obj to the stack.

#shutdown

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

#connection_stored?

This is an extension point for TimedStack and is called with a mutex.

#current_time,
#fetch_connection

This is an extension point for TimedStack and is called with a mutex.

#shutdown_connections

This is an extension point for TimedStack and is called with a mutex.

#store_connection

This is an extension point for TimedStack and is called with a mutex.

#try_create

This is an extension point for TimedStack and is called with a mutex.

Constructor Details

.new(size = 0, &block) ⇒ TimedStackMulti

[ GitHub ]

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

def initialize(size = 0, &block)
  super

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

Class Method Details

.hash_of_arrays

Returns a new hash that has arrays for keys

Using a class method to limit the bindings referenced by the hash’s default_proc

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb', line 9

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

Instance Attribute Details

#empty?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb', line 22

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

Instance Method Details

#connection_stored?(options = {}) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb', line 32

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

#fetch_connection(options = {}) (private)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb', line 36

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

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

#length

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb', line 26

def length
  @max - @created + @enqueued
end

#lru_update(connection_args) (private)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb', line 44

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

#shutdown_connections (private)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb', line 49

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

#store_connection(obj, options = {}) (private)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb', line 55

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

#try_create(options = {}) (private)

[ GitHub ]

  
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb', line 60

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