You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/08/10 15:34:07 UTC
svn commit: r1156175 -
/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
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);
}