You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/09/02 10:43:25 UTC

svn commit: r1164404 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/ httpcore-nio/src/main/java/org/apache/http/nio/pool/ httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/ httpcore-nio/src/test/jav...

Author: olegk
Date: Fri Sep  2 08:43:25 2011
New Revision: 1164404

URL: http://svn.apache.org/viewvc?rev=1164404&view=rev
Log:
Extracted connection initialization logic from connection pool implementation into separate factory classes

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/NIOConnFactory.java   (with props)
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java   (with props)
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/ConnFactory.java   (with props)
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java?rev=1164404&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java Fri Sep  2 08:43:25 2011
@@ -0,0 +1,151 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.nio.pool;
+
+import java.io.IOException;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponseFactory;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.DefaultNHttpClientConnection;
+import org.apache.http.impl.nio.reactor.SSLIOSession;
+import org.apache.http.impl.nio.reactor.SSLMode;
+import org.apache.http.impl.nio.reactor.SSLSetupHandler;
+import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.pool.NIOConnFactory;
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
+
+/**
+ * Basic non-blocking {@link NHttpClientConnection} factory.
+ * <p>
+ * The following parameters can be used to customize the behavior of this
+ * class:
+ * <ul>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#CONNECTION_TIMEOUT}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
+ * </ul>
+ *
+ * @since 4.2
+ */
+@Immutable
+public class BasicNIOConnFactory implements NIOConnFactory<HttpHost, NHttpClientConnection> {
+
+    private final HttpResponseFactory responseFactory;
+    private final ByteBufferAllocator allocator;
+    private final SSLContext sslcontext;
+    private final SSLSetupHandler sslHandler;
+    private final HttpParams params;
+
+    public BasicNIOConnFactory(
+            final SSLContext sslcontext,
+            final SSLSetupHandler sslHandler,
+            final HttpResponseFactory responseFactory,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
+        super();
+        if (responseFactory == null) {
+            throw new IllegalArgumentException("HTTP response factory may not be null");
+        }
+        if (allocator == null) {
+            throw new IllegalArgumentException("Byte buffer allocator may not be null");
+        }
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        this.sslcontext = sslcontext;
+        this.sslHandler = sslHandler;
+        this.responseFactory = responseFactory;
+        this.allocator = allocator;
+        this.params = params;
+    }
+
+    public BasicNIOConnFactory(
+            final SSLContext sslcontext,
+            final SSLSetupHandler sslHandler,
+            final HttpParams params) {
+        this(sslcontext, sslHandler, new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
+    }
+
+    public BasicNIOConnFactory(final HttpParams params) {
+        this(null, null, params);
+    }
+
+    private SSLContext getDefaultSSLContext() {
+        SSLContext sslcontext;
+        try {
+            sslcontext = SSLContext.getInstance("TLS");
+            sslcontext.init(null, null, null);
+        } catch (Exception ex) {
+            throw new IllegalStateException("Failure initializing default SSL context", ex);
+        }
+        return sslcontext;
+    }
+
+    protected NHttpClientConnection create(
+            final IOSession session,
+            final HttpResponseFactory responseFactory,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) throws IOException {
+        return new DefaultNHttpClientConnection(session, responseFactory, allocator, params);
+    }
+
+    public NHttpClientConnection create(final HttpHost route, final IOSession session) throws IOException {
+        IOSession connSession;
+        if (route.getSchemeName().equalsIgnoreCase("https")) {
+            SSLContext connSSLContext = this.sslcontext != null ? this.sslcontext : getDefaultSSLContext();
+            SSLIOSession ssliosession = new SSLIOSession(session, connSSLContext, this.sslHandler);
+            ssliosession.bind(SSLMode.CLIENT, this.params);
+            session.setAttribute(IOSession.SSL_SESSION_KEY, ssliosession);
+            connSession = ssliosession;
+        } else {
+            connSession = session;
+        }
+
+        NHttpClientConnection conn = create(connSession,
+                this.responseFactory, this.allocator, this.params);
+
+        session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+
+        int timeout = HttpConnectionParams.getSoTimeout(this.params);
+        conn.setSocketTimeout(timeout);
+
+        return conn;
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java?rev=1164404&r1=1164403&r2=1164404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java Fri Sep  2 08:43:25 2011
@@ -33,29 +33,18 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
-import javax.net.ssl.SSLContext;
-
 import org.apache.http.HttpHost;
-import org.apache.http.HttpResponseFactory;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.concurrent.FutureCallback;
-import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.impl.nio.DefaultNHttpClientConnection;
-import org.apache.http.impl.nio.reactor.SSLIOSession;
-import org.apache.http.impl.nio.reactor.SSLMode;
-import org.apache.http.impl.nio.reactor.SSLSetupHandler;
 import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.nio.pool.AbstractNIOConnPool;
+import org.apache.http.nio.pool.NIOConnFactory;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
-import org.apache.http.nio.reactor.IOSession;
-import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.ExecutionContext;
 
 /**
- * Basic non-blocking {@link IOSession} pool.
+ * Basic non-blocking {@link NHttpClientConnection} pool.
  * <p>
  * The following parameters can be used to customize the behavior of this
  * class:
@@ -75,49 +64,22 @@ public class BasicNIOConnPool extends Ab
 
     private static AtomicLong COUNTER = new AtomicLong();
 
-    private final HttpResponseFactory responseFactory;
-    private final ByteBufferAllocator allocator;
-    private final SSLContext sslcontext;
-    private final SSLSetupHandler sslHandler;
     private final HttpParams params;
 
     public BasicNIOConnPool(
             final ConnectingIOReactor ioreactor,
-            final SSLContext sslcontext,
-            final SSLSetupHandler sslHandler,
-            final HttpResponseFactory responseFactory,
-            final ByteBufferAllocator allocator,
+            final NIOConnFactory<HttpHost, NHttpClientConnection> connFactory,
             final HttpParams params) {
-        super(ioreactor, 2, 20);
-        if (responseFactory == null) {
-            throw new IllegalArgumentException("HTTP response factory may not be null");
-        }
-        if (allocator == null) {
-            throw new IllegalArgumentException("Byte buffer allocator may not be null");
-        }
+        super(ioreactor, connFactory, 2, 20);
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
-        this.sslcontext = sslcontext;
-        this.sslHandler = sslHandler;
-        this.responseFactory = responseFactory;
-        this.allocator = allocator;
         this.params = params;
     }
 
     public BasicNIOConnPool(
-            final ConnectingIOReactor ioreactor,
-            final SSLContext sslcontext,
-            final SSLSetupHandler sslHandler,
-            final HttpParams params) {
-        this(ioreactor, sslcontext, sslHandler,
-                new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
-    }
-
-    public BasicNIOConnPool(
-            final ConnectingIOReactor ioreactor,
-            final HttpParams params) {
-        this(ioreactor, null, null, params);
+            final ConnectingIOReactor ioreactor, final HttpParams params) {
+        this(ioreactor, new BasicNIOConnFactory(params), params);
     }
 
     @Override
@@ -130,42 +92,6 @@ public class BasicNIOConnPool extends Ab
         return null;
     }
 
-    private SSLContext getDefaultSSLContext() {
-        SSLContext sslcontext;
-        try {
-            sslcontext = SSLContext.getInstance("TLS");
-            sslcontext.init(null, null, null);
-        } catch (Exception ex) {
-            throw new IllegalStateException("Failure initializing default SSL context", ex);
-        }
-        return sslcontext;
-    }
-
-    @Override
-    protected NHttpClientConnection createConnection(
-            final HttpHost route, final IOSession session) throws IOException {
-        IOSession connSession;
-        if (route.getSchemeName().equalsIgnoreCase("https")) {
-            SSLContext connSSLContext = this.sslcontext != null ? this.sslcontext : getDefaultSSLContext();
-            SSLIOSession ssliosession = new SSLIOSession(session, connSSLContext, this.sslHandler);
-            ssliosession.bind(SSLMode.CLIENT, this.params);
-            session.setAttribute(IOSession.SSL_SESSION_KEY, ssliosession);
-            connSession = ssliosession;
-        } else {
-            connSession = session;
-        }
-
-        NHttpClientConnection conn = new DefaultNHttpClientConnection(
-                connSession, this.responseFactory, this.allocator, this.params);
-
-        session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
-
-        int timeout = HttpConnectionParams.getSoTimeout(this.params);
-        conn.setSocketTimeout(timeout);
-
-        return conn;
-    }
-
     @Override
     protected BasicNIOPoolEntry createEntry(final HttpHost host, final NHttpClientConnection conn) {
         return new BasicNIOPoolEntry(Long.toString(COUNTER.getAndIncrement()), host, conn);

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=1164404&r1=1164403&r2=1164404&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 Fri Sep  2 08:43:25 2011
@@ -65,6 +65,7 @@ import org.apache.http.pool.PoolStats;
 public abstract class AbstractNIOConnPool<T, C, E extends PoolEntry<T, C>> implements ConnPoolControl<T> {
 
     private final ConnectingIOReactor ioreactor;
+    private final NIOConnFactory<T, C> connFactory;
     private final SessionRequestCallback sessionRequestCallback;
     private final Map<T, RouteSpecificPool<T, C, E>> routeToPool;
     private final LinkedList<LeaseRequest<T, C, E>> leasingRequests;
@@ -80,12 +81,16 @@ public abstract class AbstractNIOConnPoo
 
     public AbstractNIOConnPool(
             final ConnectingIOReactor ioreactor,
+            final NIOConnFactory<T, C> connFactory,
             int defaultMaxPerRoute,
             int maxTotal) {
         super();
         if (ioreactor == null) {
             throw new IllegalArgumentException("I/O reactor may not be null");
         }
+        if (connFactory == null) {
+            throw new IllegalArgumentException("Connection factory may not null");
+        }
         if (defaultMaxPerRoute <= 0) {
             throw new IllegalArgumentException("Max per route value may not be negative or zero");
         }
@@ -93,6 +98,7 @@ public abstract class AbstractNIOConnPoo
             throw new IllegalArgumentException("Max total value may not be negative or zero");
         }
         this.ioreactor = ioreactor;
+        this.connFactory = connFactory;
         this.sessionRequestCallback = new InternalSessionRequestCallback();
         this.routeToPool = new HashMap<T, RouteSpecificPool<T, C, E>>();
         this.leasingRequests = new LinkedList<LeaseRequest<T, C, E>>();
@@ -109,8 +115,6 @@ public abstract class AbstractNIOConnPoo
 
     protected abstract SocketAddress resolveLocalAddress(T route);
 
-    protected abstract C createConnection(T route, IOSession session) throws IOException;
-
     protected abstract E createEntry(T route, C conn);
 
     protected abstract void closeEntry(E entry);
@@ -346,7 +350,7 @@ public abstract class AbstractNIOConnPoo
             RouteSpecificPool<T, C, E> pool = getPool(route);
             IOSession session = request.getSession();
             try {
-                C conn = createConnection(route, session);
+                C conn = this.connFactory.create(route, session);
                 E entry = pool.completed(request, conn);
                 this.leased.add(entry);
             } catch (IOException ex) {

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/NIOConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/NIOConnFactory.java?rev=1164404&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/NIOConnFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/NIOConnFactory.java Fri Sep  2 08:43:25 2011
@@ -0,0 +1,41 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.nio.pool;
+
+import java.io.IOException;
+
+import org.apache.http.nio.reactor.IOSession;
+
+/**
+ * @since 4.2
+ */
+public interface NIOConnFactory<T, C> {
+
+    C create(T route, IOSession session) throws IOException;
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/NIOConnFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/NIOConnFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/NIOConnFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java?rev=1164404&r1=1164403&r2=1164404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java Fri Sep  2 08:43:25 2011
@@ -31,6 +31,7 @@ import org.apache.http.nio.NHttpClientCo
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -39,6 +40,8 @@ import org.mockito.MockitoAnnotations;
 
 public class TestBasicNIOConnPool {
 
+    private HttpParams params;
+    private BasicNIOConnFactory connFactory;
     private BasicNIOConnPool pool;
     private HttpHost route;
     @Mock private ConnectingIOReactor reactor;
@@ -49,8 +52,9 @@ public class TestBasicNIOConnPool {
         MockitoAnnotations.initMocks(this);
 
         route = new HttpHost("localhost", 80, "http");
-
-        pool = new BasicNIOConnPool(reactor, new BasicHttpParams());
+        params = new BasicHttpParams();
+        connFactory = new BasicNIOConnFactory(params);
+        pool = new BasicNIOConnPool(reactor, connFactory, params);
     }
 
     @After
@@ -69,12 +73,12 @@ public class TestBasicNIOConnPool {
 
     @Test
     public void testCreateConnection() throws Exception {
-        pool.createConnection(route, session);
+        connFactory.create(route, session);
     }
 
     @Test
     public void testCreateEntry() throws Exception {
-        NHttpClientConnection conn = pool.createConnection(route, session);
+        NHttpClientConnection conn = connFactory.create(route, session);
         BasicNIOPoolEntry entry = pool.createEntry(route, conn);
 
         pool.closeEntry(entry);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java?rev=1164404&r1=1164403&r2=1164404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java Fri Sep  2 08:43:25 2011
@@ -56,11 +56,19 @@ public class TestNIOConnPool {
 
     }
 
+    static class LocalConnFactory implements NIOConnFactory<String, IOSession> {
+
+        public IOSession create(String route, IOSession session) throws IOException {
+            return session;
+        }
+
+    }
+
     static class LocalSessionPool extends AbstractNIOConnPool<String, IOSession, LocalPoolEntry> {
 
         public LocalSessionPool(
                 final ConnectingIOReactor ioreactor, int defaultMaxPerRoute, int maxTotal) {
-            super(ioreactor, defaultMaxPerRoute, maxTotal);
+            super(ioreactor, new LocalConnFactory(), defaultMaxPerRoute, maxTotal);
         }
 
         @Override
@@ -74,11 +82,6 @@ public class TestNIOConnPool {
         }
 
         @Override
-        protected IOSession createConnection(final String route, final IOSession session) {
-            return session;
-        }
-
-        @Override
         protected LocalPoolEntry createEntry(final String route, final IOSession session) {
             return new LocalPoolEntry(route, session);
         }

Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java?rev=1164404&r1=1164403&r2=1164404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java Fri Sep  2 08:43:25 2011
@@ -38,6 +38,7 @@ import org.apache.http.HttpRequestInterc
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.pool.BasicConnFactory;
 import org.apache.http.impl.pool.BasicConnPool;
 import org.apache.http.impl.pool.BasicPoolEntry;
 import org.apache.http.message.BasicHttpRequest;
@@ -85,7 +86,7 @@ public class ElementalPoolingHttpGet {
 
         final HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
 
-        final BasicConnPool pool = new BasicConnPool(params);
+        final BasicConnPool pool = new BasicConnPool(new BasicConnFactory(params));
         pool.setDefaultMaxPerRoute(2);
         pool.setMaxTotal(2);
 

Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java?rev=1164404&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java Fri Sep  2 08:43:25 2011
@@ -0,0 +1,92 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.pool;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+import javax.net.ssl.SSLSocketFactory;
+
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpHost;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.impl.DefaultHttpClientConnection;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.pool.ConnFactory;
+
+/**
+ * @since 4.2
+ */
+@Immutable
+public class BasicConnFactory implements ConnFactory<HttpHost, HttpClientConnection> {
+
+    private final SSLSocketFactory sslfactory;
+    private final HttpParams params;
+
+    public BasicConnFactory(final SSLSocketFactory sslfactory, final HttpParams params) {
+        super();
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP params may not be null");
+        }
+        this.sslfactory = sslfactory;
+        this.params = params;
+    }
+
+    public BasicConnFactory(final HttpParams params) {
+        this(null, params);
+    }
+
+    protected HttpClientConnection create(final Socket socket, final HttpParams params) throws IOException {
+        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
+        conn.bind(socket, params);
+        return conn;
+    }
+
+    public HttpClientConnection create(final HttpHost host) throws IOException {
+        String scheme = host.getSchemeName();
+        Socket socket = null;
+        if ("http".equalsIgnoreCase(scheme)) {
+            socket = new Socket();
+        } if ("https".equalsIgnoreCase(scheme)) {
+            if (this.sslfactory != null) {
+                socket = this.sslfactory.createSocket();
+            }
+        }
+        if (socket == null) {
+            throw new IOException(scheme + " scheme is not supported");
+        }
+        int connectTimeout = HttpConnectionParams.getConnectionTimeout(this.params);
+        int soTimeout = HttpConnectionParams.getSoTimeout(this.params);
+
+        socket.setSoTimeout(soTimeout);
+        socket.connect(new InetSocketAddress(host.getHostName(), host.getPort()), connectTimeout);
+        return create(socket, this.params);
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java?rev=1164404&r1=1164403&r2=1164404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java Fri Sep  2 08:43:25 2011
@@ -27,64 +27,30 @@
 package org.apache.http.impl.pool;
 
 import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
 import java.util.concurrent.atomic.AtomicLong;
 
-import javax.net.ssl.SSLSocketFactory;
-
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpConnection;
 import org.apache.http.HttpHost;
 import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.impl.DefaultHttpClientConnection;
-import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.pool.AbstractConnPool;
+import org.apache.http.pool.ConnFactory;
 
+/**
+ * @since 4.2
+ */
 @ThreadSafe
 public class BasicConnPool extends AbstractConnPool<HttpHost, HttpClientConnection, BasicPoolEntry> {
 
     private static AtomicLong COUNTER = new AtomicLong();
 
-    private final SSLSocketFactory sslfactory;
-    private final HttpParams params;
-
-    public BasicConnPool(final SSLSocketFactory sslfactory, final HttpParams params) {
-        super(2, 20);
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP params may not be null");
-        }
-        this.sslfactory = sslfactory;
-        this.params = params;
+    public BasicConnPool(final ConnFactory<HttpHost, HttpClientConnection> connFactory) {
+        super(connFactory, 2, 20);
     }
 
     public BasicConnPool(final HttpParams params) {
-        this(null, params);
-    }
-
-    @Override
-    protected HttpClientConnection createConnection(final HttpHost host) throws IOException {
-        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
-        String scheme = host.getSchemeName();
-        Socket socket = null;
-        if ("http".equalsIgnoreCase(scheme)) {
-            socket = new Socket();
-        } if ("https".equalsIgnoreCase(scheme)) {
-            if (this.sslfactory != null) {
-                socket = this.sslfactory.createSocket();
-            }
-        }
-        if (socket == null) {
-            throw new IOException(scheme + " scheme is not supported");
-        }
-        int connectTimeout = HttpConnectionParams.getConnectionTimeout(this.params);
-        int soTimeout = HttpConnectionParams.getSoTimeout(this.params);
-
-        socket.setSoTimeout(soTimeout);
-        socket.connect(new InetSocketAddress(host.getHostName(), host.getPort()), connectTimeout);
-        conn.bind(socket, this.params);
-        return conn;
+        super(new BasicConnFactory(params), 2, 20);
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java?rev=1164404&r1=1164403&r2=1164404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java Fri Sep  2 08:43:25 2011
@@ -31,6 +31,9 @@ import org.apache.http.HttpHost;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.pool.PoolEntry;
 
+/**
+ * @since 4.2
+ */
 @ThreadSafe
 public class BasicPoolEntry extends PoolEntry<HttpHost, HttpClientConnection> {
 

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=1164404&r1=1164403&r2=1164404&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 Fri Sep  2 08:43:25 2011
@@ -55,6 +55,7 @@ import org.apache.http.annotation.Thread
 public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>> implements ConnPoolControl<T> {
 
     private final Lock lock;
+    private final ConnFactory<T, C> connFactory;
     private final Map<T, RouteSpecificPool<T, C, E>> routeToPool;
     private final Set<E> leased;
     private final LinkedList<E> available;
@@ -66,9 +67,13 @@ public abstract class AbstractConnPool<T
     private volatile int maxTotal;
 
     public AbstractConnPool(
+            final ConnFactory<T, C> connFactory,
             int defaultMaxPerRoute,
             int maxTotal) {
         super();
+        if (connFactory == null) {
+            throw new IllegalArgumentException("Connection factory may not null");
+        }
         if (defaultMaxPerRoute <= 0) {
             throw new IllegalArgumentException("Max per route value may not be negative or zero");
         }
@@ -76,6 +81,7 @@ public abstract class AbstractConnPool<T
             throw new IllegalArgumentException("Max total value may not be negative or zero");
         }
         this.lock = new ReentrantLock();
+        this.connFactory = connFactory;
         this.routeToPool = new HashMap<T, RouteSpecificPool<T, C, E>>();
         this.leased = new HashSet<E>();
         this.available = new LinkedList<E>();
@@ -85,8 +91,6 @@ public abstract class AbstractConnPool<T
         this.maxTotal = maxTotal;
     }
 
-    protected abstract C createConnection(T route) throws IOException;
-
     protected abstract E createEntry(T route, C conn);
 
     protected abstract void closeEntry(E entry);
@@ -228,7 +232,7 @@ public abstract class AbstractConnPool<T
                                 otherpool.remove(lastUsed);
                             }
                         }
-                        C conn = createConnection(route);
+                        C conn = this.connFactory.create(route);
                         entry = pool.add(conn);
                         this.leased.add(entry);
                         return entry;

Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/ConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/ConnFactory.java?rev=1164404&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/ConnFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/ConnFactory.java Fri Sep  2 08:43:25 2011
@@ -0,0 +1,39 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.pool;
+
+import java.io.IOException;
+
+/**
+ * @since 4.2
+ */
+public interface ConnFactory<T, C> {
+
+    C create(T route) throws IOException;
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/ConnFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/ConnFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/ConnFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java?rev=1164404&r1=1164403&r2=1164404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java Fri Sep  2 08:43:25 2011
@@ -27,7 +27,6 @@
 package org.apache.http.impl.pool;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
 
 import java.net.ServerSocket;
 
@@ -37,20 +36,20 @@ import javax.net.ssl.SSLSocketFactory;
 
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
+import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.HttpParams;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
 
 public class TestBasicConnPool {
 
+    private BasicConnFactory connFactory;
     private BasicConnPool pool;
     private HttpHost host;
-    @Mock private HttpParams params;
-    private HttpClientConnection conn = null;
+    private HttpParams params;
+    private HttpClientConnection conn;
 
     private ServerSocket server;
     private int serverPort;
@@ -60,8 +59,6 @@ public class TestBasicConnPool {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         // setup an "http" server
         server = new ServerSocket(0);
         serverPort = server.getLocalPort();
@@ -70,11 +67,11 @@ public class TestBasicConnPool {
         sslServer = (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket(0);
         sslServerPort = sslServer.getLocalPort();
 
-        pool = new BasicConnPool(params);
-
-        when(params.getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 0)).thenReturn(100);
-        when(params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0)).thenReturn(100);
-
+        params = new BasicHttpParams();
+        params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 100);
+        params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 100);
+        connFactory = new BasicConnFactory(params);
+        pool = new BasicConnPool(connFactory);
     }
 
     @After
@@ -87,14 +84,19 @@ public class TestBasicConnPool {
     }
 
     @Test(expected=IllegalArgumentException.class)
-    public void testNullConstructor() throws Exception {
-        pool = new BasicConnPool(null, null);
+    public void testNullConstructor1() throws Exception {
+        new BasicConnPool((HttpParams) null);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testNullConstructor2() throws Exception {
+        new BasicConnPool((BasicConnFactory) null);
     }
 
     @Test
     public void testHttpCreateConnection() throws Exception {
         host = new HttpHost("localhost", serverPort, "http");
-        conn = pool.createConnection(host);
+        conn = connFactory.create(host);
 
         assertEquals(true, conn.isOpen());
         assertEquals(100, conn.getSocketTimeout());
@@ -102,9 +104,9 @@ public class TestBasicConnPool {
 
     @Test
     public void testHttpsCreateConnection() throws Exception {
-        pool = new BasicConnPool((SSLSocketFactory)SSLSocketFactory.getDefault(), params);
+        connFactory = new BasicConnFactory((SSLSocketFactory)SSLSocketFactory.getDefault(), params);
         host = new HttpHost("localhost", sslServerPort, "https");
-        conn = pool.createConnection(host);
+        conn = connFactory.create(host);
 
         assertEquals(true, conn.isOpen());
         assertEquals(100, conn.getSocketTimeout());
@@ -113,7 +115,7 @@ public class TestBasicConnPool {
     @Test
     public void testHttpCreateEntry() throws Exception {
         host = new HttpHost("localhost", serverPort, "http");
-        conn = pool.createConnection(host);
+        conn = connFactory.create(host);
 
         BasicPoolEntry entry = pool.createEntry(host, conn);
 

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=1164404&r1=1164403&r2=1164404&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 Fri Sep  2 08:43:25 2011
@@ -42,10 +42,7 @@ public class TestConnPool {
 
     private static final int GRACE_PERIOD = 10000;
 
-    interface HttpConnectionFactory {
-
-        HttpConnection create(String route) throws IOException;
-
+    static interface LocalConnFactory extends ConnFactory<String, HttpConnection> {
     }
 
     static class LocalPoolEntry extends PoolEntry<String, HttpConnection> {
@@ -58,18 +55,10 @@ public class TestConnPool {
 
     static class LocalConnPool extends AbstractConnPool<String, HttpConnection, LocalPoolEntry> {
 
-        private final HttpConnectionFactory connFactory;
-
         public LocalConnPool(
-                final HttpConnectionFactory connFactory,
+                final ConnFactory<String, HttpConnection> connFactory,
                 int defaultMaxPerRoute, int maxTotal) {
-            super(defaultMaxPerRoute, maxTotal);
-            this.connFactory = connFactory;
-        }
-
-        @Override
-        protected HttpConnection createConnection(final String route) throws IOException {
-            return this.connFactory.create(route);
+            super(connFactory, defaultMaxPerRoute, maxTotal);
         }
 
         @Override
@@ -90,7 +79,7 @@ public class TestConnPool {
 
     @Test
     public void testEmptyPool() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
         LocalConnPool pool = new LocalConnPool(connFactory, 2, 10);
         pool.setDefaultMaxPerRoute(5);
         pool.setMaxPerRoute("somehost", 3);
@@ -107,7 +96,7 @@ public class TestConnPool {
 
     @Test
     public void testInvalidConstruction() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
         try {
             new LocalConnPool(connFactory, -1, 1);
             Assert.fail("IllegalArgumentException should have been thrown");
@@ -125,7 +114,7 @@ public class TestConnPool {
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         HttpConnection conn2 = Mockito.mock(HttpConnection.class);
 
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
         Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);
         Mockito.when(connFactory.create(Mockito.eq("otherhost"))).thenReturn(conn2);
 
@@ -160,7 +149,7 @@ public class TestConnPool {
 
     @Test
     public void testLeaseIllegal() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
         LocalConnPool pool = new LocalConnPool(connFactory, 2, 10);
         try {
             pool.lease(null, null);
@@ -171,7 +160,7 @@ public class TestConnPool {
 
     @Test
     public void testReleaseUnknownEntry() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
         LocalConnPool pool = new LocalConnPool(connFactory, 2, 10);
         pool.release(new LocalPoolEntry("somehost", Mockito.mock(HttpConnection.class)), true);
     }
@@ -222,7 +211,7 @@ public class TestConnPool {
 
     @Test
     public void testMaxLimits() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
 
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);
@@ -321,7 +310,7 @@ public class TestConnPool {
 
     @Test
     public void testConnectionRedistributionOnTotalMaxLimit() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
 
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         HttpConnection conn2 = Mockito.mock(HttpConnection.class);
@@ -425,7 +414,7 @@ public class TestConnPool {
 
     @Test
     public void testStatefulConnectionRedistributionOnPerRouteMaxLimit() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
 
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         HttpConnection conn2 = Mockito.mock(HttpConnection.class);
@@ -485,7 +474,7 @@ public class TestConnPool {
 
     @Test
     public void testCreateNewIfExpired() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
 
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);
@@ -519,7 +508,7 @@ public class TestConnPool {
 
     @Test
     public void testCloseExpired() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
 
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         Mockito.when(conn1.isOpen()).thenReturn(Boolean.FALSE);
@@ -560,7 +549,7 @@ public class TestConnPool {
 
     @Test
     public void testLeaseTimeout() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
 
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);
@@ -586,7 +575,7 @@ public class TestConnPool {
 
     @Test
     public void testLeaseIOException() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
         Mockito.doThrow(new IOException("Oppsie")).when(connFactory).create("somehost");
 
         LocalConnPool pool = new LocalConnPool(connFactory, 2, 10);
@@ -604,7 +593,7 @@ public class TestConnPool {
 
     @Test
     public void testLeaseCacnel() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
 
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);
@@ -639,7 +628,7 @@ public class TestConnPool {
 
     @Test
     public void testCloseIdle() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
 
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         HttpConnection conn2 = Mockito.mock(HttpConnection.class);
@@ -689,21 +678,21 @@ public class TestConnPool {
 
     @Test(expected=IllegalArgumentException.class)
     public void testCloseIdleInvalid() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
         LocalConnPool pool = new LocalConnPool(connFactory, 2, 2);
         pool.closeIdle(50, null);
     }
 
     @Test(expected=IllegalArgumentException.class)
     public void testGetStatsInvalid() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
         LocalConnPool pool = new LocalConnPool(connFactory, 2, 2);
         pool.getStats(null);
     }
 
     @Test
     public void testSetMaxInvalid() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
         LocalConnPool pool = new LocalConnPool(connFactory, 2, 2);
         try {
             pool.setMaxTotal(-1);
@@ -729,7 +718,7 @@ public class TestConnPool {
 
     @Test
     public void testShutdown() throws Exception {
-        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
+        LocalConnFactory connFactory = Mockito.mock(LocalConnFactory.class);
 
         HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);