simplified idle duration to start counting when connection is released
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@672969 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea0e787fde
commit
bf6371eae6
|
@ -36,7 +36,7 @@ import org.apache.http.HttpEntity;
|
|||
import org.apache.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* Handler that incapsulates the process of generating a response object
|
||||
* Handler that encapsulates the process of generating a response object
|
||||
* from a {@link HttpResponse}.
|
||||
*
|
||||
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
|
||||
|
|
|
@ -249,9 +249,12 @@ public interface ManagedClientConnection extends
|
|||
;
|
||||
|
||||
/**
|
||||
* Sets the duration that this connection can remain idle
|
||||
* before it is reused.
|
||||
* The connection should not be used again if this time elapses.
|
||||
* Sets the duration that this connection can remain idle before it is
|
||||
* reused. The connection should not be used again if this time elapses. The
|
||||
* idle duration must be reset after each request sent over this connection.
|
||||
* The elapsed time starts counting when the connection is released, which
|
||||
* is typically after the headers (and any response body, if present) is
|
||||
* fully consumed.
|
||||
*/
|
||||
void setIdleDuration(long duration, TimeUnit unit);
|
||||
|
||||
|
|
|
@ -99,9 +99,6 @@ public abstract class AbstractClientConnAdapter
|
|||
/** True if the connection has been aborted. */
|
||||
private volatile boolean aborted;
|
||||
|
||||
/** The last time this processed incoming headers. */
|
||||
private volatile long lastHeadersRead;
|
||||
|
||||
/** The duration this is valid for while idle (in ms). */
|
||||
private volatile long duration;
|
||||
|
||||
|
@ -259,8 +256,6 @@ public abstract class AbstractClientConnAdapter
|
|||
assertValid(conn);
|
||||
|
||||
unmarkReusable();
|
||||
duration = Long.MAX_VALUE; // Reset duration per request.
|
||||
lastHeadersRead = System.currentTimeMillis();
|
||||
return conn.receiveResponseHeader();
|
||||
}
|
||||
|
||||
|
@ -361,39 +356,14 @@ public abstract class AbstractClientConnAdapter
|
|||
if(duration > 0) {
|
||||
this.duration = unit.toMillis(duration);
|
||||
} else {
|
||||
this.duration = Long.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of time remaining that this connection
|
||||
* can be reused. If negative, the connection should not
|
||||
* be reused. If Long.MAX_VALUE, there is no suggested
|
||||
* duration.
|
||||
*
|
||||
* The remaining time is the elapsed time between now,
|
||||
* the time the last headers were processed, and the duration
|
||||
* given from {@link #setIdleDuration(long, TimeUnit)}.
|
||||
*/
|
||||
protected long getRemainingIdleDuration() {
|
||||
if(duration == Long.MAX_VALUE) {
|
||||
return Long.MAX_VALUE;
|
||||
} else {
|
||||
long elapsedAlready = System.currentTimeMillis() - lastHeadersRead;
|
||||
return duration - elapsedAlready;
|
||||
this.duration = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// non-javadoc, see interface ConnectionReleaseTrigger
|
||||
public void releaseConnection() {
|
||||
if (connManager != null) {
|
||||
long remainingTime = getRemainingIdleDuration();
|
||||
if(remainingTime <= 0) {
|
||||
unmarkReusable();
|
||||
} else if(remainingTime == Long.MAX_VALUE) {
|
||||
remainingTime = -1;
|
||||
}
|
||||
connManager.releaseConnection(this, remainingTime, TimeUnit.MILLISECONDS);
|
||||
connManager.releaseConnection(this, duration, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue