hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r511479 - in /jakarta/httpcomponents/httpclient/trunk/src: examples/org/apache/http/examples/client/ java/org/apache/http/impl/conn/
Date Sun, 25 Feb 2007 10:56:39 GMT
Author: rolandw
Date: Sun Feb 25 02:56:38 2007
New Revision: 511479

URL: http://svn.apache.org/viewvc?view=rev&rev=511479
Log:
TSCCM uses pooled connection adapter

Modified:
    jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java
    jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPoolEntry.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java?view=diff&rev=511479&r1=511478&r2=511479
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java
Sun Feb 25 02:56:38 2007
@@ -55,7 +55,7 @@
 import org.apache.http.conn.SocketFactory;
 import org.apache.http.conn.PlainSocketFactory;
 import org.apache.http.conn.ClientConnectionManager;
-//import org.apache.http.impl.conn.SimpleClientConnManager;
+//import org.apache.http.impl.conn.SingleClientConnManager;
 import org.apache.http.impl.conn.ThreadSafeClientConnManager;
 import org.apache.http.client.HttpClient;
 import org.apache.http.impl.client.DefaultHttpClient;
@@ -138,7 +138,7 @@
 
         ClientConnectionManager ccm =
             new ThreadSafeClientConnManager(getParams(), supportedSchemes);
-        //  new SimpleClientConnManager(getParams(), supportedSchemes);
+        //  new SingleClientConnManager(getParams(), supportedSchemes);
 
         DefaultHttpClient dhc =
             new DefaultHttpClient(getParams(), ccm, supportedSchemes);

Modified: jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java?view=diff&rev=511479&r1=511478&r2=511479
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java
Sun Feb 25 02:56:38 2007
@@ -57,7 +57,7 @@
 import org.apache.http.conn.ssl.SSLSocketFactory;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.HttpRoute;
-//import org.apache.http.impl.conn.SimpleClientConnManager;
+//import org.apache.http.impl.conn.SingleClientConnManager;
 import org.apache.http.impl.conn.ThreadSafeClientConnManager;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.RoutedRequest;
@@ -150,7 +150,7 @@
 
         ClientConnectionManager ccm =
             new ThreadSafeClientConnManager(getParams(), supportedSchemes);
-        //  new SimpleClientConnManager(getParams(), supportedSchemes);
+        //  new SingleClientConnManager(getParams(), supportedSchemes);
 
         DefaultHttpClient dhc =
             new DefaultHttpClient(getParams(), ccm, supportedSchemes);

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPoolEntry.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPoolEntry.java?view=diff&rev=511479&r1=511478&r2=511479
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPoolEntry.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPoolEntry.java
Sun Feb 25 02:56:38 2007
@@ -46,7 +46,7 @@
 /**
  * A pool entry for use by connection manager implementations.
  * Pool entries work in conjunction with an
- * {@link AbstractClientConnectionAdapter adapter}.
+ * {@link AbstractClientConnAdapter adapter}.
  * The adapter is handed out to applications that obtain a connection.
  * The pool entry stores the underlying connection and tracks the
  * {@link HttpRoute route} established.
@@ -182,7 +182,7 @@
                 ("Connection is already tunnelled.");
         }
 
-        // LOG.debug
+        // LOG.debug?
 
         this.connection.update(null, tracker.getTargetHost(),
                                secure, params);

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java?view=diff&rev=511479&r1=511478&r2=511479
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java
Sun Feb 25 02:56:38 2007
@@ -42,7 +42,8 @@
 
 /**
  * Abstract adapter from pool {@link AbstractPoolEntry entries} to
- * {@link ManagedClientConnection managed} client connections.
+ * {@link org.apache.http.conn.ManagedClientConnection managed}
+ * client connections.
  * The connection in the pool entry is used to initialize the base class.
  * In addition, methods to establish a route are delegated to the
  * pool entry. {@link #shutdown shutdown} and {@link #close close}
@@ -69,18 +70,10 @@
      *
      * @param manager   the connection manager
      * @param entry     the pool entry for the connection being wrapped
-     * <!--
-     * @ param plan      the planned route, which will be used
-     *                  to update the pool entry
-     * -->
      */
     protected AbstractPooledConnAdapter(ClientConnectionManager manager,
-                                        AbstractPoolEntry entry
-                                        //, HttpRoute plan
-                                        ) {
+                                        AbstractPoolEntry entry) {
         super(manager, entry.connection);
-
-        //entry.plannedRoute = plan;
         this.poolEntry = entry;
     }
 

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java?view=diff&rev=511479&r1=511478&r2=511479
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java
Sun Feb 25 02:56:38 2007
@@ -349,7 +349,9 @@
                  "connection not obtained from this manager.");
         }
         HttpConnectionAdapter hca = (HttpConnectionAdapter) conn;
