hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1156522 - in /httpcomponents/httpclient/branches/conn-mgmt-redesign: httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/main/java/org/apache/http/impl/c...
Date Thu, 11 Aug 2011 07:46:35 GMT
Author: olegk
Date: Thu Aug 11 07:46:35 2011
New Revision: 1156522

URL: http://svn.apache.org/viewvc?rev=1156522&view=rev
Log:
Improved #detach method implementation

Modified:
    httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
    httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
    httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
    httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java
    httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java

Modified: httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java?rev=1156522&r1=1156521&r2=1156522&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
(original)
+++ httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
Thu Aug 11 07:46:35 2011
@@ -48,7 +48,7 @@ public class Benchmark {
 
    public static void main(String[] args) throws Exception {
 
-       String ns = System.getProperty("hc.benchmark.n-requests", "200000");
+       String ns = System.getProperty("hc.benchmark.n-requests", "400000");
        String nc = System.getProperty("hc.benchmark.concurrent", "20");
        String cls = System.getProperty("hc.benchmark.content-len", "2048");
 
@@ -76,12 +76,12 @@ public class Benchmark {
        int port = connector.getLocalPort();
 
        TestHttpAgent[] agents = new TestHttpAgent[] {
-               new TestHttpClient3(),
-               new TestHttpJRE(),
-               new TestHttpCore(),
+//               new TestHttpClient3(),
+//               new TestHttpJRE(),
+//               new TestHttpCore(),
                new TestHttpClient4(),
-               new TestJettyHttpClient(),
-               new TestNingHttpClient()
+//               new TestJettyHttpClient(),
+//               new TestNingHttpClient()
        };
 
        byte[] content = new byte[contentLen];
@@ -99,7 +99,7 @@ public class Benchmark {
                try {
                    agent.init();
                    // Warm up
-                   agent.get(warmup, 5, 500);
+                   agent.get(warmup, 500, 2);
                    // Sleep a little
                    Thread.sleep(5000);
                    System.out.println("=================================");

Modified: httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java?rev=1156522&r1=1156521&r2=1156522&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
(original)
+++ httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
Thu Aug 11 07:46:35 2011
@@ -43,6 +43,7 @@ import org.apache.http.conn.ssl.SSLSocke
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;

Modified: httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java?rev=1156522&r1=1156521&r2=1156522&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
(original)
+++ httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
Thu Aug 11 07:46:35 2011
@@ -254,11 +254,11 @@ public abstract class AbstractHttpClient
     /** The connection backoff strategy. */
     @GuardedBy("this")
     private ConnectionBackoffStrategy connectionBackoffStrategy;
-    
+
     /** The backoff manager. */
     @GuardedBy("this")
     private BackoffManager backoffManager;
-    
+
     /**
      * Creates a new HTTP client.
      *
@@ -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();
     }
@@ -481,19 +470,16 @@ public abstract class AbstractHttpClient
             supportedAuthSchemes = createAuthSchemeRegistry();
         }
         return supportedAuthSchemes;
-    } 
-    
+    }
+
     public synchronized void setAuthSchemes(final AuthSchemeRegistry authSchemeRegistry)
{
         supportedAuthSchemes = authSchemeRegistry;
     }
 
     public synchronized final ConnectionBackoffStrategy getConnectionBackoffStrategy() {
-        if (connectionBackoffStrategy == null) {
-            connectionBackoffStrategy = createConnectionBackoffStrategy();
-        }
         return connectionBackoffStrategy;
     }
-    
+
     public synchronized void setConnectionBackoffStrategy(final ConnectionBackoffStrategy
strategy) {
         connectionBackoffStrategy = strategy;
     }
@@ -506,16 +492,13 @@ public abstract class AbstractHttpClient
     }
 
     public synchronized final BackoffManager getBackoffManager() {
-        if (backoffManager == null) {
-            backoffManager = createBackoffManager();
-        }
         return backoffManager;
     }
-    
+
     public synchronized void setBackoffManager(final BackoffManager manager) {
         backoffManager = manager;
     }
-    
+
     public synchronized void setCookieSpecs(final CookieSpecRegistry cookieSpecRegistry)
{
         supportedCookieSpecs = cookieSpecRegistry;
     }
@@ -827,6 +810,9 @@ public abstract class AbstractHttpClient
 
         HttpContext execContext = null;
         RequestDirector director = null;
+        ConnectionBackoffStrategy connectionBackoffStrategy = null;
+        BackoffManager backoffManager = null;
+        HttpRoutePlanner httpRoutePlanner = null;
 
         // Initialize the request execution context making copies of
         // all shared objects that are potentially threading unsafe.
@@ -852,36 +838,44 @@ public abstract class AbstractHttpClient
                     getProxyAuthenticationHandler(),
                     getUserTokenHandler(),
                     determineParams(request));
+
+            connectionBackoffStrategy = getConnectionBackoffStrategy();
+            backoffManager = getBackoffManager();
+            httpRoutePlanner = getRoutePlanner();
         }
 
         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 = httpRoutePlanner.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 (getConnectionBackoffStrategy().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);
         }
@@ -915,7 +909,7 @@ public abstract class AbstractHttpClient
                 stateHandler,
                 params);
     }
-    
+
     /**
      * @since 4.1
      */

Modified: httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java?rev=1156522&r1=1156521&r2=1156522&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java
(original)
+++ httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java
Thu Aug 11 07:46:35 2011
@@ -85,12 +85,10 @@ class ManagedClientConnectionImpl implem
         return this.poolEntry;
     }
 
-    void detach() {
+    HttpPoolEntry detach() {
+        HttpPoolEntry local = this.poolEntry;
         this.poolEntry = null;
-    }
-
-    boolean isDetached() {
-        return this.poolEntry == null;
+        return local;
     }
 
     public ClientConnectionManager getManager() {
@@ -113,6 +111,14 @@ class ManagedClientConnectionImpl implem
         return local.getConnection();
     }
 
+    private HttpPoolEntry ensurePoolEntry() {
+        HttpPoolEntry local = this.poolEntry;
+        if (local == null) {
+            throw new ConnectionShutdownException();
+        }
+        return local;
+    }
+
     public void close() throws IOException {
         OperatedClientConnection conn = getConnection();
         if (conn != null) {
@@ -254,11 +260,8 @@ class ManagedClientConnectionImpl implem
     }
 
     public HttpRoute getRoute() {
-        HttpPoolEntry local = this.poolEntry;
-        if (local == null) {
-            throw new ConnectionShutdownException();
-        }
-        return poolEntry.getEffectiveRoute();
+        HttpPoolEntry local = ensurePoolEntry();
+        return local.getEffectiveRoute();
     }
 
     public void open(
@@ -403,11 +406,13 @@ class ManagedClientConnectionImpl implem
     }
 
     public Object getState() {
-        return this.poolEntry.getState();
+        HttpPoolEntry local = ensurePoolEntry();
+        return local.getState();
     }
 
     public void setState(final Object state) {
-        this.poolEntry.setState(state);
+        HttpPoolEntry local = ensurePoolEntry();
+        local.setState(state);
     }
 
     public void markReusable() {

Modified: httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java?rev=1156522&r1=1156521&r2=1156522&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java
(original)
+++ httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java
Thu Aug 11 07:46:35 2011
@@ -229,7 +229,7 @@ public class PoolingClientConnectionMana
         }
 
         synchronized (managedConn) {
-            HttpPoolEntry entry = managedConn.getPoolEntry();
+            HttpPoolEntry entry = managedConn.detach();
             if (entry == null) {
                 return;
             }
@@ -255,7 +255,6 @@ public class PoolingClientConnectionMana
                 }
             } finally {
                 this.pool.release(entry, managedConn.isMarkedReusable());
-                managedConn.detach();
             }
             if (this.log.isDebugEnabled()) {
                 this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));



Mime
View raw message