hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1544185 - in /httpcomponents/httpcore/trunk: ./ httpcore-nio/src/main/java/org/apache/http/nio/pool/ httpcore/src/main/java/org/apache/http/pool/
Date Thu, 21 Nov 2013 13:59:56 GMT
Author: olegk
Date: Thu Nov 21 13:59:56 2013
New Revision: 1544185

URL: http://svn.apache.org/r1544185
Log:
HTTPCORE-362: Purge pool per route map after closing out expired or idle connections

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1544185&r1=1544184&r2=1544185&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Thu Nov 21 13:59:56 2013
@@ -1,6 +1,10 @@
 Changes since 4.3
 -------------------
 
+* [HTTPCORE-362] Purge pool per route map after closing out expired or idle connections with

+  #closeExpired and #closeIdle methods. 
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCORE-361] Reduced intermediate garbage in HeaderGroup#getFirstHeader()
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java?rev=1544185&r1=1544184&r2=1544185&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
Thu Nov 21 13:59:56 2013
@@ -675,6 +675,7 @@ public abstract class AbstractNIOConnPoo
         }
     }
 
+    //TODO: this method should be private
     protected void enumEntries(final Iterator<E> it, final PoolEntryCallback<T,
C> callback) {
         while (it.hasNext()) {
             final E entry = it.next();
@@ -688,6 +689,17 @@ public abstract class AbstractNIOConnPoo
         processPendingRequests();
     }
 
+    private void purgePoolMap() {
+        final Iterator<Map.Entry<T, RouteSpecificPool<T, C, E>>> it = this.routeToPool.entrySet().iterator();
+        while (it.hasNext()) {
+            final Map.Entry<T, RouteSpecificPool<T, C, E>> entry = it.next();
+            final RouteSpecificPool<T, C, E> pool = entry.getValue();
+            if (pool.getAllocatedCount() == 0) {
+                it.remove();
+            }
+        }
+    }
+
     public void closeIdle(final long idletime, final TimeUnit tunit) {
         Args.notNull(tunit, "Time unit");
         long time = tunit.toMillis(idletime);
@@ -704,6 +716,7 @@ public abstract class AbstractNIOConnPoo
             }
 
         });
+        purgePoolMap();
     }
 
     public void closeExpired() {
@@ -717,6 +730,7 @@ public abstract class AbstractNIOConnPoo
             }
 
         });
+        purgePoolMap();
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java?rev=1544185&r1=1544184&r2=1544185&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
Thu Nov 21 13:59:56 2013
@@ -57,6 +57,10 @@ abstract class RouteSpecificPool<T, C, E
         this.pending = new HashMap<SessionRequest, BasicFuture<E>>();
     }
 
+    public T getRoute() {
+        return this.route;
+    }
+
     protected abstract E createEntry(T route, C conn);
 
     public int getLeasedCount() {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java?rev=1544185&r1=1544184&r2=1544185&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
Thu Nov 21 13:59:56 2013
@@ -300,18 +300,6 @@ public abstract class AbstractConnPool<T
         }
     }
 
-    private void notifyPending(final RouteSpecificPool<T, C, E> pool) {
-        PoolEntryFuture<E> future = pool.nextPending();
-        if (future != null) {
-            this.pending.remove(future);
-        } else {
-            future = this.pending.poll();
-        }
-        if (future != null) {
-            future.wakeup();
-        }
-    }
-
     public void release(final E entry, final boolean reusable) {
         this.lock.lock();
         try {
@@ -324,7 +312,15 @@ public abstract class AbstractConnPool<T
                 } else {
                     entry.close();
                 }
-                notifyPending(pool);
+                PoolEntryFuture<E> future = pool.nextPending();
+                if (future != null) {
+                    this.pending.remove(future);
+                } else {
+                    future = this.pending.poll();
+                }
+                if (future != null) {
+                    future.wakeup();
+                }
             }
         } finally {
             this.lock.unlock();
@@ -467,6 +463,17 @@ public abstract class AbstractConnPool<T
         }
     }
 
+    private void purgePoolMap() {
+        final Iterator<Map.Entry<T, RouteSpecificPool<T, C, E>>> it = this.routeToPool.entrySet().iterator();
+        while (it.hasNext()) {
+            final Map.Entry<T, RouteSpecificPool<T, C, E>> entry = it.next();
+            final RouteSpecificPool<T, C, E> pool = entry.getValue();
+            if (pool.getPendingCount() + pool.getAllocatedCount() == 0) {
+                it.remove();
+            }
+        }
+    }
+
     /**
      * Closes connections that have been idle longer than the given period
      * of time and evicts them from the pool.
@@ -490,6 +497,7 @@ public abstract class AbstractConnPool<T
             }
 
         });
+        purgePoolMap();
     }
 
     /**
@@ -506,6 +514,7 @@ public abstract class AbstractConnPool<T
             }
 
         });
+        purgePoolMap();
     }
 
     @Override



Mime
View raw message