Improved DEBUG log statements; reduced noise in the context logging

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@691587 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2008-09-03 12:22:55 +00:00
parent fb7a529419
commit 0cfdbb16a0
5 changed files with 28 additions and 16 deletions

View File

@ -215,7 +215,7 @@ public Object getParameter(String name) {
if ((result == null) && (applicationParams != null)) { if ((result == null) && (applicationParams != null)) {
result = applicationParams.getParameter(name); result = applicationParams.getParameter(name);
} }
if (this.log.isDebugEnabled()) { if (this.log.isDebugEnabled() && result != null) {
this.log.debug("'" + name + "': " + result); this.log.debug("'" + name + "': " + result);
} }

View File

@ -330,10 +330,12 @@ public HttpResponse execute(HttpHost target, HttpRequest request,
if (HttpConnectionParams.isStaleCheckingEnabled(params)) { if (HttpConnectionParams.isStaleCheckingEnabled(params)) {
// validate connection // validate connection
this.log.debug("Stale connection check"); if (managedConn.isOpen()) {
if (managedConn.isStale()) { this.log.debug("Stale connection check");
this.log.debug("Stale connection detected"); if (managedConn.isStale()) {
managedConn.close(); this.log.debug("Stale connection detected");
managedConn.close();
}
} }
} }
} }
@ -446,10 +448,14 @@ public HttpResponse execute(HttpHost target, HttpRequest request,
// The connection is in or can be brought to a re-usable state. // The connection is in or can be brought to a re-usable state.
reuse = reuseStrategy.keepAlive(response, context); reuse = reuseStrategy.keepAlive(response, context);
if(reuse) { if (reuse) {
// Set the idle duration of this connection // Set the idle duration of this connection
long duration = keepAliveStrategy.getKeepAliveDuration(response, context); long duration = keepAliveStrategy.getKeepAliveDuration(response, context);
managedConn.setIdleDuration(duration, TimeUnit.MILLISECONDS); managedConn.setIdleDuration(duration, TimeUnit.MILLISECONDS);
if (this.log.isDebugEnabled()) {
this.log.debug("Connection can be kept alive for " + duration + " ms");
}
} }
RoutedRequest followup = handleResponse(roureq, response, context); RoutedRequest followup = handleResponse(roureq, response, context);
@ -457,7 +463,6 @@ public HttpResponse execute(HttpHost target, HttpRequest request,
done = true; done = true;
} else { } else {
if (reuse) { if (reuse) {
this.log.debug("Connection kept alive");
// Make sure the response body is fully consumed, if present // Make sure the response body is fully consumed, if present
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
if (entity != null) { if (entity != null) {

View File

@ -110,11 +110,10 @@ public void setMethod(final String method) {
} }
public ProtocolVersion getProtocolVersion() { public ProtocolVersion getProtocolVersion() {
if (this.version != null) { if (this.version == null) {
return this.version; this.version = HttpProtocolParams.getVersion(getParams());
} else {
return HttpProtocolParams.getVersion(getParams());
} }
return this.version;
} }
public void setProtocolVersion(final ProtocolVersion version) { public void setProtocolVersion(final ProtocolVersion version) {

View File

@ -371,7 +371,7 @@ public void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration
HttpRoute route = entry.getPlannedRoute(); HttpRoute route = entry.getPlannedRoute();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Freeing connection" + log.debug("Releasing connection" +
" [" + route + "][" + entry.getState() + "]"); " [" + route + "][" + entry.getState() + "]");
} }
@ -390,6 +390,11 @@ public void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration
RouteSpecificPool rospl = getRoutePool(route, true); RouteSpecificPool rospl = getRoutePool(route, true);
if (reusable) { if (reusable) {
if (log.isDebugEnabled()) {
log.debug("Pooling connection" +
" [" + route + "][" + entry.getState() + "]" +
"; keep alive for " + validDuration + " " + timeUnit.toString());
}
rospl.freeEntry(entry); rospl.freeEntry(entry);
freeConnections.add(entry); freeConnections.add(entry);
idleConnHandler.add(entry.getConnection(), validDuration, timeUnit); idleConnHandler.add(entry.getConnection(), validDuration, timeUnit);

View File

@ -198,10 +198,6 @@ public void releaseConnection(ManagedClientConnection conn, long validDuration,
try { try {
// make sure that the response has been read completely // make sure that the response has been read completely
if (hca.isOpen() && !hca.isMarkedReusable()) { if (hca.isOpen() && !hca.isMarkedReusable()) {
if (log.isDebugEnabled()) {
log.debug
("Released connection open but not marked reusable.");
}
// In MTHCM, there would be a call to // In MTHCM, there would be a call to
// SimpleHttpConnectionManager.finishLastResponse(conn); // SimpleHttpConnectionManager.finishLastResponse(conn);
// Consuming the response is handled outside in 4.0. // Consuming the response is handled outside in 4.0.
@ -220,6 +216,13 @@ public void releaseConnection(ManagedClientConnection conn, long validDuration,
} finally { } finally {
BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry(); BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
boolean reusable = hca.isMarkedReusable(); boolean reusable = hca.isMarkedReusable();
if (log.isDebugEnabled()) {
if (reusable) {
log.debug("Released connection is reusable.");
} else {
log.debug("Released connection is not reusable.");
}
}
hca.detach(); hca.detach();
if (entry != null) { if (entry != null) {
connectionPool.freeEntry(entry, reusable, validDuration, timeUnit); connectionPool.freeEntry(entry, reusable, validDuration, timeUnit);