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 979C78197 for ; Wed, 10 Aug 2011 13:34:28 +0000 (UTC) Received: (qmail 6137 invoked by uid 500); 10 Aug 2011 13:34:28 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 6090 invoked by uid 500); 10 Aug 2011 13:34:28 -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 6081 invoked by uid 99); 10 Aug 2011 13:34:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Aug 2011 13:34:28 +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; Wed, 10 Aug 2011 13:34:26 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 341F82388AB9 for ; Wed, 10 Aug 2011 13:34:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1156175 - /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java Date: Wed, 10 Aug 2011 13:34:07 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110810133407.341F82388AB9@eris.apache.org> Author: olegk Date: Wed Aug 10 13:34:06 2011 New Revision: 1156175 URL: http://svn.apache.org/viewvc?rev=1156175&view=rev Log: Eliminated synchronization overhead introduced by the connection backoff code Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java?rev=1156175&r1=1156174&r2=1156175&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java Wed Aug 10 13:34:06 2011 @@ -373,17 +373,6 @@ public abstract class AbstractHttpClient return registry; } - protected BackoffManager createBackoffManager() { - return new BackoffManager() { - public void backOff(HttpRoute ignored) { } - public void probe(HttpRoute ignored) { } - }; - } - - protected ConnectionBackoffStrategy createConnectionBackoffStrategy() { - return new NullBackoffStrategy(); - } - protected HttpRequestExecutor createRequestExecutor() { return new HttpRequestExecutor(); } @@ -488,9 +477,6 @@ public abstract class AbstractHttpClient } public synchronized final ConnectionBackoffStrategy getConnectionBackoffStrategy() { - if (connectionBackoffStrategy == null) { - connectionBackoffStrategy = createConnectionBackoffStrategy(); - } return connectionBackoffStrategy; } @@ -506,9 +492,6 @@ public abstract class AbstractHttpClient } public synchronized final BackoffManager getBackoffManager() { - if (backoffManager == null) { - backoffManager = createBackoffManager(); - } return backoffManager; } @@ -827,6 +810,9 @@ public abstract class AbstractHttpClient HttpContext execContext = null; RequestDirector director = null; + HttpRoutePlanner routePlanner = null; + ConnectionBackoffStrategy connectionBackoffStrategy = null; + BackoffManager backoffManager = null; // Initialize the request execution context making copies of // all shared objects that are potentially threading unsafe. @@ -852,36 +838,43 @@ public abstract class AbstractHttpClient getProxyAuthenticationHandler(), getUserTokenHandler(), determineParams(request)); + routePlanner = getRoutePlanner(); + connectionBackoffStrategy = getConnectionBackoffStrategy(); + backoffManager = getBackoffManager(); } try { - HttpHost targetForRoute = (target != null) ? target - : (HttpHost) determineParams(request).getParameter( - ClientPNames.DEFAULT_HOST); - HttpRoute route = getRoutePlanner().determineRoute(targetForRoute, request, execContext); - - HttpResponse out; - try { - out = director.execute(target, request, execContext); - } catch (RuntimeException re) { - if (getConnectionBackoffStrategy().shouldBackoff(re)) { - getBackoffManager().backOff(route); + if (connectionBackoffStrategy != null && backoffManager != null) { + HttpHost targetForRoute = (target != null) ? target + : (HttpHost) determineParams(request).getParameter( + ClientPNames.DEFAULT_HOST); + HttpRoute route = routePlanner.determineRoute(targetForRoute, request, execContext); + + HttpResponse out; + try { + out = director.execute(target, request, execContext); + } catch (RuntimeException re) { + if (connectionBackoffStrategy.shouldBackoff(re)) { + backoffManager.backOff(route); + } + throw re; + } catch (Exception e) { + if (connectionBackoffStrategy.shouldBackoff(e)) { + backoffManager.backOff(route); + } + if (e instanceof HttpException) throw (HttpException)e; + if (e instanceof IOException) throw (IOException)e; + throw new UndeclaredThrowableException(e); } - throw re; - } catch (Exception e) { - if (getConnectionBackoffStrategy().shouldBackoff(e)) { - getBackoffManager().backOff(route); + if (connectionBackoffStrategy.shouldBackoff(out)) { + backoffManager.backOff(route); + } else { + backoffManager.probe(route); } - if (e instanceof HttpException) throw (HttpException)e; - if (e instanceof IOException) throw (IOException)e; - throw new RuntimeException("unexpected exception", e); - } - if (getConnectionBackoffStrategy().shouldBackoff(out)) { - getBackoffManager().backOff(route); + return out; } else { - getBackoffManager().probe(route); + return director.execute(target, request, execContext); } - return out; } catch(HttpException httpException) { throw new ClientProtocolException(httpException); }