hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r883867 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/impl/conn/tsccm/ test/java/org/apache/http/impl/conn/tsccm/
Date Tue, 24 Nov 2009 20:48:21 GMT
Author: olegk
Date: Tue Nov 24 20:48:21 2009
New Revision: 883867

URL: http://svn.apache.org/viewvc?rev=883867&view=rev
Log:
Use ConnPerRoute interface to look up maxEntries value for RouteSpecificPools

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java?rev=883867&r1=883866&r2=883867&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
Tue Nov 24 20:48:21 2009
@@ -166,7 +166,7 @@
      * @return  the new pool
      */
     protected RouteSpecificPool newRouteSpecificPool(HttpRoute route) {
-        return new RouteSpecificPool(route, this.connPerRoute.getMaxForRoute(route));
+        return new RouteSpecificPool(route, this.connPerRoute);
     }
 
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java?rev=883867&r1=883866&r2=883867&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
Tue Nov 24 20:48:21 2009
@@ -36,6 +36,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.conn.OperatedClientConnection;
+import org.apache.http.conn.params.ConnPerRoute;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.util.LangUtils;
 
@@ -55,9 +56,12 @@
     /** The route this pool is for. */
     protected final HttpRoute route; //Immutable
 
-    /** the maximum number of entries allowed for this pool */
+    @Deprecated
     protected final int maxEntries;
     
+    /** Connections per route */
+    protected final ConnPerRoute connPerRoute;
+    
     /**
      * The list of free entries.
      * This list is managed LIFO, to increase idle times and
@@ -73,20 +77,39 @@
 
 
     /**
+     * @Deprecated use {@link RouteSpecificPool#RouteSpecificPool(HttpRoute, ConnPerRoute)}
+     */
+    @Deprecated
+    public RouteSpecificPool(HttpRoute route, int maxEntries) {
+        this.route = route;
+        this.maxEntries = maxEntries;
+        this.connPerRoute = new ConnPerRoute() {
+            public int getMaxForRoute(HttpRoute route) {
+                return RouteSpecificPool.this.maxEntries;
+            }
+        };
+        this.freeEntries = new LinkedList<BasicPoolEntry>();
+        this.waitingThreads = new LinkedList<WaitingThread>();
+        this.numEntries = 0;
+    }
+
+
+    /**
      * Creates a new route-specific pool.
      *
      * @param route the route for which to pool
      * @param maxEntries the maximum number of entries allowed for this pool
      */
-    public RouteSpecificPool(HttpRoute route, int maxEntries) {
+    public RouteSpecificPool(HttpRoute route, ConnPerRoute connPerRoute) {
         this.route = route;
-        this.maxEntries = maxEntries;
+        this.connPerRoute = connPerRoute;
+        this.maxEntries = connPerRoute.getMaxForRoute(route);
         this.freeEntries = new LinkedList<BasicPoolEntry>();
         this.waitingThreads = new LinkedList<WaitingThread>();
         this.numEntries = 0;
     }
 
-
+    
     /**
      * Obtains the route for which this pool is specific.
      *
@@ -126,7 +149,7 @@
      * @return capacity
      */
     public int getCapacity() {
-        return maxEntries - numEntries;
+        return connPerRoute.getMaxForRoute(route) - numEntries;
     }
     
     

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java?rev=883867&r1=883866&r2=883867&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java
Tue Nov 24 20:48:21 2009
@@ -36,6 +36,8 @@
 import junit.framework.TestSuite;
 
 import org.apache.http.HttpHost;
+import org.apache.http.conn.params.ConnPerRoute;
+import org.apache.http.conn.params.ConnPerRouteBean;
 import org.apache.http.conn.routing.HttpRoute;
 
 
@@ -79,8 +81,9 @@
         assertNull  ("pool from nowhere", wt.getPool());
         assertNull  ("thread from nowhere", wt.getThread());
 
-        HttpRoute         route = new HttpRoute(TARGET);
-        RouteSpecificPool rospl = new RouteSpecificPool(route, 10);
+        HttpRoute route = new HttpRoute(TARGET);
+        ConnPerRoute connPerRoute = new ConnPerRouteBean(10);
+        RouteSpecificPool rospl = new RouteSpecificPool(route, connPerRoute);
         wt = new WaitingThread(cnd, rospl);
         assertEquals("wrong condition", cnd, wt.getCondition());
         assertEquals("wrong pool", rospl, wt.getPool());



Mime
View raw message