hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1151821 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/nio/pool/ httpcore-nio/src/test/java/org/apache/http/nio/pool/ httpcore/src/main/java/org/apache/http/pool/ httpcore/src/test/java/org/apache/http/pool/
Date Thu, 28 Jul 2011 12:41:17 GMT
Author: olegk
Date: Thu Jul 28 12:41:14 2011
New Revision: 1151821

URL: http://svn.apache.org/viewvc?rev=1151821&view=rev
Log:
Migrated non-blocking connection pooling code from HttpAsyncClient to HttpCore

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/
      - copied from r1151803, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/pool/
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/
      - copied from r1151803, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/pool/
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
      - copied, changed from r1151814, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/pool/TestPoolEntry.java
Removed:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/PoolEntry.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/BasicPoolEntryCallback.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestPoolEntry.java
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/PoolEntryCallback.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestSessionPool.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java?rev=1151821&r1=1151803&r2=1151821&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
Thu Jul 28 12:41:14 2011
@@ -24,20 +24,23 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.nio.pool;
+package org.apache.http.nio.pool;
 
-class LeaseRequest<T, E extends PoolEntry<T>> {
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.pool.PoolEntry;
+
+class LeaseRequest<T, E extends PoolEntry<T, IOSession>> {
 
     private final T route;
     private final Object state;
     private final int connectTimeout;
-    private final PoolEntryCallback<T, E> callback;
+    private final PoolEntryCallback<E> callback;
 
     public LeaseRequest(
             final T route,
             final Object state,
             final int connectTimeout,
-            final PoolEntryCallback<T, E> callback) {
+            final PoolEntryCallback<E> callback) {
         super();
         this.route = route;
         this.state = state;
@@ -53,7 +56,7 @@ class LeaseRequest<T, E extends PoolEntr
         return this.state;
     }
 
-    public PoolEntryCallback<T, E> getCallback() {
+    public PoolEntryCallback<E> getCallback() {
         return this.callback;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/PoolEntryCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/PoolEntryCallback.java?rev=1151821&r1=1151803&r2=1151821&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/PoolEntryCallback.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/PoolEntryCallback.java
Thu Jul 28 12:41:14 2011
@@ -24,9 +24,9 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.nio.pool;
+package org.apache.http.nio.pool;
 
-public interface PoolEntryCallback<T, E extends PoolEntry<T>> {
+public interface PoolEntryCallback<E> {
 
     void completed(E entry);
 

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=1151821&r1=1151803&r2=1151821&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 Jul 28 12:41:14 2011
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.nio.pool;
+package org.apache.http.nio.pool;
 
 import java.net.SocketTimeoutException;
 import java.util.HashMap;
@@ -36,20 +36,21 @@ import java.util.Set;
 
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.SessionRequest;
+import org.apache.http.pool.PoolEntry;
 
-abstract class RouteSpecificPool<T, E extends PoolEntry<T>> {
+abstract class RouteSpecificPool<T, E extends PoolEntry<T, IOSession>> {
 
     private final T route;
     private final Set<E> leasedSessions;
     private final LinkedList<E> availableSessions;
-    private final Map<SessionRequest, PoolEntryCallback<T, E>> pendingSessions;
+    private final Map<SessionRequest, PoolEntryCallback<E>> pendingSessions;
 
     RouteSpecificPool(final T route) {
         super();
         this.route = route;
         this.leasedSessions = new HashSet<E>();
         this.availableSessions = new LinkedList<E>();
-        this.pendingSessions = new HashMap<SessionRequest, PoolEntryCallback<T, E>>();
+        this.pendingSessions = new HashMap<SessionRequest, PoolEntryCallback<E>>();
     }
 
     protected abstract E createEntry(T route, IOSession session);
@@ -124,12 +125,12 @@ abstract class RouteSpecificPool<T, E ex
 
     public void addPending(
             final SessionRequest sessionRequest,
-            final PoolEntryCallback<T, E> callback) {
+            final PoolEntryCallback<E> callback) {
         this.pendingSessions.put(sessionRequest, callback);
     }
 
-    private PoolEntryCallback<T, E> removeRequest(final SessionRequest request) {
-        PoolEntryCallback<T, E> callback = this.pendingSessions.remove(request);
+    private PoolEntryCallback<E> removeRequest(final SessionRequest request) {
+        PoolEntryCallback<E> callback = this.pendingSessions.remove(request);
         if (callback == null) {
             throw new IllegalStateException("Invalid session request");
         }
@@ -137,7 +138,7 @@ abstract class RouteSpecificPool<T, E ex
     }
 
     public E completed(final SessionRequest request) {
-        PoolEntryCallback<T, E> callback = removeRequest(request);
+        PoolEntryCallback<E> callback = removeRequest(request);
         IOSession iosession = request.getSession();
         E entry = createEntry(this.route, iosession);
         this.leasedSessions.add(entry);
@@ -146,17 +147,17 @@ abstract class RouteSpecificPool<T, E ex
     }
 
     public void cancelled(final SessionRequest request) {
-        PoolEntryCallback<T, E> callback = removeRequest(request);
+        PoolEntryCallback<E> callback = removeRequest(request);
         callback.cancelled();
     }
 
     public void failed(final SessionRequest request) {
-        PoolEntryCallback<T, E> callback = removeRequest(request);
+        PoolEntryCallback<E> callback = removeRequest(request);
         callback.failed(request.getException());
     }
 
     public void timeout(final SessionRequest request) {
-        PoolEntryCallback<T, E> callback = removeRequest(request);
+        PoolEntryCallback<E> callback = removeRequest(request);
         callback.failed(new SocketTimeoutException());
     }
 
@@ -166,11 +167,11 @@ abstract class RouteSpecificPool<T, E ex
         }
         this.pendingSessions.clear();
         for (E entry: this.availableSessions) {
-            entry.getIOSession().close();
+            entry.getConnection().close();
         }
         this.availableSessions.clear();
         for (E entry: this.leasedSessions) {
-            entry.getIOSession().close();
+            entry.getConnection().close();
         }
         this.leasedSessions.clear();
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java?rev=1151821&r1=1151803&r2=1151821&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java
Thu Jul 28 12:41:14 2011
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.nio.pool;
+package org.apache.http.nio.pool;
 
 import java.io.IOException;
 import java.net.SocketAddress;
@@ -39,13 +39,14 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
-import org.apache.http.nio.conn.PoolStats;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.nio.reactor.SessionRequestCallback;
+import org.apache.http.pool.PoolEntry;
+import org.apache.http.pool.PoolStats;
 
-public abstract class SessionPool<T, E extends PoolEntry<T>> {
+public abstract class SessionPool<T, E extends PoolEntry<T, IOSession>> {
 
     private final ConnectingIOReactor ioreactor;
     private final SessionRequestCallback sessionRequestCallback;
@@ -149,7 +150,7 @@ public abstract class SessionPool<T, E e
     public void lease(
             final T route, final Object state,
             final long connectTimeout, final TimeUnit tunit,
-            final PoolEntryCallback<T, E> callback) {
+            final PoolEntryCallback<E> callback) {
         if (route == null) {
             throw new IllegalArgumentException("Route may not be null");
         }
@@ -206,7 +207,7 @@ public abstract class SessionPool<T, E e
             T route = request.getRoute();
             Object state = request.getState();
             int timeout = request.getConnectTimeout();
-            PoolEntryCallback<T, E> callback = request.getCallback();
+            PoolEntryCallback<E> callback = request.getCallback();
 
             RouteSpecificPool<T, E> pool = getPool(request.getRoute());
             E entry = null;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java?rev=1151821&r1=1151803&r2=1151821&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
Thu Jul 28 12:41:14 2011
@@ -24,30 +24,82 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.nio.pool;
+package org.apache.http.nio.pool;
 
 import java.io.IOException;
 import java.net.SocketTimeoutException;
-import java.util.concurrent.TimeUnit;
 
 import junit.framework.Assert;
 
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.SessionRequest;
+import org.apache.http.pool.PoolEntry;
 import org.junit.Test;
 import org.mockito.Mockito;
 
 public class TestRouteSpecificPool {
 
-    static class LocalRoutePool extends RouteSpecificPool<String, PoolEntry<String>>
{
+    static class LocalPoolEntry extends PoolEntry<String, IOSession> {
+
+        public LocalPoolEntry(final String route, final IOSession conn) {
+            super(route, conn);
+        }
+
+    }
+    
+    static class BasicPoolEntryCallback implements PoolEntryCallback<LocalPoolEntry>
{
+
+        private LocalPoolEntry entry;
+        private Exception ex;
+        private boolean completed;
+        private boolean failed;
+        private boolean cancelled;
+
+        public void completed(final LocalPoolEntry entry) {
+            this.entry = entry;
+            this.completed = true;
+        }
+
+        public LocalPoolEntry getEntry() {
+            return this.entry;
+        }
+
+        public Exception getException() {
+            return this.ex;
+        }
+
+        public void failed(final Exception ex) {
+            this.ex = ex;
+            this.failed = true;
+        }
+
+        public void cancelled() {
+            this.cancelled = true;
+        }
+
+        public boolean isCompleted() {
+            return this.completed;
+        }
+
+        public boolean isFailed() {
+            return this.failed;
+        }
+
+        public boolean isCancelled() {
+            return this.cancelled;
+        }
+
+    }    
+
+    static class LocalRoutePool extends RouteSpecificPool<String, LocalPoolEntry> {
 
         public LocalRoutePool() {
             super("whatever");
         }
 
         @Override
-        protected PoolEntry<String> createEntry(String route, IOSession session) {
-            return new PoolEntry<String>(route, session, 0L, TimeUnit.MILLISECONDS);
+        protected LocalPoolEntry createEntry(String route, IOSession session) {
+            return new LocalPoolEntry(route, session);
         }
 
     };
@@ -74,9 +126,9 @@ public class TestRouteSpecificPool {
         Assert.assertEquals(0, pool.getAvailableCount());
         Assert.assertEquals(0, pool.getLeasedCount());
         Assert.assertEquals(1, pool.getPendingCount());
-        PoolEntry<String> entry = pool.completed(sessionRequest);
+        LocalPoolEntry entry = pool.completed(sessionRequest);
         Assert.assertNotNull(entry);
-        Assert.assertSame(session, entry.getIOSession());
+        Assert.assertSame(session, entry.getConnection());
         Assert.assertTrue(callback.isCompleted());
         Assert.assertFalse(callback.isFailed());
         Assert.assertFalse(callback.isCancelled());
@@ -174,11 +226,11 @@ public class TestRouteSpecificPool {
         Assert.assertEquals(0, pool.getLeasedCount());
         Assert.assertEquals(3, pool.getPendingCount());
 
-        PoolEntry<String> entry1 = pool.completed(sessionRequest1);
+        LocalPoolEntry entry1 = pool.completed(sessionRequest1);
         Assert.assertNotNull(entry1);
-        PoolEntry<String> entry2 = pool.completed(sessionRequest2);
+        LocalPoolEntry entry2 = pool.completed(sessionRequest2);
         Assert.assertNotNull(entry2);
-        PoolEntry<String> entry3 = pool.completed(sessionRequest3);
+        LocalPoolEntry entry3 = pool.completed(sessionRequest3);
         Assert.assertNotNull(entry3);
 
         Assert.assertEquals(3, pool.getAllocatedCount());
@@ -221,11 +273,11 @@ public class TestRouteSpecificPool {
         Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
         pool.addPending(sessionRequest3, new BasicPoolEntryCallback());
 
-        PoolEntry<String> entry1 = pool.completed(sessionRequest1);
+        LocalPoolEntry entry1 = pool.completed(sessionRequest1);
         Assert.assertNotNull(entry1);
-        PoolEntry<String> entry2 = pool.completed(sessionRequest2);
+        LocalPoolEntry entry2 = pool.completed(sessionRequest2);
         Assert.assertNotNull(entry2);
-        PoolEntry<String> entry3 = pool.completed(sessionRequest3);
+        LocalPoolEntry entry3 = pool.completed(sessionRequest3);
         Assert.assertNotNull(entry3);
 
         entry2.setState(Boolean.FALSE);
@@ -257,7 +309,7 @@ public class TestRouteSpecificPool {
     public void testReleaseInvalidEntry() throws Exception {
         LocalRoutePool pool = new LocalRoutePool();
         IOSession session = Mockito.mock(IOSession.class);
-        PoolEntry<String> entry = new PoolEntry<String>("whatever", session,
0L, TimeUnit.MILLISECONDS);
+        LocalPoolEntry entry = new LocalPoolEntry("whatever", session);
         pool.freeEntry(entry, true);
     }
 
@@ -282,11 +334,11 @@ public class TestRouteSpecificPool {
         Assert.assertEquals(0, pool.getLeasedCount());
         Assert.assertEquals(3, pool.getPendingCount());
 
-        PoolEntry<String> entry1 = pool.completed(sessionRequest1);
+        LocalPoolEntry entry1 = pool.completed(sessionRequest1);
         Assert.assertNotNull(entry1);
-        PoolEntry<String> entry2 = pool.completed(sessionRequest2);
+        LocalPoolEntry entry2 = pool.completed(sessionRequest2);
         Assert.assertNotNull(entry2);
-        PoolEntry<String> entry3 = pool.completed(sessionRequest3);
+        LocalPoolEntry entry3 = pool.completed(sessionRequest3);
         Assert.assertNotNull(entry3);
 
         Assert.assertEquals(3, pool.getAllocatedCount());
@@ -347,9 +399,9 @@ public class TestRouteSpecificPool {
         Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
         pool.addPending(sessionRequest3, new BasicPoolEntryCallback());
 
-        PoolEntry<String> entry1 = pool.completed(sessionRequest1);
+        LocalPoolEntry entry1 = pool.completed(sessionRequest1);
         Assert.assertNotNull(entry1);
-        PoolEntry<String> entry2 = pool.completed(sessionRequest2);
+        LocalPoolEntry entry2 = pool.completed(sessionRequest2);
         Assert.assertNotNull(entry2);
 
         pool.freeEntry(entry1, true);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestSessionPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestSessionPool.java?rev=1151821&r1=1151803&r2=1151821&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestSessionPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestSessionPool.java
Thu Jul 28 12:41:14 2011
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.nio.pool;
+package org.apache.http.nio.pool;
 
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
@@ -33,17 +33,70 @@ import java.util.concurrent.TimeUnit;
 
 import junit.framework.Assert;
 
-import org.apache.http.nio.conn.PoolStats;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.nio.reactor.SessionRequestCallback;
+import org.apache.http.pool.PoolEntry;
+import org.apache.http.pool.PoolStats;
 import org.junit.Test;
 import org.mockito.Mockito;
 
 public class TestSessionPool {
 
-    static class LocalSessionPool extends SessionPool<String, PoolEntry<String>>
{
+    static class LocalPoolEntry extends PoolEntry<String, IOSession> {
+
+        public LocalPoolEntry(final String route, final IOSession conn) {
+            super(route, conn);
+        }
+
+    }
+    
+    static class BasicPoolEntryCallback implements PoolEntryCallback<LocalPoolEntry>
{
+
+        private LocalPoolEntry entry;
+        private Exception ex;
+        private boolean completed;
+        private boolean failed;
+        private boolean cancelled;
+
+        public void completed(final LocalPoolEntry entry) {
+            this.entry = entry;
+            this.completed = true;
+        }
+
+        public LocalPoolEntry getEntry() {
+            return this.entry;
+        }
+
+        public Exception getException() {
+            return this.ex;
+        }
+
+        public void failed(final Exception ex) {
+            this.ex = ex;
+            this.failed = true;
+        }
+
+        public void cancelled() {
+            this.cancelled = true;
+        }
+
+        public boolean isCompleted() {
+            return this.completed;
+        }
+
+        public boolean isFailed() {
+            return this.failed;
+        }
+
+        public boolean isCancelled() {
+            return this.cancelled;
+        }
+
+    }    
+
+    static class LocalSessionPool extends SessionPool<String, LocalPoolEntry> {
 
         public LocalSessionPool(
                 final ConnectingIOReactor ioreactor, int defaultMaxPerRoute, int maxTotal)
{
@@ -61,13 +114,13 @@ public class TestSessionPool {
         }
 
         @Override
-        protected PoolEntry<String> createEntry(final String route, final IOSession
session) {
-            return new PoolEntry<String>(route, session, 0L, TimeUnit.MILLISECONDS);
+        protected LocalPoolEntry createEntry(final String route, final IOSession session)
{
+            return new LocalPoolEntry(route, session);
         }
 
         @Override
-        protected void closeEntry(final PoolEntry<String> entry) {
-            IOSession session = entry.getIOSession();
+        protected void closeEntry(final LocalPoolEntry entry) {
+            IOSession session = entry.getConnection();
             session.close();
         }
 
@@ -92,8 +145,8 @@ public class TestSessionPool {
 
     @Test
     public void testInternalLeaseRequest() throws Exception {
-        LeaseRequest<String, PoolEntry<String>> leaseRequest =
-            new LeaseRequest<String, PoolEntry<String>>("somehost", null, 0,
+        LeaseRequest<String, LocalPoolEntry> leaseRequest =
+            new LeaseRequest<String, LocalPoolEntry>("somehost", null, 0,
                     new BasicPoolEntryCallback());
         Assert.assertEquals("[somehost][null]", leaseRequest.toString());
     }
@@ -283,11 +336,11 @@ public class TestSessionPool {
         pool.lease("otherhost", null, -1, TimeUnit.MILLISECONDS, callback3);
         pool.requestCompleted(sessionRequest2);
 
-        PoolEntry<String> entry1 = callback1.getEntry();
+        LocalPoolEntry entry1 = callback1.getEntry();
         Assert.assertNotNull(entry1);
-        PoolEntry<String> entry2 = callback2.getEntry();
+        LocalPoolEntry entry2 = callback2.getEntry();
         Assert.assertNotNull(entry2);
-        PoolEntry<String> entry3 = callback3.getEntry();
+        LocalPoolEntry entry3 = callback3.getEntry();
         Assert.assertNotNull(entry3);
 
         pool.release(entry1, true);
@@ -327,8 +380,7 @@ public class TestSessionPool {
     public void testReleaseUnknownEntry() throws Exception {
         ConnectingIOReactor ioreactor = Mockito.mock(ConnectingIOReactor.class);
         LocalSessionPool pool = new LocalSessionPool(ioreactor, 2, 2);
-        pool.release(new PoolEntry<String>(
-                "somehost", Mockito.mock(IOSession.class), 1000, TimeUnit.SECONDS), true);
+        pool.release(new LocalPoolEntry("somehost", Mockito.mock(IOSession.class)), true);
     }
 
     @Test
@@ -370,11 +422,11 @@ public class TestSessionPool {
         pool.lease("otherhost", null, -1, TimeUnit.MILLISECONDS, callback3);
         pool.requestCompleted(sessionRequest2);
 
-        PoolEntry<String> entry1 = callback1.getEntry();
+        LocalPoolEntry entry1 = callback1.getEntry();
         Assert.assertNotNull(entry1);
-        PoolEntry<String> entry2 = callback2.getEntry();
+        LocalPoolEntry entry2 = callback2.getEntry();
         Assert.assertNotNull(entry2);
-        PoolEntry<String> entry3 = callback3.getEntry();
+        LocalPoolEntry entry3 = callback3.getEntry();
         Assert.assertNotNull(entry3);
 
         pool.release(entry1, true);
@@ -400,13 +452,13 @@ public class TestSessionPool {
         pool.lease("otherhost", null, -1, TimeUnit.MILLISECONDS, callback9);
 
         Assert.assertTrue(callback4.isCompleted());
-        PoolEntry<String> entry4 = callback4.getEntry();
+        LocalPoolEntry entry4 = callback4.getEntry();
         Assert.assertNotNull(entry4);
         Assert.assertTrue(callback5.isCompleted());
-        PoolEntry<String> entry5 = callback5.getEntry();
+        LocalPoolEntry entry5 = callback5.getEntry();
         Assert.assertNotNull(entry5);
         Assert.assertTrue(callback6.isCompleted());
-        PoolEntry<String> entry6 = callback6.getEntry();
+        LocalPoolEntry entry6 = callback6.getEntry();
         Assert.assertNotNull(entry6);
         Assert.assertFalse(callback7.isCompleted());
         Assert.assertFalse(callback8.isCompleted());
@@ -491,10 +543,10 @@ public class TestSessionPool {
         pool.requestCompleted(sessionRequest2);
 
         Assert.assertTrue(callback1.isCompleted());
-        PoolEntry<String> entry1 = callback1.getEntry();
+        LocalPoolEntry entry1 = callback1.getEntry();
         Assert.assertNotNull(entry1);
         Assert.assertTrue(callback2.isCompleted());
-        PoolEntry<String> entry2 = callback2.getEntry();
+        LocalPoolEntry entry2 = callback2.getEntry();
         Assert.assertNotNull(entry2);
 
         Assert.assertFalse(callback3.isCompleted());
@@ -522,10 +574,10 @@ public class TestSessionPool {
         pool.requestCompleted(sessionRequest4);
 
         Assert.assertTrue(callback3.isCompleted());
-        PoolEntry<String> entry3 = callback3.getEntry();
+        LocalPoolEntry entry3 = callback3.getEntry();
         Assert.assertNotNull(entry3);
         Assert.assertTrue(callback4.isCompleted());
-        PoolEntry<String> entry4 = callback4.getEntry();
+        LocalPoolEntry entry4 = callback4.getEntry();
         Assert.assertNotNull(entry4);
 
         totals = pool.getTotalStats();
@@ -564,10 +616,10 @@ public class TestSessionPool {
         pool.requestCompleted(sessionRequest1);
 
         Assert.assertTrue(callback5.isCompleted());
-        PoolEntry<String> entry5 = callback5.getEntry();
+        LocalPoolEntry entry5 = callback5.getEntry();
         Assert.assertNotNull(entry5);
         Assert.assertTrue(callback6.isCompleted());
-        PoolEntry<String> entry6 = callback6.getEntry();
+        LocalPoolEntry entry6 = callback6.getEntry();
         Assert.assertNotNull(entry6);
 
         totals = pool.getTotalStats();
@@ -621,7 +673,7 @@ public class TestSessionPool {
         pool.requestCompleted(sessionRequest1);
 
         Assert.assertTrue(callback1.isCompleted());
-        PoolEntry<String> entry1 = callback1.getEntry();
+        LocalPoolEntry entry1 = callback1.getEntry();
         Assert.assertNotNull(entry1);
 
         entry1.updateExpiry(1, TimeUnit.MILLISECONDS);
@@ -679,10 +731,10 @@ public class TestSessionPool {
         pool.requestCompleted(sessionRequest2);
 
         Assert.assertTrue(callback1.isCompleted());
-        PoolEntry<String> entry1 = callback1.getEntry();
+        LocalPoolEntry entry1 = callback1.getEntry();
         Assert.assertNotNull(entry1);
         Assert.assertTrue(callback2.isCompleted());
-        PoolEntry<String> entry2 = callback2.getEntry();
+        LocalPoolEntry entry2 = callback2.getEntry();
         Assert.assertNotNull(entry2);
 
         entry1.updateExpiry(1, TimeUnit.MILLISECONDS);
@@ -737,10 +789,10 @@ public class TestSessionPool {
         pool.requestCompleted(sessionRequest2);
 
         Assert.assertTrue(callback1.isCompleted());
-        PoolEntry<String> entry1 = callback1.getEntry();
+        LocalPoolEntry entry1 = callback1.getEntry();
         Assert.assertNotNull(entry1);
         Assert.assertTrue(callback2.isCompleted());
-        PoolEntry<String> entry2 = callback2.getEntry();
+        LocalPoolEntry entry2 = callback2.getEntry();
         Assert.assertNotNull(entry2);
 
         entry1.updateExpiry(0, TimeUnit.MILLISECONDS);
@@ -833,8 +885,7 @@ public class TestSessionPool {
         } catch (IllegalStateException expected) {
         }
         // Ignored if shut down
-        pool.release(new PoolEntry<String>(
-                "somehost", Mockito.mock(IOSession.class), 1000, TimeUnit.SECONDS), true);
+        pool.release(new LocalPoolEntry("somehost", Mockito.mock(IOSession.class)), true);
         pool.requestCompleted(Mockito.mock(SessionRequest.class));
         pool.requestFailed(Mockito.mock(SessionRequest.class));
         pool.requestCancelled(Mockito.mock(SessionRequest.class));

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java?rev=1151821&r1=1151820&r2=1151821&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
Thu Jul 28 12:41:14 2011
@@ -71,11 +71,11 @@ public class PoolEntry<T, C> {
         this(route, conn, 0, TimeUnit.MILLISECONDS);
     }
 
-    protected T getRoute() {
+    public T getRoute() {
         return this.route;
     }
 
-    protected C getConnection() {
+    public C getConnection() {
         return this.conn;
     }
 
@@ -87,11 +87,11 @@ public class PoolEntry<T, C> {
         return this.validUnit;
     }
 
-    protected Object getState() {
+    public Object getState() {
         return this.state;
     }
 
-    protected void setState(final Object state) {
+    public void setState(final Object state) {
         this.state = state;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java?rev=1151821&r1=1151820&r2=1151821&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java
Thu Jul 28 12:41:14 2011
@@ -97,12 +97,10 @@ public class TestConnPool {
         PoolStats totals = pool.getTotalStats();
         Assert.assertEquals(0, totals.getAvailable());
         Assert.assertEquals(0, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
         Assert.assertEquals(10, totals.getMax());
         PoolStats stats = pool.getStats("somehost");
         Assert.assertEquals(0, stats.getAvailable());
         Assert.assertEquals(0, stats.getLeased());
-        Assert.assertEquals(0, stats.getPending());
         Assert.assertEquals(3, stats.getMax());
         Assert.assertEquals("[leased: []][available: []][pending: []]", pool.toString());
     }
@@ -145,7 +143,6 @@ public class TestConnPool {
         PoolStats totals = pool.getTotalStats();
         Assert.assertEquals(0, totals.getAvailable());
         Assert.assertEquals(3, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
 
         LocalPoolEntry entry = future1.get();
         Assert.assertSame(entry1, entry);
@@ -159,8 +156,6 @@ public class TestConnPool {
         totals = pool.getTotalStats();
         Assert.assertEquals(2, totals.getAvailable());
         Assert.assertEquals(0, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
-
     }
 
     @Test
@@ -270,7 +265,6 @@ public class TestConnPool {
         PoolStats totals = pool.getTotalStats();
         Assert.assertEquals(3, totals.getAvailable());
         Assert.assertEquals(0, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
 
         Future<LocalPoolEntry> future4 = pool.lease("somehost", null);
         GetPoolEntryThread t4 = new GetPoolEntryThread(future4);
@@ -375,7 +369,6 @@ public class TestConnPool {
         PoolStats totals = pool.getTotalStats();
         Assert.assertEquals(0, totals.getAvailable());
         Assert.assertEquals(2, totals.getLeased());
-        Assert.assertEquals(2, totals.getPending());
 
         pool.release(entry1, true);
         pool.release(entry2, true);
@@ -395,7 +388,6 @@ public class TestConnPool {
         totals = pool.getTotalStats();
         Assert.assertEquals(0, totals.getAvailable());
         Assert.assertEquals(2, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
 
         Future<LocalPoolEntry> future5 = pool.lease("somehost", null);
         GetPoolEntryThread t5 = new GetPoolEntryThread(future5);
@@ -422,7 +414,6 @@ public class TestConnPool {
         totals = pool.getTotalStats();
         Assert.assertEquals(0, totals.getAvailable());
         Assert.assertEquals(2, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
 
         pool.release(entry5, true);
         pool.release(entry6, true);
@@ -430,7 +421,6 @@ public class TestConnPool {
         totals = pool.getTotalStats();
         Assert.assertEquals(2, totals.getAvailable());
         Assert.assertEquals(0, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
     }
 
     @Test
@@ -462,11 +452,9 @@ public class TestConnPool {
         PoolStats totals = pool.getTotalStats();
         Assert.assertEquals(0, totals.getAvailable());
         Assert.assertEquals(1, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
         PoolStats stats = pool.getStats("somehost");
         Assert.assertEquals(0, stats.getAvailable());
         Assert.assertEquals(1, stats.getLeased());
-        Assert.assertEquals(0, stats.getPending());
     }
 
     @Test
@@ -505,11 +493,9 @@ public class TestConnPool {
         PoolStats totals = pool.getTotalStats();
         Assert.assertEquals(1, totals.getAvailable());
         Assert.assertEquals(0, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
         PoolStats stats = pool.getStats("somehost");
         Assert.assertEquals(1, stats.getAvailable());
         Assert.assertEquals(0, stats.getLeased());
-        Assert.assertEquals(0, stats.getPending());
     }
 
     @Test
@@ -625,11 +611,9 @@ public class TestConnPool {
         PoolStats totals = pool.getTotalStats();
         Assert.assertEquals(1, totals.getAvailable());
         Assert.assertEquals(0, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
         PoolStats stats = pool.getStats("somehost");
         Assert.assertEquals(1, stats.getAvailable());
         Assert.assertEquals(0, stats.getLeased());
-        Assert.assertEquals(0, stats.getPending());
 
         pool.closeIdle(-1, TimeUnit.MILLISECONDS);
 
@@ -638,11 +622,9 @@ public class TestConnPool {
         totals = pool.getTotalStats();
         Assert.assertEquals(0, totals.getAvailable());
         Assert.assertEquals(0, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
         stats = pool.getStats("somehost");
         Assert.assertEquals(0, stats.getAvailable());
         Assert.assertEquals(0, stats.getLeased());
-        Assert.assertEquals(0, stats.getPending());
     }
 
     @Test(expected=IllegalArgumentException.class)
@@ -707,7 +689,6 @@ public class TestConnPool {
         PoolStats totals = pool.getTotalStats();
         Assert.assertEquals(1, totals.getAvailable());
         Assert.assertEquals(1, totals.getLeased());
-        Assert.assertEquals(0, totals.getPending());
 
         pool.shutdown(1000);
         Assert.assertTrue(pool.isShutdown());

Copied: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
(from r1151814, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/pool/TestPoolEntry.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java?p2=httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/pool/TestPoolEntry.java&r1=1151814&r2=1151821&rev=1151821&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/pool/TestPoolEntry.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
Thu Jul 28 12:41:14 2011
@@ -24,28 +24,28 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.nio.pool;
+package org.apache.http.pool;
 
 import java.util.concurrent.TimeUnit;
 
 import junit.framework.Assert;
 
-import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.HttpConnection;
 import org.junit.Test;
 import org.mockito.Mockito;
 
 public class TestPoolEntry {
 
-    static class MockPoolEntry extends PoolEntry<String> {
+    static class MockPoolEntry extends PoolEntry<String, HttpConnection> {
 
         public MockPoolEntry(final String route,
                 long timeToLive, final TimeUnit tunit) {
-            super(route, Mockito.mock(IOSession.class), timeToLive, tunit);
+            super(route, Mockito.mock(HttpConnection.class), timeToLive, tunit);
         }
 
-        public MockPoolEntry(final String route, final IOSession iosession,
+        public MockPoolEntry(final String route, final HttpConnection conn,
                 long timeToLive, final TimeUnit tunit) {
-            super(route, iosession, timeToLive, tunit);
+            super(route, conn, timeToLive, tunit);
         }
 
     }
@@ -63,7 +63,7 @@ public class TestPoolEntry {
     @Test
     public void testInvalidConstruction() throws Exception {
         try {
-            new MockPoolEntry(null, Mockito.mock(IOSession.class), 0L, TimeUnit.MILLISECONDS);
+            new MockPoolEntry(null, Mockito.mock(HttpConnection.class), 0L, TimeUnit.MILLISECONDS);
             Assert.fail("IllegalArgumentException should have been thrown");
         } catch (IllegalArgumentException expected) {
         }
@@ -73,7 +73,7 @@ public class TestPoolEntry {
         } catch (IllegalArgumentException expected) {
         }
         try {
-            new MockPoolEntry("stuff", Mockito.mock(IOSession.class), 0L, null);
+            new MockPoolEntry("stuff", Mockito.mock(HttpConnection.class), 0L, null);
             Assert.fail("IllegalArgumentException should have been thrown");
         } catch (IllegalArgumentException expected) {
         }



Mime
View raw message