Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E0F3D9CB8 for ; Thu, 26 Apr 2012 10:23:08 +0000 (UTC) Received: (qmail 53984 invoked by uid 500); 26 Apr 2012 10:23:08 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 53952 invoked by uid 500); 26 Apr 2012 10:23:08 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 53943 invoked by uid 99); 26 Apr 2012 10:23:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Apr 2012 10:23:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Apr 2012 10:23:04 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id EE7FA2388B46 for ; Thu, 26 Apr 2012 10:22:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1330755 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio: client/DefaultAsyncRequestDirector.java conn/HttpNIOConnPool.java Date: Thu, 26 Apr 2012 10:22:42 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120426102242.EE7FA2388B46@eris.apache.org> Author: olegk Date: Thu Apr 26 10:22:42 2012 New Revision: 1330755 URL: http://svn.apache.org/viewvc?rev=1330755&view=rev Log: Include exchange ID in the DefaultAsyncRequestDirector logs Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/HttpNIOConnPool.java Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java?rev=1330755&r1=1330754&r2=1330755&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java Thu Apr 26 10:22:42 2012 @@ -31,6 +31,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; import org.apache.commons.logging.Log; import org.apache.http.ConnectionClosedException; @@ -90,6 +91,8 @@ import org.apache.http.protocol.HttpProc class DefaultAsyncRequestDirector implements HttpAsyncRequestExecutionHandler { + private static final AtomicLong COUNTER = new AtomicLong(1); + private final Log log; private final HttpAsyncRequestProducer requestProducer; @@ -110,6 +113,7 @@ class DefaultAsyncRequestDirector imp private final AuthState proxyAuthState; private final HttpAuthenticator authenticator; private final HttpParams clientParams; + private final long id; private volatile boolean closed; private volatile ManagedClientAsyncConnection managedConn; @@ -164,6 +168,7 @@ class DefaultAsyncRequestDirector imp this.proxyAuthState = new AuthState(); this.authenticator = new HttpAuthenticator(log); this.clientParams = clientParams; + this.id = COUNTER.getAndIncrement(); } public void close() { @@ -193,7 +198,9 @@ class DefaultAsyncRequestDirector imp public synchronized void start() { try { - + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] start execution"); + } this.localContext.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetAuthState); this.localContext.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState); @@ -227,7 +234,9 @@ class DefaultAsyncRequestDirector imp case HttpRouteDirector.CONNECT_PROXY: break; case HttpRouteDirector.TUNNEL_TARGET: - this.log.debug("Tunnel required"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Tunnel required"); + } HttpRequest connect = createConnectRequest(route); this.currentRequest = wrapRequest(connect); this.currentRequest.setParams(this.params); @@ -283,13 +292,16 @@ class DefaultAsyncRequestDirector imp } this.execCount++; if (this.log.isDebugEnabled()) { - this.log.debug("Attempt " + this.execCount + " to execute request"); + this.log.debug("[exchange: " + this.id + "] Attempt " + this.execCount + " to execute request"); } return this.currentRequest; } public synchronized void produceContent( final ContentEncoder encoder, final IOControl ioctrl) throws IOException { + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] produce content"); + } this.requestContentProduced = true; this.requestProducer.produceContent(encoder, ioctrl); if (encoder.isCompleted()) { @@ -298,6 +310,9 @@ class DefaultAsyncRequestDirector imp } public void requestCompleted(final HttpContext context) { + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] request completed"); + } this.requestSent = true; this.requestProducer.requestCompleted(context); } @@ -314,7 +329,7 @@ class DefaultAsyncRequestDirector imp public synchronized void responseReceived( final HttpResponse response) throws IOException, HttpException { if (this.log.isDebugEnabled()) { - this.log.debug("Response: " + response.getStatusLine()); + this.log.debug("[exchange: " + this.id + "] Response received " + response.getStatusLine()); } this.currentResponse = response; this.currentResponse.setParams(this.params); @@ -355,6 +370,9 @@ class DefaultAsyncRequestDirector imp public synchronized void consumeContent( final ContentDecoder decoder, final IOControl ioctrl) throws IOException { + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Consume content"); + } if (this.finalResponse != null) { this.responseConsumer.consumeContent(decoder, ioctrl); } else { @@ -394,7 +412,9 @@ class DefaultAsyncRequestDirector imp } public synchronized void responseCompleted(final HttpContext context) { - this.log.debug("Response fully read"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Response fully read"); + } try { if (this.resultCallback.isDone()) { return; @@ -409,29 +429,37 @@ class DefaultAsyncRequestDirector imp } else { s = "indefinitely"; } - this.log.debug("Connection can be kept alive " + s); + this.log.debug("[exchange: " + this.id + "] Connection can be kept alive " + s); } this.managedConn.setIdleDuration(duration, TimeUnit.MILLISECONDS); } else { - this.log.debug("Connection cannot be kept alive"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Connection cannot be kept alive"); + } this.managedConn.unmarkReusable(); if (this.proxyAuthState.getState() == AuthProtocolState.SUCCESS && this.proxyAuthState.getAuthScheme() != null && this.proxyAuthState.getAuthScheme().isConnectionBased()) { - this.log.debug("Resetting proxy auth state"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Resetting proxy auth state"); + } this.proxyAuthState.reset(); } if (this.targetAuthState.getState() == AuthProtocolState.SUCCESS && this.targetAuthState.getAuthScheme() != null && this.targetAuthState.getAuthScheme().isConnectionBased()) { - this.log.debug("Resetting target auth state"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Resetting target auth state"); + } this.targetAuthState.reset(); } } if (this.finalResponse != null) { this.responseConsumer.responseCompleted(this.localContext); - this.log.debug("Response processed"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Response processed"); + } releaseConnection(); T result = this.responseConsumer.getResult(); Exception ex = this.responseConsumer.getException(); @@ -468,7 +496,9 @@ class DefaultAsyncRequestDirector imp } public synchronized boolean cancel() { - this.log.debug("HTTP exchange cancelled"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Cancelled"); + } try { boolean cancelled = this.responseConsumer.cancel(); @@ -504,7 +534,7 @@ class DefaultAsyncRequestDirector imp private synchronized void connectionRequestCompleted(final ManagedClientAsyncConnection conn) { if (this.log.isDebugEnabled()) { - this.log.debug("Connection request succeeded: " + conn); + this.log.debug("[exchange: " + this.id + "] Connection allocated: " + conn); } try { this.managedConn = conn; @@ -531,7 +561,9 @@ class DefaultAsyncRequestDirector imp } private synchronized void connectionRequestFailed(final Exception ex) { - this.log.debug("Connection request failed", ex); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] connection request failed"); + } try { this.resultCallback.failed(ex, this); } finally { @@ -540,7 +572,9 @@ class DefaultAsyncRequestDirector imp } private synchronized void connectionRequestCancelled() { - this.log.debug("Connection request cancelled"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Connection request cancelled"); + } try { this.resultCallback.cancelled(this); } finally { @@ -566,6 +600,9 @@ class DefaultAsyncRequestDirector imp private void requestConnection() { HttpRoute route = this.mainRequest.getRoute(); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Request connection for " + route); + } long connectTimeout = HttpConnectionParams.getConnectionTimeout(this.params); Object userToken = this.localContext.getAttribute(ClientContext.USER_TOKEN); this.connmgr.leaseConnection( @@ -705,11 +742,15 @@ class DefaultAsyncRequestDirector imp // Reset auth states if redirecting to another host if (!route.getTargetHost().equals(newTarget)) { - this.log.debug("Resetting target auth state"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Resetting target auth state"); + } this.targetAuthState.reset(); AuthScheme authScheme = this.proxyAuthState.getAuthScheme(); if (authScheme != null && authScheme.isConnectionBased()) { - this.log.debug("Resetting proxy auth state"); + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + this.id + "] Resetting proxy auth state"); + } this.proxyAuthState.reset(); } } @@ -720,7 +761,7 @@ class DefaultAsyncRequestDirector imp HttpRoute newRoute = determineRoute(newTarget, newRequest, this.localContext); if (this.log.isDebugEnabled()) { - this.log.debug("Redirecting to '" + uri + "' via " + newRoute); + this.log.debug("[exchange: " + this.id + "] Redirecting to '" + uri + "' via " + newRoute); } return new RoutedRequest(newRequest, newRoute); } Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/HttpNIOConnPool.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/HttpNIOConnPool.java?rev=1330755&r1=1330754&r2=1330755&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/HttpNIOConnPool.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/HttpNIOConnPool.java Thu Apr 26 10:22:42 2012 @@ -42,7 +42,7 @@ import org.apache.http.nio.reactor.IOSes class HttpNIOConnPool extends AbstractNIOConnPool { - private static AtomicLong COUNTER = new AtomicLong(); + private static final AtomicLong COUNTER = new AtomicLong(1); private final Log log; private final AsyncSchemeRegistry schemeRegistry;