hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r558327 - /jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java
Date Sat, 21 Jul 2007 13:12:44 GMT
Author: rolandw
Date: Sat Jul 21 06:12:40 2007
New Revision: 558327

URL: http://svn.apache.org/viewvc?view=rev&rev=558327
Log:
more cosmetic renaming

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

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java?view=diff&rev=558327&r1=558326&r2=558327
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java
Sat Jul 21 06:12:40 2007
@@ -214,7 +214,7 @@
 
             // we used to clone the hostconfig here, but it is now immutable:
             //route = new HttpRoute(route);
-            HostConnectionPool hostPool = connectionPool.getHostPool(route);
+            RouteConnPool routePool = connectionPool.getHostPool(route);
             WaitingThread waitingThread = null;
 
             boolean useTimeout = (timeout > 0);
@@ -231,12 +231,12 @@
                 
                 // happen to have a free connection with the right specs
                 //
-                if (hostPool.freeConnections.size() > 0) {
+                if (routePool.freeConnections.size() > 0) {
                     entry = connectionPool.getFreeConnection(route);
 
                 // have room to make more
                 //
-                } else if ((hostPool.numConnections < maxHostConnections) 
+                } else if ((routePool.numConnections < maxHostConnections) 
                     && (connectionPool.numConnections < maxTotalConnections))
{
 
                     entry = createPoolEntry(route);
@@ -244,7 +244,7 @@
                 // have room to add host connection, and there is at least one
                 // free connection that can be liberated to make overall room
                 //
-                } else if ((hostPool.numConnections < maxHostConnections) 
+                } else if ((routePool.numConnections < maxHostConnections) 
                     && (connectionPool.freeConnections.size() > 0)) {
 
                     connectionPool.deleteLeastUsedConnection();
@@ -269,7 +269,7 @@
                         
                         if (waitingThread == null) {
                             waitingThread = new WaitingThread();
-                            waitingThread.hostConnectionPool = hostPool;
+                            waitingThread.pool = routePool;
                             waitingThread.thread = Thread.currentThread();
                         } else {
                             waitingThread.interruptedByConnectionPool = false;
@@ -279,7 +279,7 @@
                             startWait = System.currentTimeMillis();
                         }
                         
-                        hostPool.waitingThreads.addLast(waitingThread);
+                        routePool.waitingThreads.addLast(waitingThread);
                         connectionPool.waitingThreads.addLast(waitingThread);
                         connectionPool.wait(timeToWait);
                         
@@ -300,7 +300,7 @@
                             // "spurious wakeup", or were interrupted by an
                             // external thread.  Regardless we need to 
                             // cleanup for ourselves in the wait queue.
-                            hostPool.waitingThreads.remove(waitingThread);
+                            routePool.waitingThreads.remove(waitingThread);
                             connectionPool.waitingThreads.remove(waitingThread);
                         }
                         
@@ -604,8 +604,8 @@
      */
     public int getConnectionsInPool(HttpRoute route) {
         synchronized (connectionPool) {
-            HostConnectionPool hostPool = connectionPool.getHostPool(route);
-            return hostPool.numConnections;
+            RouteConnPool routePool = connectionPool.getHostPool(route);
+            return routePool.numConnections;
         }
     }
 
@@ -679,7 +679,7 @@
 
         /**
          * Map where keys are {@link HttpRoute}s and values are
-         * {@link HostConnectionPool}s
+         * {@link RouteConnPool}s
          */
         private final Map mapHosts = new HashMap();
 
@@ -735,14 +735,14 @@
             TrackingPoolEntry createEntry(HttpRoute route,
                                           OperatedClientConnection conn) {
 
-            HostConnectionPool hostPool = getHostPool(route);
+            RouteConnPool routePool = getHostPool(route);
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Allocating new connection, route=" + route);
             }
             TrackingPoolEntry entry = new TrackingPoolEntry(conn);
             entry.plannedRoute = route;
             numConnections++;
-            hostPool.numConnections++;
+            routePool.numConnections++;
     
             // store a reference to this entry so that it can be cleaned up
             // in the event it is not correctly released
@@ -761,9 +761,9 @@
         public synchronized
             void handleLostConnection(HttpRoute config) {
 
-            HostConnectionPool hostPool = getHostPool(config);
-            hostPool.numConnections--;
-            if (hostPool.numConnections < 1)
+            RouteConnPool routePool = getHostPool(config);
+            routePool.numConnections--;
+            if (routePool.numConnections < 1)
                 mapHosts.remove(config);
 
             numConnections--;
@@ -777,14 +777,14 @@
          * @return a pool (list) of connections available for the given route
          */
         public synchronized
-            HostConnectionPool getHostPool(HttpRoute route) {
+            RouteConnPool getHostPool(HttpRoute route) {
 
             // Look for a list of connections for the given config
-            HostConnectionPool listConnections =
-                (HostConnectionPool) mapHosts.get(route);
+            RouteConnPool listConnections =
+                (RouteConnPool) mapHosts.get(route);
             if (listConnections == null) {
                 // First time for this config
-                listConnections = new HostConnectionPool();
+                listConnections = new RouteConnPool();
                 listConnections.route = route;
                 mapHosts.put(route, listConnections);
             }
@@ -803,10 +803,10 @@
 
             TrackingPoolEntry entry = null;
 
-            HostConnectionPool hostPool = getHostPool(route);
+            RouteConnPool routePool = getHostPool(route);
 
-            if (hostPool.freeConnections.size() > 0) {
-                entry = (TrackingPoolEntry) hostPool.freeConnections.removeLast();
+            if (routePool.freeConnections.size() > 0) {
+                entry = (TrackingPoolEntry) routePool.freeConnections.removeLast();
                 freeConnections.remove(entry);
                 // store a reference to this entry so that it can be cleaned up
                 // in the event it is not correctly released
@@ -870,12 +870,12 @@
 
             closeConnection(entry.connection);
 
-            HostConnectionPool hostPool = getHostPool(route);
+            RouteConnPool routePool = getHostPool(route);
             
-            hostPool.freeConnections.remove(entry);
-            hostPool.numConnections--;
+            routePool.freeConnections.remove(entry);
+            routePool.numConnections--;
             numConnections--;
-            if (hostPool.numConnections < 1)
+            if (routePool.numConnections < 1)
                 mapHosts.remove(route);
 
             // remove the connection from the timeout handler
@@ -901,7 +901,7 @@
          * Notifies a waiting thread that a connection for the given configuration is 
          * available.
          * @param configuration the host config to use for notifying
-         * @see #notifyWaitingThread(HostConnectionPool)
+         * @see #notifyWaitingThread(RouteConnPool)
          */
         public synchronized void notifyWaitingThread(HttpRoute configuration) {
             notifyWaitingThread(getHostPool(configuration));
@@ -912,28 +912,28 @@
          * available.  This will wake a thread waiting in this host pool or if there is not
          * one a thread in the connection pool will be notified.
          * 
-         * @param hostPool the host pool to use for notifying
+         * @param routePool the host pool to use for notifying
          */
-        public synchronized void notifyWaitingThread(HostConnectionPool hostPool) {
+        public synchronized void notifyWaitingThread(RouteConnPool routePool) {
 
             // find the thread we are going to notify, we want to ensure that each
             // waiting thread is only interrupted once so we will remove it from 
             // all wait queues before interrupting it
             WaitingThread waitingThread = null;
                 
-            if (hostPool.waitingThreads.size() > 0) {
+            if (routePool.waitingThreads.size() > 0) {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Notifying thread waiting on host pool, route=" 
-                        + hostPool.route);
+                        + routePool.route);
                 }
-                waitingThread = (WaitingThread) hostPool.waitingThreads.removeFirst();
+                waitingThread = (WaitingThread) routePool.waitingThreads.removeFirst();
                 waitingThreads.remove(waitingThread);
             } else if (waitingThreads.size() > 0) {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("No-one waiting on host pool, notifying next waiting thread.");
                 }
                 waitingThread = (WaitingThread) waitingThreads.removeFirst();
-                waitingThread.hostConnectionPool.waitingThreads.remove(waitingThread);
+                waitingThread.pool.waitingThreads.remove(waitingThread);
             } else if (LOG.isDebugEnabled()) {
                 LOG.debug("Notifying no-one, there are no waiting threads");
             }
@@ -966,16 +966,16 @@
                     return;
                 }
                 
-                HostConnectionPool hostPool = getHostPool(route);
+                RouteConnPool routePool = getHostPool(route);
 
                 // Put the connection back in the available list
                 // and notify a waiter
-                hostPool.freeConnections.add(entry);
-                if (hostPool.numConnections == 0) {
+                routePool.freeConnections.add(entry);
+                if (routePool.numConnections == 0) {
                     // for some reason this connection pool didn't already exist
                     LOG.error("Host connection pool not found, route=" 
                               + route);
-                    hostPool.numConnections = 1;
+                    routePool.numConnections = 1;
                 }
 
                 freeConnections.add(entry);
@@ -993,10 +993,10 @@
                 // register the connection with the timeout handler
                 idleConnectionHandler.add(entry.connection);
 
-                notifyWaitingThread(hostPool);
+                notifyWaitingThread(routePool);
             }
         }
-    }
+    } // class ConnectionPool
 
 
     private static void closeConnection(final OperatedClientConnection conn) {
@@ -1024,7 +1024,7 @@
      * A simple struct-like class to combine the connection list and the count
      * of created connections.
      */
-    private static class HostConnectionPool {
+    private static class RouteConnPool {
 
         /** The route this pool is for */
         public HttpRoute route;
@@ -1048,12 +1048,12 @@
         public Thread thread;
         
         /** The connection pool the thread is waiting for */
-        public HostConnectionPool hostConnectionPool;
+        public RouteConnPool pool;
         
         /**
          * Indicates the source of an interruption.
          * Set to <code>true</code> inside
-         * {@link ConnectionPool#notifyWaitingThread(HostConnectionPool)}
+         * {@link ConnectionPool#notifyWaitingThread(RouteConnPool)}
          * and {@link ThreadSafeClientConnManager#shutdown shutdown()}
          * before the thread is interrupted.
          * If not set, the thread was interrupted from the outside.
@@ -1061,6 +1061,7 @@
         public boolean interruptedByConnectionPool = false;
     }
 
+
     /**
      * A thread for listening for HttpConnections reclaimed by the garbage
      * collector.
@@ -1124,7 +1125,7 @@
             }
         }
 
-    }
+    } // class ReferenceQueueThread
 
     
     /**



Mime
View raw message