hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r561041 - in /jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http: conn/ impl/conn/ impl/conn/tsccm/
Date Mon, 30 Jul 2007 16:52:27 GMT
Author: rolandw
Date: Mon Jul 30 09:52:22 2007
New Revision: 561041

URL: http://svn.apache.org/viewvc?view=rev&rev=561041
Log:
code and JavaDoc cleanup

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

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java?view=diff&rev=561041&r1=561040&r2=561041
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java
Mon Jul 30 09:52:22 2007
@@ -32,6 +32,9 @@
 package org.apache.http.conn;
 
 
+import org.apache.http.params.HttpParams;
+
+
 
 /**
  * Management interface for {@link ManagedClientConnection client connections}.
@@ -49,7 +52,23 @@
  */
 public interface ClientConnectionManager {
 
-    SchemeRegistry getSchemeRegistry();
+    /**
+     * Obtains the parameters of this manager.
+     *
+     * @return  the parameters, never <code>null</code>
+     */
+    HttpParams getParams()
+        ;
+
+
+    /**
+     * Obtains the scheme registry used by this manager.
+     *
+     * @return  the scheme registry, never <code>null</code>
+     */
+    SchemeRegistry getSchemeRegistry()
+        ;
+
     
     /**
      * Obtains a connection.

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java?view=diff&rev=561041&r1=561040&r2=561041
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
Mon Jul 30 09:52:22 2007
@@ -114,10 +114,12 @@
                                    SchemeRegistry schreg) {
 
         if (params == null) {
-            throw new IllegalArgumentException("Parameters must not be null.");
+            throw new IllegalArgumentException
+                ("Parameters must not be null.");
         }
         if (schreg == null) {
-            throw new IllegalArgumentException("Scheme registry must not be null.");
+            throw new IllegalArgumentException
+                ("Scheme registry must not be null.");
         }
         this.params          = params;
         this.schemeRegistry  = schreg;
@@ -131,6 +133,12 @@
     } // <constructor>
 
 
+    // non-javadoc, see interface ClientConnectionManager
+    public HttpParams getParams() {
+        return this.params;
+    }
+
+    // non-javadoc, see interface ClientConnectionManager
     public SchemeRegistry getSchemeRegistry() {
         return this.schemeRegistry;
     }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java?view=diff&rev=561041&r1=561040&r2=561041
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
Mon Jul 30 09:52:22 2007
@@ -121,17 +121,15 @@
     /**
      * Creates a new connection pool.
      *
-     * @param tsccm     the connection manager
+     * @param mgr   the connection manager
      */
-    protected AbstractConnPool(ThreadSafeClientConnManager tsccm) {
+    protected AbstractConnPool(ClientConnectionManager mgr) {
 
-        params = tsccm.getParams();
+        params = mgr.getParams();
 
         issuedConnections = new HashSet();
         idleConnHandler = new IdleConnectionHandler();
 
-        //@@@ currently must be false, otherwise the TSCCM
-        //@@@ will not be garbage collected in the unit test...
         boolean conngc = true; //@@@ check parameters to decide
         if (conngc) {
             refQueue = new ReferenceQueue();
@@ -142,7 +140,7 @@
             t.start();
         }
 
-        connManager = new ConnMgrRef(tsccm, refQueue);
+        connManager = new ConnMgrRef(mgr, refQueue);
     }
 
 

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java?view=diff&rev=561041&r1=561040&r2=561041
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
Mon Jul 30 09:52:22 2007
@@ -37,7 +37,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-//import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.ClientConnectionOperator;
 import org.apache.http.conn.ConnectionPoolTimeoutException;
 import org.apache.http.conn.HttpRoute;
@@ -138,10 +138,10 @@
     /**
      * Creates a new connection pool, managed by route.
      *
-     * @param tsccm     the connection manager
+     * @param mgr   the connection manager
      */
-    public ConnPoolByRoute(ThreadSafeClientConnManager tsccm) {
-        super(tsccm);
+    public ConnPoolByRoute(ClientConnectionManager mgr) {
+        super(mgr);
 
         freeConnections = new LinkedList();
         waitingThreads = new LinkedList();

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java?view=diff&rev=561041&r1=561040&r2=561041
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
Mon Jul 30 09:52:22 2007
@@ -66,8 +66,7 @@
 public class ThreadSafeClientConnManager
     implements ClientConnectionManager {
 
-    //@@@ LOG must be static for now, it's used in static methods
-    private final static Log LOG =
+    private final Log LOG =
         LogFactory.getLog(ThreadSafeClientConnManager.class);
 
 
@@ -75,18 +74,13 @@
     protected SchemeRegistry schemeRegistry; 
     
     /** The parameters of this connection manager. */
-    private HttpParams params;
-
+    protected HttpParams params;
 
     /** The pool of connections being managed. */
-    //@@@ temporarily, used in BasicPoolEntry
-    /*private*/ AbstractConnPool connectionPool;
+    protected final AbstractConnPool connectionPool;
 
     /** The operator for opening and updating connections. */
-    /*private*/ ClientConnectionOperator connOperator;
-
-    /** Indicates whether this connection manager is shut down. */
-    private volatile boolean isShutDown;
+    protected ClientConnectionOperator connOperator;
     
 
 
@@ -103,18 +97,45 @@
         if (params == null) {
             throw new IllegalArgumentException("Parameters must not be null.");
         }
-        this.params = params;
-        this.schemeRegistry  = schreg;
-        this.connectionPool = new ConnPoolByRoute(this);
-        this.connOperator = createConnectionOperator(schreg);
-        this.isShutDown = false;
-
-        //@@@ synchronized(BadStaticMaps.ALL_CONNECTION_MANAGERS) {
-        //@@@    BadStaticMaps.ALL_CONNECTION_MANAGERS.put(this, null);
-        //@@@}
+        this.params         = params;
+        this.schemeRegistry = schreg;
+        this.connectionPool = createConnectionPool();
+        this.connOperator   = createConnectionOperator(schreg);
+
     } // <constructor>
 
 
+    /**
+     * Hook for creating the connection pool.
+     *
+     * @return  the connection pool to use
+     */
+    protected AbstractConnPool createConnectionPool() {
+
+        return new ConnPoolByRoute(this);
+    }
+
+
+    /**
+     * Hook for creating the connection operator.
+     * It is called by the constructor.
+     * Derived classes can override this method to change the
+     * instantiation of the operator.
+     * The default implementation here instantiates
+     * {@link DefaultClientConnectionOperator DefaultClientConnectionOperator}.
+     *
+     * @param schreg    the scheme registry to use, or <code>null</code>
+     *
+     * @return  the connection operator to use
+     */
+    protected ClientConnectionOperator
+        createConnectionOperator(SchemeRegistry schreg) {
+
+        return new DefaultClientConnectionOperator(schreg);
+    }
+
+
+    // non-javadoc, see interface ClientConnectionManager
     public SchemeRegistry getSchemeRegistry() {
         return this.schemeRegistry;
     }
@@ -127,13 +148,13 @@
             try {
                 return getConnection(route, 0);
             } catch (ConnectionPoolTimeoutException e) {
-                // we'll go ahead and log this, but it should never happen.
+                // We'll go ahead and log this, but it should never happen.
                 // Exceptions are only thrown when the timeout occurs and
                 // since we have no timeout, it doesn't happen.
                 LOG.debug(
                     "Unexpected exception while waiting for connection",
                     e
-                );
+                    );
             }
         }
     }
@@ -159,33 +180,8 @@
         return new TSCCMConnAdapter(this, entry);
     }
 
