hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r607426 - /httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
Date Sat, 29 Dec 2007 15:16:52 GMT
Author: rolandw
Date: Sat Dec 29 07:16:51 2007
New Revision: 607426

URL: http://svn.apache.org/viewvc?rev=607426&view=rev
Log:
HTTPCLIENT-725: use factory methods

Modified:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java?rev=607426&r1=607425&r2=607426&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
Sat Dec 29 07:16:51 2007
@@ -73,17 +73,17 @@
 
 
     /** The list of free connections */
-    private Queue<BasicPoolEntry> freeConnections;
+    protected Queue<BasicPoolEntry> freeConnections;
 
     /** The list of WaitingThreads waiting for a connection */
-    private Queue<WaitingThread> waitingThreads;
+    protected Queue<WaitingThread> waitingThreads;
 
     /**
      * A map of route-specific pools.
      * Keys are of class {@link HttpRoute},
      * values of class {@link RouteSpecificPool}.
      */
-    private final Map<HttpRoute,RouteSpecificPool> routeToPool;
+    protected final Map<HttpRoute,RouteSpecificPool> routeToPool;
 
 
 
@@ -95,10 +95,68 @@
     public ConnPoolByRoute(ClientConnectionManager mgr) {
         super(mgr);
 
-        //@@@ use factory method, at least for waitingThreads
-        freeConnections = new LinkedList<BasicPoolEntry>();
-        waitingThreads = new LinkedList<WaitingThread>();
-        routeToPool = new HashMap<HttpRoute,RouteSpecificPool>();
+        freeConnections = createFreeConnQueue();
+        waitingThreads  = createWaitingThreadQueue();
+        routeToPool     = createRouteToPoolMap();
+    }
+
+
+    /**
+     * Creates the queue for {@link #freeConnections}.
+     * Called once by the constructor.
+     *
+     * @return  a queue
+     */
+    protected Queue<BasicPoolEntry> createFreeConnQueue() {
+        return new LinkedList<BasicPoolEntry>();
+    }
+
+    /**
+     * Creates the queue for {@link #waitingThreads}.
+     * Called once by the constructor.
+     *
+     * @return  a queue
+     */
+    protected Queue<WaitingThread> createWaitingThreadQueue() {
+        return new LinkedList<WaitingThread>();
+    }
+
+    /**
+     * Creates the map for {@link #routeToPool}.
+     * Called once by the constructor.
+     *
+     * @return  a map
+     */
+    protected Map<HttpRoute,RouteSpecificPool> createRouteToPoolMap() {
+        return new HashMap<HttpRoute,RouteSpecificPool>();
+    }
+
+
+    /**
+     * Creates a new route-specific pool.
+     * Called by {@link #getRoutePool} when necessary.
+     *
+     * @param route     the route
+     *
+     * @return  the new pool
+     */
+    protected RouteSpecificPool newRouteSpecificPool(HttpRoute route) {
+        return new RouteSpecificPool(route);
+    }
+
+
+    /**
+     * Creates a new waiting thread.
+     * Called by {@link #getRoutePool} when necessary.
+     *
+     * @param cond      the condition to wait for
+     * @param rospl     the route specific pool, or <code>null</code>
+     *
+     * @return  a waiting thread representation
+     */
+    protected WaitingThread newWaitingThread(Condition cond,
+                                             RouteSpecificPool rospl) {
+        return new WaitingThread(cond, rospl);
     }
 
 
@@ -133,19 +191,6 @@
     }
 
 
-    /**
-     * Creates a new route-specific pool.
-     * Called by {@link #getRoutePool getRoutePool}, if necessary.
-     *
-     * @param route     the route
-     *
-     * @return  the new pool
-     */
-    protected RouteSpecificPool newRouteSpecificPool(HttpRoute route) {
-        return new RouteSpecificPool(route);
-    }
-
-
     //@@@ consider alternatives for gathering statistics
     public int getConnectionsInPool(HttpRoute route) {
 
@@ -219,9 +264,8 @@
                     }
 
                     if (waitingThread == null) {
-                        //@@@ use factory method?
-                        waitingThread = new WaitingThread
-                            (poolLock.newCondition(), rospl);
+                        waitingThread =
+                            newWaitingThread(poolLock.newCondition(), rospl);
                     }
 
                     boolean success = false;
@@ -363,15 +407,16 @@
             LOG.debug("Creating new connection. " + rospl.getRoute());
         }
 
-        BasicPoolEntry entry = null;
+        // the entry will create the connection when needed
+        BasicPoolEntry entry =
+            new BasicPoolEntry(op, rospl.getRoute(), refQueue);
+
         try {
             poolLock.lock();
 
-            // the entry will create the connection when needed
-            entry = new BasicPoolEntry(op, rospl.getRoute(), refQueue);
             rospl.createdEntry(entry);
             numConnections++;
-    
+
             issuedConnections.add(entry.getWeakRef());
 
         } finally {



Mime
View raw message