lib/persistent_http.rb in persistent_http-1.0.2 vs lib/persistent_http.rb in persistent_http-1.0.3

- old
+ new

@@ -81,10 +81,14 @@ ## # HTTP version to enable version specific features. attr_reader :http_version ## + # Connection will be renewed if it hasn't been used in this amount of time. Defaults to 10 seconds. + attr_reader :idle_timeout + + ## # The value sent in the Keep-Alive header. Defaults to 30. Not needed for # HTTP/1.1 servers. # # This may not work correctly for HTTP/1.0 servers # @@ -141,11 +145,11 @@ attr_accessor :verify_mode ## # The threshold in seconds for checking out a connection at which a warning # will be logged via the logger - attr_accessor :warn_timeout + attr_reader :warn_timeout ## # Creates a new PersistentHTTP. # # Set +name+ to keep your connections apart from everybody else's. Not @@ -169,10 +173,11 @@ @debug_output = options[:debug_output] @default_path = options[:default_path] @force_retry = options[:force_retry] @headers = options[:header] || {} @host = options[:host] + @idle_timeout = options[:idle_timeout] || 10 @keep_alive = options[:keep_alive] || 30 @logger = options[:logger] @open_timeout = options[:open_timeout] @pool_size = options[:pool_size] || 1 @port = options[:port] @@ -225,10 +230,12 @@ end @pool = GenePool.new(:name => name + '-' + connection_id, :pool_size => @pool_size, :warn_timeout => @warn_timeout, + :idle_timeout => @idle_timeout, + :close_proc => nil, :logger => @logger) do begin connection = Net::HTTP.new(*net_http_args) connection.set_debug_output @debug_output if @debug_output connection.open_timeout = @open_timeout if @open_timeout @@ -244,10 +251,20 @@ raise Error, "host down: #{connection.address}:#{connection.port}" end end end + # Reset the size of the connection pool + def pool_size=(pool_size) + @gene_pool.pool_size = pool_size + end + + # Return the size of the connection pool + def pool_size + @gene_pool.pool_size + end + ## # Makes a request per +req+. If +req+ is nil a Net::HTTP::Get is performed # against +default_path+. # # If a block is passed #request behaves like Net::HTTP#request (the body of @@ -318,14 +335,11 @@ end end ## # Shuts down all connections. - - def shutdown - raise 'Shutdown not implemented' - # TBD - need to think about this one - @count_hash = nil + def shutdown(timeout=10) + @gene_pool.close(timeout) end ####### private #######