-
-    /**
-     * Hook for creating the connection operator.
-     * It is called by the constructor.
-     * Derived classes can override this method to change the
-     * instantiation of the operator.
-     * The default implementation here instantiates
-     * {@link DefaultClientConnectionOperator DefaultClientConnectionOperator}.
-     *
-     * @param schreg    the scheme registry to use, or <code>null</code>
-     *
-     * @return  the connection operator to use
-     */
-    protected ClientConnectionOperator
-        createConnectionOperator(SchemeRegistry schreg) {
-
-        return new DefaultClientConnectionOperator(schreg);
-    }
-
     
-    /**
-     * Releases an allocated connection.
-     * If another thread is blocked in getConnection() that could use this
-     * connection, it will be woken up.
-     *
-     * @param conn the connection to make available.
-     */
+    // non-javadoc, see interface ClientConnectionManager
     public void releaseConnection(ManagedClientConnection conn) {
 
         if (!(conn instanceof TSCCMConnAdapter)) {
@@ -206,7 +202,7 @@
                     LOG.debug
                         ("Released connection open but not marked reusable.");
                 }
-                // In MTHCM, method releasePoolEntry below would call
+                // In MTHCM, there would be a call to
                 // SimpleHttpConnectionManager.finishLastResponse(conn);
                 // Consuming the response is handled outside in 4.0.
 
@@ -224,55 +220,19 @@
         } finally {
             BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
             hca.detach();
-            releasePoolEntry(entry);
+            if (entry != null) // is it worth to bother with this check? @@@
+                connectionPool.freeEntry(entry);
         }
     }
 
 