-        if ((hca.poolEntry != null) && (hca.poolEntry.manager != this)) {
+        if ((hca.poolEntry != null) &&
+            //@@@ (hca.poolEntry.manager != this) &&
+            (hca.connManager != this)) {
             throw new IllegalArgumentException
                 ("Connection not obtained from this manager.");
         }
@@ -366,11 +368,9 @@
                 // Consuming the response is handled outside in 4.0.
 
                 // make sure this connection will not be re-used
-                //@@@ Can we set some kind of flag before shutting down?
-                //@@@ If shutdown throws an exception, we can't be sure
-                //@@@ that the connection will consider itself closed.
-                // be nice and call close() rather than shutdown()?
-                // I'm not in a nice mood today. -rolandw-
+                // Shut down rather than close, we might have gotten here
+                // because of a shutdown trigger.
+                // Shutdown of the adapter also clears the tracked route.
                 hca.shutdown();
             }
         } catch (IOException iox) {
@@ -379,7 +379,7 @@
                 LOG.debug("Exception shutting down released connection.",
                           iox);
         } finally {
-            TrackingPoolEntry entry = hca.poolEntry;
+            TrackingPoolEntry entry = (TrackingPoolEntry) hca.poolEntry;
             hca.detach();
             releasePoolEntry(entry);
         }
@@ -1126,6 +1126,7 @@
         private TrackingPoolEntry(OperatedClientConnection occ) {
             super(occ);
             //@@@ pass planned route to the constructor?
+            //@@@ or update when the adapter is created?
             this.manager = ThreadSafeClientConnManager.this;
             this.reference = new WeakReference(this, REFERENCE_QUEUE);
         }
@@ -1145,12 +1146,7 @@
      * All connections given out by the manager are wrappers which
      * can be {@link #detach detach}ed to prevent further use on release.
      */
-    private class HttpConnectionAdapter
-        extends AbstractClientConnAdapter {
-
-        /** The wrapped pool entry. */
-        private TrackingPoolEntry poolEntry;
-
+    private class HttpConnectionAdapter extends AbstractPooledConnAdapter {
 
         /**
          * Creates a new adapter.
@@ -1158,106 +1154,10 @@
          * @param entry   the pool entry for the connection being wrapped
          */
         protected HttpConnectionAdapter(TrackingPoolEntry entry) {
-            super(ThreadSafeClientConnManager.this, entry.connection);
-            poolEntry = entry;
+            super(ThreadSafeClientConnManager.this, entry);
             super.markedReusable = true;
         }
-
-
-        /**
-         * Asserts that this adapter is still attached.
-         *
-         * @throws IllegalStateException
-         *      if it is {@link #detach detach}ed
-         */
-        protected final void assertAttached() {
-            if (poolEntry == null) {
-                throw new IllegalStateException("Adapter is detached.");
-            }
-        }
-
-        /**
-         * Checks if the wrapped connection is still available.
-         *
-         * @return <code>true</code> if still available,
-         *         <code>false</code> if {@link #detach detached}
-         */
-        protected boolean hasConnection() {
-            return wrappedConnection != null;
-        }
-
-        /**
-         * Detaches this adapter from the wrapped connection.
-         * This adapter becomes useless.
-         */
-        private void detach() {
-            this.wrappedConnection = null;
-            this.poolEntry = null;
-        }
-
-
-        // non-javadoc, see interface ManagedHttpConnection
-        public HttpRoute getRoute() {
-
-            assertAttached();
-            return (poolEntry.tracker == null) ?
-                null : poolEntry.tracker.toRoute();
-        }
-
-        // non-javadoc, see interface ManagedHttpConnection
-        public void open(HttpRoute route,
-                         HttpContext context, HttpParams params)
-            throws IOException {
-
-            assertAttached();
-            poolEntry.open(route, context, params);
-        }
-
-
-        // non-javadoc, see interface ManagedHttpConnection
-        public void tunnelCreated(boolean secure, HttpParams params)
-            throws IOException {
-
-            assertAttached();
-            poolEntry.tunnelCreated(secure, params);
-        }
-
-
-        // non-javadoc, see interface ManagedHttpConnection
-        public void layerProtocol(HttpContext context, HttpParams params)
-            throws IOException {
-
-            assertAttached();
-            poolEntry.layerProtocol(context, params);
-        }
-
-
-
-        // non-javadoc, see interface HttpConnection        
-        public void close() throws IOException {
-            if (poolEntry != null)
-                poolEntry.closing();
-
-            if (hasConnection()) {
-                wrappedConnection.close();
-            } else {
-                // do nothing
-            }
-        }
-
-        // non-javadoc, see interface HttpConnection        
-        public void shutdown() throws IOException {
-            if (poolEntry != null)
-                poolEntry.closing();
-
-            if (hasConnection()) {
-                wrappedConnection.shutdown();
-            } else {
-                // do nothing
-            }
-        }
-
-    } // class HttpConnectionAdapter
+    }
 
 } // class ThreadSafeClientConnManager
 



Mime
View raw message