Matt Solnit wrote:
Hi everyone. Using HttpClient 4.0.1, is it possible to set a maximum overall lifetime
for pooled (persistent) connections? I looked at implementing
ConnectionKeepAliveStrategy, but I believe this is invoked for every request, so there is
no way to "remember" when a connection was initially opened.
Currently I'm looking at creating a new sub-class of
ThreadSafeClientConnManager, which in turn uses a new sub-class of
DefaultClientConnectionOperator, which returns a connection wrapper that
remembers when it's opened. This could in turn be used by a
ConnectionKeepAliveStrategy which knows to look for the special wrapped
connection type and check how long it's been open.
It looks like the work for HTTPCLIENT-915
(https://issues.apache.org/jira/browse/HTTPCLIENT-915) might help with this
approach, eliminating the need for a special wrapper class.
All that being said, is there a recommended strategy? Any feedback would be
appreciated.
Hi Matt
Currently idle time counter gets reset after each lease/release of a
persistent connection, and there is not way to change this behavior
without writing a new connection manager. The good news is that the idle
connection handling logic is encapsulated in one class, which could be
replaced with a pluggable strategy.
http://hc.apache.org/httpcomponents-client/httpclient/xref/org/apache/http/impl/conn/IdleConnectionHandler.html
Another possibility may be to make connection creation time available
through the HttpConnectionMetrics interface:
http://hc.apache.org/httpcomponents-core/httpcore/apidocs/org/apache/http/HttpConnection.html#getMetrics%28%29
Hope this helps
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]