-    /**
-     * Releases an allocated connection by the pool entry.
-     *
-     * @param entry     the pool entry for the connection to release,
-     *                  or <code>null</code>
-     */
-    private void releasePoolEntry(BasicPoolEntry entry) {
-
-        if (entry == null)
-            return;
-
-        connectionPool.freeEntry(entry);
-    }
-
-
-
-    /* *
-     * Shuts down all instances of this class.
-     *
-     * @deprecated no replacement
-     * /
-    public static void shutdownAll() {
-        //@@@ BadStaticMaps.shutdownAll();
+    // non-javadoc, see interface ClientConnectionManager
+    public void shutdown() {
+        connectionPool.shutdown();
     }
-    */
 
 
     /**
-     * Shuts down the connection manager and releases all resources.
-     * All connections associated with this manager will be closed
-     * and released. 
-     * The connection manager can no longer be used once shut down.
-     * Calling this method more than once will have no effect.
-     */
-    public synchronized void shutdown() {
-        synchronized (connectionPool) {
-            if (!isShutDown) {
-                isShutDown = true;
-                connectionPool.shutdown();
-            }
-        }
-    }
-
-    /**
      * Gets the total number of pooled connections for the given route.
      * This is the total number of connections that have been created and
      * are still in use by this connection manager for the route.
@@ -286,6 +246,7 @@
         return ((ConnPoolByRoute)connectionPool).getConnectionsInPool(route);
     }
 
+
     /**
      * Gets the total number of pooled connections.  This is the total number of 
      * connections that have been created and are still in use by this connection 
@@ -301,57 +262,32 @@
     }
 
 
-    /**
-     * Deletes all free connections that are closed.
-     * Only connections currently owned by the connection
-     * manager are processed.
-     */
-    private void deleteClosedConnections() {
-        connectionPool.deleteClosedConnections();
-    }
-
-
-    /**
-     * Deletes all free connections that are idle or closed.
-     */
+    // non-javadoc, see interface ClientConnectionManager
     public void closeIdleConnections(long idleTimeout) {
+        // combine these two in a single call?
         connectionPool.closeIdleConnections(idleTimeout);
-        deleteClosedConnections();
+        connectionPool.deleteClosedConnections();
     }
 
 
-    /**
-     * Returns {@link HttpParams parameters} associated 
-     * with this connection manager.
-     */
+    // non-javadoc, see interface ClientConnectionManager
     public HttpParams getParams() {
         return this.params;
     }
 
-    /**
+
+    /* *
      * Assigns {@link HttpParams parameters} for this 
      * connection manager.
-     * 
-     * @see HttpConnectionManagerParams
-     */
+     * /
+    //@@@ this is basically a no-op unless we pass the params to the pool
     public void setParams(final HttpParams params) {
         if (params == null) {
             throw new IllegalArgumentException("Parameters may not be null");
         }
         this.params = params;
     }
-
-
-    //@@@ still needed?
-    static /*default*/ void closeConnection(final OperatedClientConnection conn) {
-        if (conn != null) {
-            try {
-                conn.close();
-            } catch (IOException ex) {
-                LOG.debug("I/O error closing connection", ex);
-            }
-        }
-    }
+    */
 
 
 } // class ThreadSafeClientConnManager



Mime
View raw message