Class: Seahorse::Client::NetHttp::ConnectionPool Private
- Inherits:
-
Object
- Object
- Seahorse::Client::NetHttp::ConnectionPool
- Defined in:
- lib/seahorse/client/net_http/connection_pool.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: ExtendedSession
Constant Summary collapse
- OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ http_proxy: nil, http_open_timeout: 15, http_read_timeout: 60, http_idle_timeout: 5, http_continue_timeout: 1, http_wire_trace: false, logger: nil, ssl_verify_peer: true, ssl_ca_bundle: nil, ssl_ca_directory: nil, ssl_ca_store: nil, }
Instance Attribute Summary collapse
-
#http_continue_timeout ⇒ Float?
readonly
The current value of http_continue_timeout.
-
#http_idle_timeout ⇒ Integer, Float
readonly
The current value of http_idle_timeout.
-
#http_open_timeout ⇒ Integer, Float
readonly
The current value of http_open_timeout.
-
#http_proxy ⇒ URI::HTTP?
readonly
Returns the configured proxy.
-
#http_read_timeout ⇒ Integer, Float
readonly
The current value of http_read_timeout.
-
#http_wire_trace ⇒ Boolean
(also: #http_wire_trace?)
readonly
The current value of http_wire_trace.
-
#logger ⇒ Logger?
readonly
The current value of logger.
-
#ssl_ca_bundle ⇒ String?
readonly
The current value of ssl_ca_bundle.
-
#ssl_ca_directory ⇒ String?
readonly
The current value of ssl_ca_directory.
-
#ssl_ca_store ⇒ String?
readonly
The current value of ssl_ca_store.
-
#ssl_verify_peer ⇒ Boolean
(also: #ssl_verify_peer?)
readonly
The current value of ssl_verify_peer.
Class Method Summary collapse
-
.for(options = {}) ⇒ ConnectionPool
private
Returns a connection pool constructed from the given options.
-
.pools ⇒ Array<ConnectionPool>
private
Returns a list of of the constructed connection pools.
Instance Method Summary collapse
-
#clean! ⇒ nil
private
Removes stale http sessions from the pool (that have exceeded the idle timeout).
-
#empty! ⇒ nil
private
Closes and removes removes all sessions from the pool.
-
#initialize(options = {}) ⇒ ConnectionPool
constructor
private
A new instance of ConnectionPool.
-
#request(endpoint, request) {|net_http_response| ... } ⇒ nil
private
Makes an HTTP request, yielding a Net::HTTPResponse object.
- #session_for(endpoint) {|session| ... } ⇒ nil private
-
#size ⇒ Integer
private
Returns the count of sessions currently in the pool, not counting those currently in use.
Constructor Details
#initialize(options = {}) ⇒ ConnectionPool
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ConnectionPool.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 44 def initialize( = {}) OPTIONS.each_pair do |opt_name, default_value| value = [opt_name].nil? ? default_value : [opt_name] instance_variable_set("@#{opt_name}", value) end @pool_mutex = Mutex.new @pool = Hash.new do |pool, endpoint| pool[endpoint] = [] pool[endpoint] end end |
Instance Attribute Details
#http_continue_timeout ⇒ Float? (readonly)
Returns the current value of http_continue_timeout.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def http_continue_timeout @http_continue_timeout end |
#http_idle_timeout ⇒ Integer, Float (readonly)
Returns the current value of http_idle_timeout.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def http_idle_timeout @http_idle_timeout end |
#http_open_timeout ⇒ Integer, Float (readonly)
Returns the current value of http_open_timeout.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def http_open_timeout @http_open_timeout end |
#http_proxy ⇒ URI::HTTP? (readonly)
Returns the configured proxy.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def http_proxy @http_proxy end |
#http_read_timeout ⇒ Integer, Float (readonly)
Returns the current value of http_read_timeout.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def http_read_timeout @http_read_timeout end |
#http_wire_trace ⇒ Boolean (readonly) Also known as: http_wire_trace?
Returns the current value of http_wire_trace.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def http_wire_trace @http_wire_trace end |
#logger ⇒ Logger? (readonly)
Returns the current value of logger.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def logger @logger end |
#ssl_ca_bundle ⇒ String? (readonly)
Returns the current value of ssl_ca_bundle.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def ssl_ca_bundle @ssl_ca_bundle end |
#ssl_ca_directory ⇒ String? (readonly)
Returns the current value of ssl_ca_directory.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def ssl_ca_directory @ssl_ca_directory end |
#ssl_ca_store ⇒ String? (readonly)
Returns the current value of ssl_ca_store.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def ssl_ca_store @ssl_ca_store end |
#ssl_verify_peer ⇒ Boolean (readonly) Also known as: ssl_verify_peer?
Returns the current value of ssl_verify_peer.
24 25 26 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 24 def ssl_verify_peer @ssl_verify_peer end |
Class Method Details
.for(options = {}) ⇒ ConnectionPool
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a connection pool constructed from the given options. Calling this method twice with the same options will return the same pool.
218 219 220 221 222 223 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 218 def for = {} = () @pools_mutex.synchronize do @pools[] ||= new() end end |
.pools ⇒ Array<ConnectionPool>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a list of of the constructed connection pools.
227 228 229 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 227 def pools @pools.values end |
Instance Method Details
#clean! ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes stale http sessions from the pool (that have exceeded the idle timeout).
134 135 136 137 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 134 def clean! @pool_mutex.synchronize { _clean } nil end |
#empty! ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Closes and removes removes all sessions from the pool. If empty! is called while there are outstanding requests they may get checked back into the pool, leaving the pool in a non-empty state.
144 145 146 147 148 149 150 151 152 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 144 def empty! @pool_mutex.synchronize do @pool.each_pair do |endpoint,sessions| sessions.each(&:finish) end @pool.clear end nil end |
#request(endpoint, request) {|net_http_response| ... } ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Makes an HTTP request, yielding a Net::HTTPResponse object.
pool.request('http://domain', Net::HTTP::Get.new('/')) do |resp|
puts resp.code # status code
puts resp.to_h.inspect # dump the headers
puts resp.body
end
81 82 83 84 85 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 81 def request(endpoint, request, &block) session_for(endpoint) do |http| yield(http.request(request)) end end |
#session_for(endpoint) {|session| ... } ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 93 def session_for(endpoint, &block) endpoint = remove_path_and_query(endpoint) session = nil # attempt to recycle an already open session @pool_mutex.synchronize do _clean session = @pool[endpoint].shift end begin session ||= start_session(endpoint) session.read_timeout = http_read_timeout session.continue_timeout = http_continue_timeout if session.respond_to?(:continue_timeout=) yield(session) rescue session.finish if session raise else # No error raised? Good, check the session into the pool. @pool_mutex.synchronize { @pool[endpoint] << session } end nil end |
#size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the count of sessions currently in the pool, not counting those currently in use.
121 122 123 124 125 126 127 128 129 |
# File 'lib/seahorse/client/net_http/connection_pool.rb', line 121 def size @pool_mutex.synchronize do size = 0 @pool.each_pair do |endpoint,sessions| size += sessions.size end size end end |