You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/12/28 18:08:14 UTC

svn commit: r607289 - in /httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm: ConnPoolByRoute.java RouteSpecificPool.java WaitingThread.java

Author: rolandw
Date: Fri Dec 28 09:08:13 2007
New Revision: 607289

URL: http://svn.apache.org/viewvc?rev=607289&view=rev
Log:
HTTPCLIENT-677: switching to new WaitingThread class

Modified:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/WaitingThread.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=607289&r1=607288&r2=607289&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 Fri Dec 28 09:08:13 2007
@@ -91,31 +91,6 @@
 
 
     /**
-     * A thread and the pool in which it is waiting.
-     * <!-- @@@ will be revised for HTTPCLIENT-677 -->
-     */
-    protected static class WaitingThread {
-
-        /** The thread that is waiting for an entry. */
-        public Thread thread;
-
-        /** The route specific pool the thread is waiting for. */
-        public RouteSpecificPool pool;
-
-        /**
-         * Indicates the source of an interruption.
-         * Set to <code>true</code> inside
-         * {@link #notifyWaitingThread(RouteSpecificPool)}
-         * and {@link #shutdown shutdown()}
-         * before the thread is interrupted.
-         * If not set, the thread was interrupted from the outside.
-         */
-        public boolean interruptedByConnectionPool = false;
-    }
-
-
-
-    /**
      * Creates a new connection pool, managed by route.
      *
      * @param mgr   the connection manager
@@ -258,11 +233,12 @@
                         }
    
                         if (waitingThread == null) {
-                            waitingThread = new WaitingThread();
-                            waitingThread.pool = rospl;
-                            waitingThread.thread = Thread.currentThread();
+                            waitingThread = new WaitingThread
+                                (poolLock.newCondition(), rospl);
+                            //@@@waitingThread.pool = rospl;
+                            //@@@waitingThread.thread = Thread.currentThread();
                         } else {
-                            waitingThread.interruptedByConnectionPool = false;
+                            waitingThread.interruptedByConnectionPool = false;//@@@
                         }
 
                         if (useTimeout) {
@@ -271,7 +247,8 @@
 
                         rospl.queueThread(waitingThread);
                         waitingThreads.add(waitingThread);
-                        poolCondition.await(timeToWait, TimeUnit.MILLISECONDS);
+                        //@@@ poolCondition.await(timeToWait, TimeUnit.MILLISECONDS);
+                        waitingThread.await(timeToWait); //@@@, TimeUnit.MILLISECONDS);
 
                     } catch (InterruptedException e) {
                         if (!waitingThread.interruptedByConnectionPool) {
@@ -547,7 +524,7 @@
                     LOG.debug("Notifying thread waiting on any pool.");
                 }
                 waitingThread = waitingThreads.remove();
-                waitingThread.pool.removeThread(waitingThread);
+                waitingThread.getPool().removeThread(waitingThread);
 
             } else if (LOG.isDebugEnabled()) {
                 LOG.debug("Notifying no-one, there are no waiting threads");
@@ -555,7 +532,7 @@
 
             if (waitingThread != null) {
                 waitingThread.interruptedByConnectionPool = true;
-                waitingThread.thread.interrupt();
+                waitingThread.getThread().interrupt(); //@@@ HTTPCLIENT-677
             }
 
         } finally {
@@ -610,7 +587,7 @@
                 WaitingThread waiter = iwth.next();
                 iwth.remove();
                 waiter.interruptedByConnectionPool = true;
-                waiter.thread.interrupt();
+                waiter.getThread().interrupt(); //@@@ HTTPCLIENT-677
             }
 
             routeToPool.clear();

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java?rev=607289&r1=607288&r2=607289&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java Fri Dec 28 09:08:13 2007
@@ -53,7 +53,7 @@
     protected LinkedList<BasicPoolEntry> freeEntries;
 
     /** The list of threads waiting for this pool. */
-    protected Queue<ConnPoolByRoute.WaitingThread> waitingThreads;
+    protected Queue<WaitingThread> waitingThreads;
 
     /** The number of created entries. */
     protected int numEntries;
@@ -67,7 +67,7 @@
     public RouteSpecificPool(HttpRoute r) {
         this.route = r;
         this.freeEntries = new LinkedList<BasicPoolEntry>();
-        this.waitingThreads = new LinkedList<ConnPoolByRoute.WaitingThread>();
+        this.waitingThreads = new LinkedList<WaitingThread>();
         this.numEntries = 0;
     }
 
@@ -207,7 +207,7 @@
      *
      * @param wt        the waiting thread
      */
-    public void queueThread(ConnPoolByRoute.WaitingThread wt) {
+    public void queueThread(WaitingThread wt) {
         if (wt == null) {
             throw new IllegalArgumentException
                 ("Waiting thread must not be null.");
@@ -232,7 +232,7 @@
      *
      * @return  a waiting thread, or <code>null</code> if there is none
      */
-    public ConnPoolByRoute.WaitingThread dequeueThread() {
+    public WaitingThread dequeueThread() {
         return this.waitingThreads.poll();
     }
 
@@ -242,7 +242,7 @@
      *
      * @param wt        the waiting thread
      */
-    public void removeThread(ConnPoolByRoute.WaitingThread wt) {
+    public void removeThread(WaitingThread wt) {
         if (wt == null)
             return;
 

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/WaitingThread.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/WaitingThread.java?rev=607289&r1=607288&r2=607289&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/WaitingThread.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/WaitingThread.java Fri Dec 28 09:08:13 2007
@@ -68,7 +68,8 @@
      * before the thread is interrupted.
      * If not set, the thread was interrupted from the outside.
      */
-    private boolean interruptedByConnectionPool;
+    //@@@ to be removed in HTTPCLIENT-677
+    /*default@@@*/ boolean interruptedByConnectionPool;
 
 
     /**
@@ -100,10 +101,11 @@
      *
      * @see #wakeup
      */
-    public void await(int timeout)
+    public void await(long timeout)
         throws InterruptedException {
 
         //@@@ check timeout for negative, or assume overflow?
+        //@@@ for now, leave the check to the condition
 
         // This is only a sanity check. We cannot not synchronize here,
         // the lock would not be released on calling cond.await() below.
@@ -117,8 +119,6 @@
         this.waiter = Thread.currentThread();
 
         try {
-            //@@@ how to convert the int timeout to the long argument?
-            //@@@ (timeout & 0xffffffffL)? or check for negative above?
             this.cond.await(timeout, TimeUnit.MILLISECONDS);
         } finally {
             this.waiter = null;