HTTPCLIENT-725: time unit when closing idle connections
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@607432 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d1a4c2ce6d
commit
1d3425c2db
|
@ -1,7 +1,10 @@
|
|||
Changes since 4.0 Alpha 2
|
||||
-------------------
|
||||
|
||||
* [HTTPCLIENT-677] Connection manager no longer uses Thread.interrupt()
|
||||
* [HTTPCLIENT-725] Use TimeUnit arguments for timeouts in connection manager.
|
||||
Contributed by Roland Weber <rolandw at apache.org>
|
||||
|
||||
* [HTTPCLIENT-677] Connection manager no longer uses Thread.interrupt().
|
||||
Contributed by Roland Weber <rolandw at apache.org>
|
||||
|
||||
* [HTTPCLIENT-716] Allow application-defined routes.
|
||||
|
@ -16,11 +19,11 @@ Changes since 4.0 Alpha 2
|
|||
* [HTTPCLIENT-715] Remove RoutedRequest from API
|
||||
Contributed by Roland Weber <rolandw at apache.org>
|
||||
|
||||
* [HTTPCLIENT-705] Fixed incorrect handling of URIs with null path component
|
||||
* [HTTPCLIENT-705] Fixed incorrect handling of URIs with null path component.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
* [HTTPCLIENT-688] HttpOptions#getAllowedMethods can now handle multiple
|
||||
Allow headers
|
||||
Allow headers.
|
||||
Contributed by Andrea Selva <selva.andre at gmail.com>
|
||||
|
||||
|
||||
|
|
|
@ -131,12 +131,14 @@ public interface ClientConnectionManager {
|
|||
/**
|
||||
* Closes idle connections in the pool.
|
||||
* Open connections in the pool that have not been used for the
|
||||
* timespan given by the timeout argument will be closed.
|
||||
* timespan given by the argument will be closed.
|
||||
* Currently allocated connections are not subject to this method.
|
||||
* Times will be checked with milliseconds precision
|
||||
*
|
||||
* @param idletime the idle time in milliseconds
|
||||
* @param idletime the idle time of connections to be closed
|
||||
* @param tunit the unit for the <code>idletime</code>
|
||||
*/
|
||||
void closeIdleConnections(long idletime)
|
||||
void closeIdleConnections(long idletime, TimeUnit tunit)
|
||||
;
|
||||
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ public class IdleConnectionHandler {
|
|||
*
|
||||
* @param idleTime the minimum idle time, in milliseconds, for connections to be closed
|
||||
*/
|
||||
//@@@ add TimeUnit argument here?
|
||||
public void closeIdleConnections(long idleTime) {
|
||||
|
||||
// the latest time for which connections will be closed
|
||||
|
|
|
@ -289,11 +289,17 @@ public class SingleClientConnManager implements ClientConnectionManager {
|
|||
|
||||
|
||||
// non-javadoc, see interface ClientConnectionManager
|
||||
public void closeIdleConnections(long idletime) {
|
||||
public void closeIdleConnections(long idletime, TimeUnit tunit) {
|
||||
assertStillUp();
|
||||
|
||||
// idletime can be 0 or negative, no problem there
|
||||
if (tunit == null) {
|
||||
throw new IllegalArgumentException("Time unit must not be null.");
|
||||
}
|
||||
|
||||
if ((managedConn == null) && uniquePoolEntry.connection.isOpen()) {
|
||||
final long cutoff = System.currentTimeMillis() - idletime;
|
||||
final long cutoff =
|
||||
System.currentTimeMillis() - tunit.toMillis(idletime);
|
||||
if (lastReleaseTime <= cutoff) {
|
||||
try {
|
||||
uniquePoolEntry.close();
|
||||
|
|
|
@ -249,12 +249,18 @@ public abstract class AbstractConnPool implements RefQueueHandler {
|
|||
*
|
||||
* @param idletime the time the connections should have been idle
|
||||
* in order to be closed now
|
||||
* @param tunit the unit for the <code>idletime</code>
|
||||
*/
|
||||
public void closeIdleConnections(long idletime) {
|
||||
public void closeIdleConnections(long idletime, TimeUnit tunit) {
|
||||
|
||||
// idletime can be 0 or negative, no problem there
|
||||
if (tunit == null) {
|
||||
throw new IllegalArgumentException("Time unit must not be null.");
|
||||
}
|
||||
|
||||
try {
|
||||
poolLock.lock();
|
||||
idleConnHandler.closeIdleConnections(idletime);
|
||||
idleConnHandler.closeIdleConnections(tunit.toMillis(idletime));
|
||||
} finally {
|
||||
poolLock.unlock();
|
||||
}
|
||||
|
|
|
@ -264,9 +264,9 @@ public class ThreadSafeClientConnManager
|
|||
|
||||
|
||||
// non-javadoc, see interface ClientConnectionManager
|
||||
public void closeIdleConnections(long idleTimeout) {
|
||||
public void closeIdleConnections(long idleTimeout, TimeUnit tunit) {
|
||||
// combine these two in a single call?
|
||||
connectionPool.closeIdleConnections(idleTimeout);
|
||||
connectionPool.closeIdleConnections(idleTimeout, tunit);
|
||||
connectionPool.deleteClosedConnections();
|
||||
}
|
||||
|
||||
|
|
|
@ -393,7 +393,8 @@ public class TestTSCCMNoServer extends TestCase {
|
|||
assertEquals("connectionsInPool(host)",
|
||||
mgr.getConnectionsInPool(route), 1);
|
||||
|
||||
mgr.closeIdleConnections(0L); // implicitly deletes them, too
|
||||
// this implicitly deletes them
|
||||
mgr.closeIdleConnections(0L, TimeUnit.MILLISECONDS);
|
||||
|
||||
assertEquals("connectionsInPool",
|
||||
mgr.getConnectionsInPool(), 0);
|
||||
|
|
Loading…
Reference in New Issue