hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r618019 - in /httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm: AbstractConnPool.java ThreadSafeClientConnManager.java
Date Sun, 03 Feb 2008 17:02:33 GMT
Author: rolandw
Date: Sun Feb  3 09:02:31 2008
New Revision: 618019

URL: http://svn.apache.org/viewvc?rev=618019&view=rev
Log:
HTTPCLIENT-740: start connection GC thread in extra call after construction

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

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java?rev=618019&r1=618018&r2=618019&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
Sun Feb  3 09:02:31 2008
@@ -150,17 +150,44 @@
         boolean fair = false; //@@@ check parameters to decide
         poolLock = new ReentrantLock(fair);
 
-        boolean conngc = true; //@@@ check parameters to decide
-        if (conngc) {
-            refQueue = new ReferenceQueue<Object>();
-            refWorker = new RefQueueWorker(refQueue, this);
-            Thread t = new Thread(refWorker); //@@@ use a thread factory
-            t.setDaemon(true);
-            t.setName("RefQueueWorker@" + this);
-            t.start();
+        connManager = new ConnMgrRef(mgr, null);
+    }
+
+
+    /**
+     * Enables connection garbage collection (GC).
+     * This method must be called immediately after creating the
+     * connection pool. It is not possible to enable connection GC
+     * after pool entries have been created. Neither is it possible
+     * to disable connection GC.
+     *
+     * @throws IllegalStateException
+     *         if connection GC is already enabled, or if it cannot be
+     *         enabled because there already are pool entries
+     */
+    public void enableConnectionGC()
+        throws IllegalStateException {
+
+        if (refQueue != null) {
+            throw new IllegalStateException("Connection GC already enabled.");
         }
+        try {
+            poolLock.lock();
+            if (numConnections > 0) { //@@@ is this check sufficient?
+                throw new IllegalStateException("Pool already in use.");
+            }
+        } finally {
+            poolLock.unlock();
+        }
+
+        refQueue  = new ReferenceQueue<Object>();
+        refWorker = new RefQueueWorker(refQueue, this);
+        Thread t = new Thread(refWorker); //@@@ use a thread factory
+        t.setDaemon(true);
+        t.setName("RefQueueWorker@" + this);
+        t.start();
 
-        connManager = new ConnMgrRef(mgr, refQueue);
+        connManager = new ConnMgrRef(connManager.get(), refQueue);
     }
 
 

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java?rev=618019&r1=618018&r2=618019&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
Sun Feb  3 09:02:31 2008
@@ -112,7 +112,12 @@
      */
     protected AbstractConnPool createConnectionPool() {
 
-        return new ConnPoolByRoute(this);
+        AbstractConnPool acp = new ConnPoolByRoute(this);
+        boolean conngc = true; //@@@ check parameters to decide
+        if (conngc) {
+            acp.enableConnectionGC();
+        }
+        return acp;
     }
 
 



Mime
View raw message