hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1405507 [2/3] - in /httpcomponents/httpclient/trunk: ./ fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient/src/examples/org/apache/http/examples/conn/ httpclient/src/main/java/org/apache/http/conn/ httpclient/src/main/java/o...
Date Sun, 04 Nov 2012 07:37:52 GMT
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java Sun Nov  4 07:37:50 2012
@@ -33,6 +33,9 @@ import java.net.Socket;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+
 import org.apache.http.annotation.NotThreadSafe;
 
 import org.apache.commons.logging.Log;
@@ -51,6 +54,7 @@ import org.apache.http.io.HttpMessagePar
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.io.SessionOutputBuffer;
 
+import org.apache.http.conn.HttpSSLConnection;
 import org.apache.http.conn.OperatedClientConnection;
 
 /**
@@ -70,7 +74,7 @@ import org.apache.http.conn.OperatedClie
  */
 @NotThreadSafe // connSecure, targetHost
 public class DefaultClientConnection extends SocketHttpClientConnection
-    implements OperatedClientConnection, HttpContext {
+    implements OperatedClientConnection, HttpSSLConnection, HttpContext {
 
     private final Log log = LogFactory.getLog(getClass());
     private final Log headerLog = LogFactory.getLog("org.apache.http.headers");
@@ -109,6 +113,14 @@ public class DefaultClientConnection ext
         return this.socket;
     }
 
+    public SSLSession getSSLSession() {
+        if (this.socket instanceof SSLSocket) {
+            return ((SSLSocket) this.socket).getSession();
+        } else {
+            return null;
+        }
+    }
+
     public void opening(Socket sock, HttpHost target) throws IOException {
         assertNotOpen();
         this.socket = sock;

Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java (from r1398094, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java&r1=1398094&r2=1405507&rev=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java Sun Nov  4 07:37:50 2012
@@ -24,25 +24,22 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.conn;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
+package org.apache.http.impl.conn;
 
-import org.apache.http.conn.DnsResolver;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.conn.HttpConnectionFactory;
 
 /**
- * DNS resolver that uses the default OS implementation for resolving host names.
- *
- * @since 4.2
+ * @since 4.3
  */
-public class SystemDefaultDnsResolver implements DnsResolver {
+@Immutable
+public class DefaultClientConnectionFactory implements HttpConnectionFactory<DefaultClientConnection> {
+
+    public static final DefaultClientConnectionFactory INSTANCE = new DefaultClientConnectionFactory();
 
-    /**
-     * {@inheritDoc}
-     */
-    public InetAddress[] resolve(String host) throws UnknownHostException {
-        return InetAddress.getAllByName(host);
+    public DefaultClientConnection create() {
+        return new DefaultClientConnection();
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java Sun Nov  4 07:37:50 2012
@@ -84,7 +84,10 @@ import org.apache.http.conn.DnsResolver;
  * </ul>
  *
  * @since 4.0
+ *
+ * @deprecated (4.3) use {@link PoolingHttpClientConnectionManager}.
  */
+@Deprecated
 @ThreadSafe
 public class DefaultClientConnectionOperator implements ClientConnectionOperator {
 

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java?rev=1405507&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java Sun Nov  4 07:37:50 2012
@@ -0,0 +1,215 @@
+/*
+ * ====================================================================
+ *
+ *  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.conn;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpHost;
+import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.conn.ConnectionPoolTimeoutException;
+import org.apache.http.conn.ConnectionRequest;
+import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.HttpClientConnectionManager;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.params.HttpParams;
+import org.apache.http.pool.ConnPool;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * Base class for {@link HttpClientConnectionManager} implementations.
+ * This class primarily provides consistent implementation of
+ * {@link #connect(HttpClientConnection, HttpHost, InetAddress, HttpContext, HttpParams)}
+ * and {@link #upgrade(HttpClientConnection, HttpHost, HttpContext, HttpParams)}
+ * methods for all standard connection managers shipped with HttpClient.
+ *
+ * @since 4.3
+ */
+@ThreadSafe
+abstract class HttpClientConnectionManagerBase implements HttpClientConnectionManager {
+
+    private final ConnPool<HttpRoute, CPoolEntry> pool;
+    private final HttpClientConnectionOperator connectionOperator;
+
+    HttpClientConnectionManagerBase(
+            final ConnPool<HttpRoute, CPoolEntry> pool,
+            final SchemeRegistry schemeRegistry,
+            final DnsResolver dnsResolver) {
+        super();
+        if (pool == null) {
+            throw new IllegalArgumentException("Connection pool may nor be null");
+        }
+        if (schemeRegistry == null) {
+            throw new IllegalArgumentException("Scheme registry may nor be null");
+        }
+        this.pool = pool;
+        this.connectionOperator = new HttpClientConnectionOperator(schemeRegistry, dnsResolver);
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            shutdown();
+        } finally {
+            super.finalize();
+        }
+    }
+
+    public SchemeRegistry getSchemeRegistry() {
+        return this.connectionOperator.getSchemeRegistry();
+    }
+
+    protected void onConnectionLeaseRequest(final HttpRoute route, final Object state) {
+    }
+
+    protected void onConnectionLease(final CPoolEntry entry) {
+    }
+
+    protected void onConnectionKeepAlive(final CPoolEntry entry) {
+    }
+
+    protected void onConnectionRelease(final CPoolEntry entry) {
+    }
+
+    public ConnectionRequest requestConnection(
+            final HttpRoute route,
+            final Object state) {
+        if (route == null) {
+            throw new IllegalArgumentException("HTTP route may not be null");
+        }
+        onConnectionLeaseRequest(route, state);
+        final Future<CPoolEntry> future = this.pool.lease(route, state, null);
+        return new ConnectionRequest() {
+
+            public boolean cancel() {
+                return future.cancel(true);
+            }
+
+            public HttpClientConnection get(
+                    final long timeout,
+                    final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
+                return leaseConnection(future, timeout, tunit);
+            }
+
+        };
+
+    }
+
+    protected HttpClientConnection leaseConnection(
+            final Future<CPoolEntry> future,
+            final long timeout,
+            final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
+        CPoolEntry entry;
+        try {
+            entry = future.get(timeout, tunit);
+            if (entry == null || future.isCancelled()) {
+                throw new InterruptedException();
+            }
+            if (entry.getConnection() == null) {
+                throw new IllegalStateException("Pool entry with no connection");
+            }
+            onConnectionLease(entry);
+            return CPoolProxy.newProxy(entry);
+        } catch (ExecutionException ex) {
+            Throwable cause = ex.getCause();
+            if (cause == null) {
+                cause = ex;
+            }
+            InterruptedException intex = new InterruptedException();
+            intex.initCause(cause);
+            throw intex;
+        } catch (TimeoutException ex) {
+            throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool");
+        }
+    }
+
+    public void releaseConnection(
+            final HttpClientConnection managedConn,
+            final Object state,
+            final long keepalive, final TimeUnit tunit) {
+        if (managedConn == null) {
+            throw new IllegalArgumentException("Managed connection may not be null");
+        }
+        synchronized (managedConn) {
+            CPoolEntry entry = CPoolProxy.detach(managedConn);
+            if (entry == null) {
+                return;
+            }
+            DefaultClientConnection conn = entry.getConnection();
+            try {
+                if (conn.isOpen()) {
+                    entry.setState(state);
+                    entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
+                    onConnectionKeepAlive(entry);
+                }
+            } finally {
+                this.pool.release(entry, conn.isOpen());
+                onConnectionRelease(entry);
+            }
+        }
+    }
+
+    public void connect(
+            final HttpClientConnection managedConn,
+            final HttpHost host,
+            final InetAddress local,
+            final HttpContext context,
+            final HttpParams params) throws IOException {
+        if (managedConn == null) {
+            throw new IllegalArgumentException("Connection may not be null");
+        }
+        DefaultClientConnection conn;
+        synchronized (managedConn) {
+            CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
+            conn = entry.getConnection();
+        }
+        this.connectionOperator.connect(conn, host, local, context, params);
+    }
+
+    public void upgrade(
+            final HttpClientConnection managedConn,
+            final HttpHost host,
+            final HttpContext context,
+            final HttpParams params) throws IOException {
+        if (managedConn == null) {
+            throw new IllegalArgumentException("Connection may not be null");
+        }
+        DefaultClientConnection conn;
+        synchronized (managedConn) {
+            CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
+            conn = entry.getConnection();
+        }
+        this.connectionOperator.upgrade(conn, host, context, params);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java?rev=1405507&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java Sun Nov  4 07:37:50 2012
@@ -0,0 +1,163 @@
+/*
+ * ====================================================================
+ *
+ *  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.conn;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpHost;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.HttpClientConnectionManager;
+import org.apache.http.conn.HttpHostConnectException;
+import org.apache.http.conn.HttpInetSocketAddress;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
+
+@Immutable
+class HttpClientConnectionOperator {
+
+    private final Log log = LogFactory.getLog(HttpClientConnectionManager.class);
+
+    private final SchemeRegistry schemeRegistry;
+    private final DnsResolver dnsResolver;
+
+    HttpClientConnectionOperator(
+            final SchemeRegistry schemeRegistry,
+            final DnsResolver dnsResolver) {
+        super();
+        if (schemeRegistry == null) {
+            throw new IllegalArgumentException("Scheme registry may nor be null");
+        }
+        this.schemeRegistry = schemeRegistry;
+        this.dnsResolver = dnsResolver != null ? dnsResolver : SystemDefaultDnsResolver.INSTANCE;
+    }
+
+    public SchemeRegistry getSchemeRegistry() {
+        return this.schemeRegistry;
+    }
+
+    public DnsResolver getDnsResolver() {
+        return this.dnsResolver;
+    }
+
+    private SchemeRegistry getSchemeRegistry(final HttpContext context) {
+        SchemeRegistry reg = (SchemeRegistry) context.getAttribute(
+                ClientContext.SCHEME_REGISTRY);
+        if (reg == null) {
+            reg = this.schemeRegistry;
+        }
+        return reg;
+    }
+
+    public void connect(
+            final DefaultClientConnection conn,
+            final HttpHost host,
+            final InetAddress local,
+            final HttpContext context,
+            final HttpParams params) throws IOException {
+        SchemeRegistry registry = getSchemeRegistry(context);
+        Scheme schm = registry.getScheme(host.getSchemeName());
+        SchemeSocketFactory sf = schm.getSchemeSocketFactory();
+
+        InetAddress[] addresses = this.dnsResolver.resolve(host.getHostName());
+        int port = schm.resolvePort(host.getPort());
+        for (int i = 0; i < addresses.length; i++) {
+            InetAddress address = addresses[i];
+            boolean last = i == addresses.length - 1;
+
+            Socket sock = sf.createSocket(params);
+            conn.opening(sock, host);
+
+            InetSocketAddress remoteAddress = new HttpInetSocketAddress(host, address, port);
+            InetSocketAddress localAddress = null;
+            if (local != null) {
+                localAddress = new InetSocketAddress(local, 0);
+            }
+            if (this.log.isDebugEnabled()) {
+                this.log.debug("Connecting to " + remoteAddress);
+            }
+            try {
+                Socket connsock = sf.connectSocket(sock, remoteAddress, localAddress, params);
+                if (sock != connsock) {
+                    sock = connsock;
+                    conn.opening(sock, host);
+                }
+                conn.openCompleted(sf.isSecure(sock), params);
+                return;
+            } catch (ConnectException ex) {
+                if (last) {
+                    throw new HttpHostConnectException(host, ex);
+                }
+            } catch (ConnectTimeoutException ex) {
+                if (last) {
+                    throw ex;
+                }
+            }
+            if (this.log.isDebugEnabled()) {
+                this.log.debug("Connect to " + remoteAddress + " timed out. " +
+                        "Connection will be retried using another IP address");
+            }
+        }
+    }
+
+    public void upgrade(
+            final DefaultClientConnection conn,
+            final HttpHost host,
+            final HttpContext context,
+            final HttpParams params) throws IOException {
+        SchemeRegistry registry = getSchemeRegistry(context);
+        Scheme schm = registry.getScheme(host.getSchemeName());
+        if (!(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory)) {
+            throw new IllegalArgumentException
+                ("Target scheme (" + schm.getName() +
+                 ") must have layered socket factory.");
+        }
+        SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory();
+        Socket sock;
+        try {
+            int port = schm.resolvePort(host.getPort());
+            sock = lsf.createLayeredSocket(
+                    conn.getSocket(), host.getHostName(), port, params);
+        } catch (ConnectException ex) {
+            throw new HttpHostConnectException(host, ex);
+        }
+        conn.update(sock, host, lsf.isSecure(sock), params);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpConnPool.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpConnPool.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpConnPool.java Sun Nov  4 07:37:50 2012
@@ -38,7 +38,10 @@ import org.apache.http.pool.ConnFactory;
 
 /**
  * @since 4.2
+ *
+ * @deprecated (4.3) no longer used.
  */
+@Deprecated
 class HttpConnPool extends AbstractConnPool<HttpRoute, OperatedClientConnection, HttpPoolEntry> {
 
     private static AtomicLong COUNTER = new AtomicLong();

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpPoolEntry.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpPoolEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpPoolEntry.java Sun Nov  4 07:37:50 2012
@@ -38,7 +38,10 @@ import org.apache.http.pool.PoolEntry;
 
 /**
  * @since 4.2
+ *
+ * @deprecated (4.3) no longer used.
  */
+@Deprecated
 class HttpPoolEntry extends PoolEntry<HttpRoute, OperatedClientConnection> {
 
     private final Log log;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java Sun Nov  4 07:37:50 2012
@@ -51,6 +51,12 @@ import org.apache.http.conn.routing.Rout
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpContext;
 
+/**
+ * @since 4.2
+ *
+ * @deprecated (4.3) no longer used.
+ */
+@Deprecated
 @NotThreadSafe
 class ManagedClientConnectionImpl implements ManagedClientConnection {
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java Sun Nov  4 07:37:50 2012
@@ -66,7 +66,10 @@ import org.apache.http.conn.DnsResolver;
  * can be adjusted using HTTP parameters.
  *
  * @since 4.2
+ *
+ * @deprecated (4.3) use {@link PoolingHttpClientConnectionManager}.
  */
+@Deprecated
 @ThreadSafe
 public class PoolingClientConnectionManager implements ClientConnectionManager, ConnPoolControl<HttpRoute> {
 

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java?rev=1405507&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java Sun Nov  4 07:37:50 2012
@@ -0,0 +1,231 @@
+/*
+ * ====================================================================
+ *
+ *  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.conn;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpClientConnection;
+import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.pool.ConnPoolControl;
+import org.apache.http.pool.PoolStats;
+
+/**
+ * <tt>ClientConnectionPoolManager</tt> maintains a pool of
+ * {@link HttpClientConnection}s and is able to service connection requests
+ * from multiple execution threads. Connections are pooled on a per route
+ * basis. A request for a route which already the manager has persistent
+ * connections for available in the pool will be services by leasing
+ * a connection from the pool rather than creating a brand new connection.
+ * <p/>
+ * <tt>ClientConnectionPoolManager</tt> maintains a maximum limit of connection
+ * on a per route basis and in total. Per default this implementation will
+ * create no more than than 2 concurrent connections per given route
+ * and no more 20 connections in total. For many real-world applications
+ * these limits may prove too constraining, especially if they use HTTP
+ * as a transport protocol for their services. Connection limits, however,
+ * can be adjusted using {@link ConnPoolControl} methods.
+ *
+ * @since 4.3
+ */
+@ThreadSafe
+public class PoolingHttpClientConnectionManager extends HttpClientConnectionManagerBase {
+
+    private final Log log = LogFactory.getLog(getClass());
+
+    private final CPool pool;
+
+    public PoolingHttpClientConnectionManager() {
+        this(SchemeRegistryFactory.createDefault());
+    }
+
+    public PoolingHttpClientConnectionManager(final SchemeRegistry schreg) {
+        this(schreg, -1, TimeUnit.MILLISECONDS);
+    }
+
+    public PoolingHttpClientConnectionManager(
+            final SchemeRegistry schreg, final DnsResolver dnsResolver) {
+        this(schreg, dnsResolver, -1, TimeUnit.MILLISECONDS);
+    }
+
+    public PoolingHttpClientConnectionManager(
+            final SchemeRegistry schemeRegistry,
+            final long timeToLive, final TimeUnit tunit) {
+        this(new CPool(2, 20, timeToLive, tunit), schemeRegistry, null);
+    }
+
+    public PoolingHttpClientConnectionManager(
+            final SchemeRegistry schemeRegistry,
+            final DnsResolver dnsResolver,
+            final long timeToLive, final TimeUnit tunit) {
+        this(new CPool(2, 20, timeToLive, tunit), schemeRegistry, dnsResolver);
+    }
+
+    PoolingHttpClientConnectionManager(
+            final CPool pool,
+            final SchemeRegistry schemeRegistry,
+            final DnsResolver dnsResolver) {
+        super(pool, schemeRegistry, dnsResolver);
+        this.pool = pool;
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            shutdown();
+        } finally {
+            super.finalize();
+        }
+    }
+
+    private String format(final HttpRoute route, final Object state) {
+        StringBuilder buf = new StringBuilder();
+        buf.append("[route: ").append(route).append("]");
+        if (state != null) {
+            buf.append("[state: ").append(state).append("]");
+        }
+        return buf.toString();
+    }
+
+    private String formatStats(final HttpRoute route) {
+        StringBuilder buf = new StringBuilder();
+        PoolStats totals = this.pool.getTotalStats();
+        PoolStats stats = this.pool.getStats(route);
+        buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
+        buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
+        buf.append(" of ").append(stats.getMax()).append("; ");
+        buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
+        buf.append(" of ").append(totals.getMax()).append("]");
+        return buf.toString();
+    }
+
+    private String format(final CPoolEntry entry) {
+        StringBuilder buf = new StringBuilder();
+        buf.append("[id: ").append(entry.getId()).append("]");
+        buf.append("[route: ").append(entry.getRoute()).append("]");
+        Object state = entry.getState();
+        if (state != null) {
+            buf.append("[state: ").append(state).append("]");
+        }
+        return buf.toString();
+    }
+
+    @Override
+    protected void onConnectionLeaseRequest(final HttpRoute route, final Object state) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Connection request: " + format(route, state) + formatStats(route));
+        }
+    }
+
+    @Override
+    protected void onConnectionLease(final CPoolEntry entry) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute()));
+        }
+    }
+
+    @Override
+    protected void onConnectionKeepAlive(final CPoolEntry entry) {
+        if (this.log.isDebugEnabled()) {
+            long keepalive = entry.getExpiry();
+            String s;
+            if (keepalive > 0) {
+                s = "for " + (double) keepalive / 1000 + " seconds";
+            } else {
+                s = "indefinitely";
+            }
+            this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
+        }
+    }
+
+    @Override
+    protected void onConnectionRelease(final CPoolEntry entry) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
+        }
+    }
+
+    public void shutdown() {
+        this.log.debug("Connection manager is shutting down");
+        try {
+            this.pool.shutdown();
+        } catch (IOException ex) {
+            this.log.debug("I/O exception shutting down connection manager", ex);
+        }
+        this.log.debug("Connection manager shut down");
+    }
+
+    public void closeIdleConnections(long idleTimeout, TimeUnit tunit) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
+        }
+        this.pool.closeIdle(idleTimeout, tunit);
+    }
+
+    public void closeExpiredConnections() {
+        this.log.debug("Closing expired connections");
+        this.pool.closeExpired();
+    }
+
+    public int getMaxTotal() {
+        return this.pool.getMaxTotal();
+    }
+
+    public void setMaxTotal(int max) {
+        this.pool.setMaxTotal(max);
+    }
+
+    public int getDefaultMaxPerRoute() {
+        return this.pool.getDefaultMaxPerRoute();
+    }
+
+    public void setDefaultMaxPerRoute(int max) {
+        this.pool.setDefaultMaxPerRoute(max);
+    }
+
+    public int getMaxPerRoute(final HttpRoute route) {
+        return this.pool.getMaxPerRoute(route);
+    }
+
+    public void setMaxPerRoute(final HttpRoute route, int max) {
+        this.pool.setMaxPerRoute(route, max);
+    }
+
+    public PoolStats getTotalStats() {
+        return this.pool.getTotalStats();
+    }
+
+    public PoolStats getStats(final HttpRoute route) {
+        return this.pool.getStats(route);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java Sun Nov  4 07:37:50 2012
@@ -38,6 +38,8 @@ import org.apache.http.conn.DnsResolver;
  */
 public class SystemDefaultDnsResolver implements DnsResolver {
 
+    public static final SystemDefaultDnsResolver INSTANCE = new SystemDefaultDnsResolver();
+
     /**
      * {@inheritDoc}
      */

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java Sun Nov  4 07:37:50 2012
@@ -39,7 +39,7 @@ import org.apache.http.HttpResponseInter
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.localserver.LocalTestServer;
 import org.apache.http.localserver.RandomHandler;
 import org.apache.http.protocol.BasicHttpProcessor;
@@ -79,7 +79,7 @@ public class TestConnectionReuse {
 
         InetSocketAddress saddress = this.localServer.getServiceAddress();
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(5);
         mgr.setDefaultMaxPerRoute(5);
 
@@ -138,7 +138,7 @@ public class TestConnectionReuse {
 
         InetSocketAddress saddress = this.localServer.getServiceAddress();
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(5);
         mgr.setDefaultMaxPerRoute(5);
 
@@ -188,7 +188,7 @@ public class TestConnectionReuse {
 
         InetSocketAddress saddress = this.localServer.getServiceAddress();
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(5);
         mgr.setDefaultMaxPerRoute(5);
 
@@ -239,7 +239,7 @@ public class TestConnectionReuse {
 
         InetSocketAddress saddress = this.localServer.getServiceAddress();
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
         mgr.setDefaultMaxPerRoute(1);
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestAutoRetryHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestAutoRetryHttpClient.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestAutoRetryHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestAutoRetryHttpClient.java Sun Nov  4 07:37:50 2012
@@ -48,6 +48,7 @@ import org.apache.http.protocol.HttpCont
 import org.junit.Before;
 import org.junit.Test;
 
+@Deprecated
 public class TestAutoRetryHttpClient{
 
     private AutoRetryHttpClient impl;

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java Sun Nov  4 07:37:50 2012
@@ -34,12 +34,12 @@ import org.apache.http.client.HttpClient
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
 import org.apache.http.conn.scheme.SchemeSocketFactory;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpContext;
@@ -54,7 +54,7 @@ public class TestRequestRetryHandler {
 
         SchemeRegistry schemeRegistry = new SchemeRegistry();
         schemeRegistry.register(new Scheme("http", 80, new OppsieSchemeSocketFactory()));
-        ClientConnectionManager connManager = new PoolingClientConnectionManager(schemeRegistry);
+        HttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(schemeRegistry);
         TestHttpRequestRetryHandler testRetryHandler = new TestHttpRequestRetryHandler();
 
         HttpClient client = new HttpClientBuilder()

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java Sun Nov  4 07:37:50 2012
@@ -28,10 +28,12 @@ package org.apache.http.impl.client.inte
 
 import java.io.IOException;
 import java.net.ConnectException;
+import java.net.InetAddress;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
@@ -41,16 +43,15 @@ import org.apache.http.ProtocolVersion;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.concurrent.Cancellable;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.ClientConnectionRequest;
 import org.apache.http.conn.ConnectionPoolTimeoutException;
-import org.apache.http.conn.ManagedClientConnection;
+import org.apache.http.conn.ConnectionRequest;
+import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.impl.conn.SchemeRegistryFactory;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.mockup.SocketFactoryMockup;
@@ -171,7 +172,7 @@ public class TestAbortHandling extends I
         this.localServer.register("*", new BasicService());
 
         final CountDownLatch releaseLatch = new CountDownLatch(1);
-        final PoolingClientConnectionManager conMan = new PoolingClientConnectionManager();
+        final PoolingHttpClientConnectionManager conMan = new PoolingHttpClientConnectionManager();
         final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
         final CountDownLatch getLatch = new CountDownLatch(1);
         final HttpClient client = new HttpClientBuilder().setConnectionManager(conMan).build();
@@ -210,7 +211,7 @@ public class TestAbortHandling extends I
     public void testAbortBeforeExecute() throws Exception {
         this.localServer.register("*", new BasicService());
 
-        final PoolingClientConnectionManager conMan = new PoolingClientConnectionManager();
+        final PoolingHttpClientConnectionManager conMan = new PoolingHttpClientConnectionManager();
         final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
         final CountDownLatch getLatch = new CountDownLatch(1);
         final CountDownLatch startLatch = new CountDownLatch(1);
@@ -296,15 +297,17 @@ public class TestAbortHandling extends I
      */
     @Test
     public void testSocketConnectFailureReleasesConnection() throws Exception {
-        ManagedClientConnection conn = Mockito.mock(ManagedClientConnection.class);
-        Mockito.doThrow(new ConnectException()).when(conn).open(
-                Mockito.any(HttpRoute.class),
+        HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
+        ConnectionRequest connrequest = Mockito.mock(ConnectionRequest.class);
+        Mockito.when(connrequest.get(
+                Mockito.anyInt(), Mockito.any(TimeUnit.class))).thenReturn(conn);
+        HttpClientConnectionManager connmgr = Mockito.mock(HttpClientConnectionManager.class);
+        Mockito.doThrow(new ConnectException()).when(connmgr).connect(
+                Mockito.any(HttpClientConnection.class),
+                Mockito.any(HttpHost.class),
+                Mockito.any(InetAddress.class),
                 Mockito.any(HttpContext.class),
                 Mockito.any(HttpParams.class));
-        ClientConnectionRequest connrequest = Mockito.mock(ClientConnectionRequest.class);
-        Mockito.when(connrequest.getConnection(
-                Mockito.anyInt(), Mockito.any(TimeUnit.class))).thenReturn(conn);
-        ClientConnectionManager connmgr = Mockito.mock(ClientConnectionManager.class);
 
         SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
 
@@ -321,7 +324,7 @@ public class TestAbortHandling extends I
             Assert.fail("expected IOException");
         } catch(IOException expected) {}
 
-        Mockito.verify(conn).abortConnection();
+        Mockito.verify(connmgr).releaseConnection(conn, null, 0, TimeUnit.MILLISECONDS);
     }
 
     private static class BasicService implements HttpRequestHandler {
@@ -352,7 +355,7 @@ public class TestAbortHandling extends I
         }
     }
 
-    private static class ConnMan4 extends PoolingClientConnectionManager {
+    private static class ConnMan4 extends PoolingHttpClientConnectionManager {
         private final CountDownLatch connLatch;
         private final CountDownLatch awaitLatch;
 
@@ -363,19 +366,20 @@ public class TestAbortHandling extends I
         }
 
         @Override
-        public ClientConnectionRequest requestConnection(HttpRoute route, Object state) {
+        public ConnectionRequest requestConnection(HttpRoute route, Object state) {
             // If this is the redirect route, stub the return value
             // so-as to pretend the host is waiting on a slot...
             if(route.getTargetHost().getHostName().equals("localhost")) {
                 final Thread currentThread = Thread.currentThread();
 
-                return new ClientConnectionRequest() {
+                return new ConnectionRequest() {
 
-                    public void abortRequest() {
+                    public boolean cancel() {
                         currentThread.interrupt();
+                        return true;
                     }
 
-                    public ManagedClientConnection getConnection(
+                    public HttpClientConnection get(
                             long timeout, TimeUnit tunit)
                             throws InterruptedException,
                             ConnectionPoolTimeoutException {
@@ -388,7 +392,7 @@ public class TestAbortHandling extends I
                         if(!awaitLatch.await(timeout, tunit))
                             throw new ConnectionPoolTimeoutException();
 
-                        return Mockito.mock(ManagedClientConnection.class);
+                        return Mockito.mock(HttpClientConnection.class);
                     }
                 };
             } else {
@@ -398,7 +402,7 @@ public class TestAbortHandling extends I
     }
 
 
-    static class ConMan implements ClientConnectionManager {
+    static class ConMan implements HttpClientConnectionManager {
         private final CountDownLatch connLatch;
         private final CountDownLatch awaitLatch;
 
@@ -415,28 +419,25 @@ public class TestAbortHandling extends I
             throw new UnsupportedOperationException("just a mockup");
         }
 
-        public ManagedClientConnection getConnection(HttpRoute route) {
-            throw new UnsupportedOperationException("just a mockup");
-        }
-
-        public ManagedClientConnection getConnection(HttpRoute route,
+        public HttpClientConnection getConnection(HttpRoute route,
                 long timeout, TimeUnit tunit) {
             throw new UnsupportedOperationException("just a mockup");
         }
 
-        public ClientConnectionRequest requestConnection(
+        public ConnectionRequest requestConnection(
                 final HttpRoute route,
                 final Object state) {
 
             final Thread currentThread = Thread.currentThread();
 
-            return new ClientConnectionRequest() {
+            return new ConnectionRequest() {
 
-                public void abortRequest() {
+                public boolean cancel() {
                     currentThread.interrupt();
+                    return true;
                 }
 
-                public ManagedClientConnection getConnection(
+                public HttpClientConnection get(
                         long timeout, TimeUnit tunit)
                         throws InterruptedException,
                         ConnectionPoolTimeoutException {
@@ -449,8 +450,9 @@ public class TestAbortHandling extends I
                     if(!awaitLatch.await(timeout, tunit))
                         throw new ConnectionPoolTimeoutException();
 
-                    return Mockito.mock(ManagedClientConnection.class);
+                    return Mockito.mock(HttpClientConnection.class);
                 }
+
             };
         }
 
@@ -464,11 +466,22 @@ public class TestAbortHandling extends I
             return registry;
         }
 
-        public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) {
+        public void shutdown() {
+        }
+
+        public void releaseConnection(HttpClientConnection conn, Object newState,
+                long validDuration, TimeUnit timeUnit) {
             throw new UnsupportedOperationException("just a mockup");
         }
 
-        public void shutdown() {
+        public void connect(HttpClientConnection conn, HttpHost host, InetAddress localAddress,
+                HttpContext context, HttpParams params) throws IOException {
+            throw new UnsupportedOperationException("just a mockup");
+        }
+
+        public void upgrade(HttpClientConnection conn, HttpHost host, HttpContext context,
+                HttpParams params) throws IOException {
+            throw new UnsupportedOperationException("just a mockup");
         }
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java?rev=1405507&r1=1405506&r2=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java Sun Nov  4 07:37:50 2012
@@ -32,6 +32,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
@@ -39,14 +40,13 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.MalformedChunkCodingException;
 import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.ClientConnectionRequest;
+import org.apache.http.conn.ConnectionRequest;
 import org.apache.http.conn.ConnectionPoolTimeoutException;
-import org.apache.http.conn.ManagedClientConnection;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.impl.DefaultHttpServerConnection;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.pool.PoolStats;
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpContext;
@@ -58,12 +58,12 @@ import org.junit.Test;
 
 public class TestConnectionAutoRelease extends IntegrationTestBase {
 
-    private PoolingClientConnectionManager mgr;
+    private PoolingHttpClientConnectionManager mgr;
 
     @Before
     public void setUp() throws Exception {
         startServer();
-        this.mgr = new PoolingClientConnectionManager();
+        this.mgr = new PoolingHttpClientConnectionManager();
         this.httpclient = new HttpClientBuilder().setConnectionManager(this.mgr).build();
     }
 
@@ -82,9 +82,9 @@ public class TestConnectionAutoRelease e
 
         HttpResponse response = this.httpclient.execute(target, httpget);
 
-        ClientConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
         try {
-            connreq.getConnection(250, TimeUnit.MILLISECONDS);
+            connreq.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
         } catch (ConnectionPoolTimeoutException expected) {
         }
@@ -99,9 +99,9 @@ public class TestConnectionAutoRelease e
 
         // Make sure one connection is available
         connreq = this.mgr.requestConnection(new HttpRoute(target), null);
-        ManagedClientConnection conn = connreq.getConnection(250, TimeUnit.MILLISECONDS);
+        HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
 
-        this.mgr.releaseConnection(conn, -1, null);
+        this.mgr.releaseConnection(conn, null, -1, null);
     }
 
     @Test
@@ -119,9 +119,9 @@ public class TestConnectionAutoRelease e
 
         HttpResponse response = this.httpclient.execute(target, httpget);
 
-        ClientConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
         try {
-            connreq.getConnection(250, TimeUnit.MILLISECONDS);
+            connreq.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
         } catch (ConnectionPoolTimeoutException expected) {
         }
@@ -137,9 +137,9 @@ public class TestConnectionAutoRelease e
 
         // Make sure one connection is available
         connreq = this.mgr.requestConnection(new HttpRoute(target), null);
-        ManagedClientConnection conn = connreq.getConnection(250, TimeUnit.MILLISECONDS);
+        HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
 
-        this.mgr.releaseConnection(conn, -1, null);
+        this.mgr.releaseConnection(conn, null, -1, null);
     }
 
     @Test
@@ -157,9 +157,9 @@ public class TestConnectionAutoRelease e
 
         HttpResponse response = this.httpclient.execute(target, httpget);
 
-        ClientConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
         try {
-            connreq.getConnection(250, TimeUnit.MILLISECONDS);
+            connreq.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
         } catch (ConnectionPoolTimeoutException expected) {
         }
@@ -173,9 +173,9 @@ public class TestConnectionAutoRelease e
 
         // Make sure one connection is available
         connreq = this.mgr.requestConnection(new HttpRoute(target), null);
-        ManagedClientConnection conn = connreq.getConnection(250, TimeUnit.MILLISECONDS);
+        HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
 
-        this.mgr.releaseConnection(conn, -1, null);
+        this.mgr.releaseConnection(conn, null, -1, null);
     }
 
     @Test
@@ -224,9 +224,9 @@ public class TestConnectionAutoRelease e
 
         HttpResponse response = this.httpclient.execute(target, httpget);
 
-        ClientConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
         try {
-            connreq.getConnection(250, TimeUnit.MILLISECONDS);
+            connreq.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
         } catch (ConnectionPoolTimeoutException expected) {
         }
@@ -246,9 +246,9 @@ public class TestConnectionAutoRelease e
 
         // Make sure one connection is available
         connreq = this.mgr.requestConnection(new HttpRoute(target), null);
-        ManagedClientConnection conn = connreq.getConnection(250, TimeUnit.MILLISECONDS);
+        HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
 
-        this.mgr.releaseConnection(conn, -1, null);
+        this.mgr.releaseConnection(conn, null, -1, null);
     }
 
 }

Copied: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java (from r1398094, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingConnManager.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java?p2=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java&p1=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingConnManager.java&r1=1398094&r2=1405507&rev=1405507&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingConnManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java Sun Nov  4 07:37:50 2012
@@ -25,10 +25,9 @@
  *
  */
 
-package org.apache.http.impl.conn;
+package org.apache.http.impl.client.integration;
 
 import java.io.IOException;
-import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketException;
@@ -37,24 +36,24 @@ import java.util.concurrent.CountDownLat
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.ClientConnectionOperator;
-import org.apache.http.conn.ClientConnectionRequest;
 import org.apache.http.conn.ConnectTimeoutException;
 import org.apache.http.conn.ConnectionPoolTimeoutException;
-import org.apache.http.conn.ManagedClientConnection;
-import org.apache.http.conn.OperatedClientConnection;
+import org.apache.http.conn.ConnectionRequest;
+import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.conn.scheme.PlainSocketFactory;
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
 import org.apache.http.conn.scheme.SchemeSocketFactory;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.impl.conn.SchemeRegistryFactory;
 import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.params.BasicHttpParams;
@@ -73,76 +72,30 @@ import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Tests for <code>PoolingClientConnectionManager</code> that do require a server
+ * Tests for <code>PoolingHttpClientConnectionManager</code> that do require a server
  * to communicate with.
  */
-public class TestPoolingConnManager extends LocalServerTestBase {
+public class TestConnectionManagement extends LocalServerTestBase {
 
-    @Before 
+    @Before
     public void setup() throws Exception {
         startServer();
     }
-    
-    /**
-     * Tests executing several requests in parallel.
-     */
-    @Test
-    public void testParallelRequests() throws Exception {
-        // 3.x: TestHttpConnectionManager.testGetFromMultipleThreads
-
-        final int COUNT = 8; // adjust to execute more requests
-
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
-        mgr.setMaxTotal(COUNT/2);
-        mgr.setDefaultMaxPerRoute(COUNT/2);
-
-        final HttpHost target = getServerHttp();
-        final HttpRoute route = new HttpRoute(target, null, false);
-        final int      rsplen = 8;
-        final String      uri = "/random/" + rsplen;
-
-        ExecReqThread[] threads = new ExecReqThread [COUNT];
-        for (int i=0; i<COUNT; i++) {
-            HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
-            threads[i] = new ExecReqThread(request, route, mgr, 5000L);
-        }
-
-        for (int i=0; i<threads.length; i++) {
-            threads[i].start();
-        }
-
-        for (int i=0; i<threads.length; i++) {
-            threads[i].join(10000);
-            Assert.assertNull("exception in thread " + i,
-                       threads[i].getException());
-            Assert.assertNotNull("no response in thread " + i,
-                          threads[i].getResponse());
-            Assert.assertEquals("wrong status code in thread " + i, 200,
-                         threads[i].getResponse()
-                         .getStatusLine().getStatusCode());
-            Assert.assertNotNull("no response data in thread " + i,
-                          threads[i].getResponseData());
-            Assert.assertEquals("wrong length of data in thread" + i, rsplen,
-                         threads[i].getResponseData().length);
-        }
 
-        mgr.shutdown();
-    }
-
-    private static ManagedClientConnection getConnection(
-            final ClientConnectionManager mgr,
+    private static HttpClientConnection getConnection(
+            final HttpClientConnectionManager mgr,
             final HttpRoute route,
             long timeout,
             TimeUnit unit) throws ConnectionPoolTimeoutException, InterruptedException {
-        ClientConnectionRequest connRequest = mgr.requestConnection(route, null);
-        return connRequest.getConnection(timeout, unit);
+        ConnectionRequest connRequest = mgr.requestConnection(route, null);
+        return connRequest.get(timeout, unit);
     }
 
-    private static ManagedClientConnection getConnection(
-            final ClientConnectionManager mgr,
+    private static HttpClientConnection getConnection(
+            final HttpClientConnectionManager mgr,
             final HttpRoute route) throws ConnectionPoolTimeoutException, InterruptedException {
-        ClientConnectionRequest connRequest = mgr.requestConnection(route, null);
-        return connRequest.getConnection(0, null);
+        ConnectionRequest connRequest = mgr.requestConnection(route, null);
+        return connRequest.get(0, null);
     }
 
     /**
@@ -151,7 +104,7 @@ public class TestPoolingConnManager exte
     @Test
     public void testReleaseConnection() throws Exception {
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
 
         HttpHost target = getServerHttp();
@@ -162,16 +115,16 @@ public class TestPoolingConnManager exte
         HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
         HttpContext context = new BasicHttpContext();
         HttpParams params = new BasicHttpParams();
-        
-        ManagedClientConnection conn = getConnection(mgr, route);
-        conn.open(route, context, params);
+
+        HttpClientConnection conn = getConnection(mgr, route);
+        mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
 
         context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
 
         HttpProcessor httpProcessor = new ImmutableHttpProcessor(
                 new HttpRequestInterceptor[] { new RequestContent(), new RequestConnControl() });
-        
+
         HttpRequestExecutor exec = new HttpRequestExecutor();
         exec.preProcess(request, httpProcessor, context);
         HttpResponse response = exec.execute(request, conn, context);
@@ -193,13 +146,12 @@ public class TestPoolingConnManager exte
             // expected
         }
 
-        // release connection without marking for re-use
-        // expect the next connection obtained to be closed
-        mgr.releaseConnection(conn, -1, null);
+        conn.close();
+        mgr.releaseConnection(conn, null, -1, null);
         conn = getConnection(mgr, route);
         Assert.assertFalse("connection should have been closed", conn.isOpen());
 
-        conn.open(route, context, params);
+        mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
 
         // repeat the communication, no need to prepare the request again
         context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
@@ -215,8 +167,7 @@ public class TestPoolingConnManager exte
 
         // release connection after marking it for re-use
         // expect the next connection obtained to be open
-        conn.markReusable();
-        mgr.releaseConnection(conn, -1, null);
+        mgr.releaseConnection(conn, null, -1, null);
         conn = getConnection(mgr, route);
         Assert.assertTrue("connection should have been open", conn.isOpen());
 
@@ -232,7 +183,7 @@ public class TestPoolingConnManager exte
                      rsplen, data.length);
         // ignore data, but it must be read
 
-        mgr.releaseConnection(conn, -1, null);
+        mgr.releaseConnection(conn, null, -1, null);
         mgr.shutdown();
     }
 
@@ -242,7 +193,7 @@ public class TestPoolingConnManager exte
     @Test
     public void testReleaseConnectionWithTimeLimits() throws Exception {
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
 
         HttpHost target = getServerHttp();
@@ -254,15 +205,15 @@ public class TestPoolingConnManager exte
         HttpContext context = new BasicHttpContext();
         HttpParams params = new BasicHttpParams();
 
-        ManagedClientConnection conn = getConnection(mgr, route);
-        conn.open(route, context, params);
+        HttpClientConnection conn = getConnection(mgr, route);
+        mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
 
         context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
 
         HttpProcessor httpProcessor = new ImmutableHttpProcessor(
                 new HttpRequestInterceptor[] { new RequestContent(), new RequestConnControl() });
-        
+
         HttpRequestExecutor exec = new HttpRequestExecutor();
         exec.preProcess(request, httpProcessor, context);
         HttpResponse response = exec.execute(request, conn, context);
@@ -284,15 +235,14 @@ public class TestPoolingConnManager exte
             // expected
         }
 
-        // release connection without marking for re-use
-        // expect the next connection obtained to be closed
-        mgr.releaseConnection(conn, 100, TimeUnit.MILLISECONDS);
+        conn.close();
+        mgr.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
         conn = getConnection(mgr, route);
         Assert.assertFalse("connection should have been closed", conn.isOpen());
 
         // repeat the communication, no need to prepare the request again
-        conn.open(route, context, params);
-        
+        mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
+
         context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
         response = exec.execute(request, conn, context);
 
@@ -304,10 +254,7 @@ public class TestPoolingConnManager exte
                      rsplen, data.length);
         // ignore data, but it must be read
 
-        // release connection after marking it for re-use
-        // expect the next connection obtained to be open
-        conn.markReusable();
-        mgr.releaseConnection(conn, 100, TimeUnit.MILLISECONDS);
+        mgr.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
         conn = getConnection(mgr, route);
         Assert.assertTrue("connection should have been open", conn.isOpen());
 
@@ -323,15 +270,14 @@ public class TestPoolingConnManager exte
                      rsplen, data.length);
         // ignore data, but it must be read
 
-        conn.markReusable();
-        mgr.releaseConnection(conn, 100, TimeUnit.MILLISECONDS);
+        mgr.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
         Thread.sleep(150);
         conn = getConnection(mgr, route);
         Assert.assertTrue("connection should have been closed", !conn.isOpen());
 
         // repeat the communication, no need to prepare the request again
-        conn.open(route, context, params);
-        
+        mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
+
         context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
         response = exec.execute(request, conn, context);
 
@@ -349,7 +295,7 @@ public class TestPoolingConnManager exte
     @Test
     public void testCloseExpiredIdleConnections() throws Exception {
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
 
         HttpHost target = getServerHttp();
@@ -357,13 +303,13 @@ public class TestPoolingConnManager exte
         HttpContext context = new BasicHttpContext();
         HttpParams params = new BasicHttpParams();
 
-        ManagedClientConnection conn = getConnection(mgr, route);
-        conn.open(route, context, params);
+        HttpClientConnection conn = getConnection(mgr, route);
+        mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
 
         Assert.assertEquals(1, mgr.getTotalStats().getLeased());
         Assert.assertEquals(1, mgr.getStats(route).getLeased());
-        conn.markReusable();
-        mgr.releaseConnection(conn, 100, TimeUnit.MILLISECONDS);
+
+        mgr.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
 
         // Released, still active.
         Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
@@ -389,7 +335,7 @@ public class TestPoolingConnManager exte
     @Test
     public void testCloseExpiredTTLConnections() throws Exception {
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(
                 SchemeRegistryFactory.createDefault(), 100, TimeUnit.MILLISECONDS);
         mgr.setMaxTotal(1);
 
@@ -398,14 +344,13 @@ public class TestPoolingConnManager exte
         HttpContext context = new BasicHttpContext();
         HttpParams params = new BasicHttpParams();
 
-        ManagedClientConnection conn = getConnection(mgr, route);
-        conn.open(route, context, params);
+        HttpClientConnection conn = getConnection(mgr, route);
+        mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
 
         Assert.assertEquals(1, mgr.getTotalStats().getLeased());
         Assert.assertEquals(1, mgr.getStats(route).getLeased());
         // Release, let remain idle for forever
-        conn.markReusable();
-        mgr.releaseConnection(conn, -1, TimeUnit.MILLISECONDS);
+        mgr.releaseConnection(conn, null, -1, TimeUnit.MILLISECONDS);
 
         // Released, still active.
         Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
@@ -435,7 +380,7 @@ public class TestPoolingConnManager exte
     @Test
     public void testReleaseConnectionOnAbort() throws Exception {
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
+        PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
         mgr.setMaxTotal(1);
 
         HttpHost target = getServerHttp();
@@ -448,15 +393,15 @@ public class TestPoolingConnManager exte
         HttpRequest request =
             new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
 
-        ManagedClientConnection conn = getConnection(mgr, route);
-        conn.open(route, context, params);
+        HttpClientConnection conn = getConnection(mgr, route);
+        mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
 
         context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
 
         HttpProcessor httpProcessor = new ImmutableHttpProcessor(
                 new HttpRequestInterceptor[] { new RequestContent(), new RequestConnControl() });
-        
+
         HttpRequestExecutor exec = new HttpRequestExecutor();
         exec.preProcess(request, httpProcessor, context);
         HttpResponse response = exec.execute(request, conn, context);
@@ -475,14 +420,15 @@ public class TestPoolingConnManager exte
         }
 
         // abort the connection
-        Assert.assertTrue(conn instanceof ManagedClientConnection);
-        ((ManagedClientConnection) conn).abortConnection();
+        Assert.assertTrue(conn instanceof HttpClientConnection);
+        conn.shutdown();
+        mgr.releaseConnection(conn, null, -1, null);
 
         // the connection is expected to be released back to the manager
         conn = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
         Assert.assertFalse("connection should have been closed", conn.isOpen());
 
-        mgr.releaseConnection(conn, -1, null);
+        mgr.releaseConnection(conn, null, -1, null);
         mgr.shutdown();
     }
 
@@ -495,7 +441,7 @@ public class TestPoolingConnManager exte
         SchemeRegistry registry = new SchemeRegistry();
         registry.register(scheme);
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(registry);
+        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(registry);
         mgr.setMaxTotal(1);
 
         HttpHost target = getServerHttp();
@@ -503,14 +449,15 @@ public class TestPoolingConnManager exte
         HttpContext context = new BasicHttpContext();
         HttpParams params = new BasicHttpParams();
 
-        final ManagedClientConnection conn = getConnection(mgr, route);
+        final HttpClientConnection conn = getConnection(mgr, route);
 
         final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
         Thread abortingThread = new Thread(new Runnable() {
             public void run() {
                 try {
                     stallingSocketFactory.waitForState();
-                    conn.abortConnection();
+                    conn.shutdown();
+                    mgr.releaseConnection(conn, null, -1, null);
                     connectLatch.countDown();
                 } catch (Throwable e) {
                     throwRef.set(e);
@@ -520,7 +467,7 @@ public class TestPoolingConnManager exte
         abortingThread.start();
 
         try {
-            conn.open(route, context, params);
+            mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
             Assert.fail("expected SocketException");
         } catch(SocketException expected) {}
 
@@ -532,10 +479,10 @@ public class TestPoolingConnManager exte
         Assert.assertEquals(0, localServer.getAcceptedConnectionCount());
 
         // the connection is expected to be released back to the manager
-        ManagedClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
+        HttpClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
         Assert.assertFalse("connection should have been closed", conn2.isOpen());
 
-        mgr.releaseConnection(conn2, -1, null);
+        mgr.releaseConnection(conn2, null, -1, null);
         mgr.shutdown();
     }
 
@@ -548,7 +495,7 @@ public class TestPoolingConnManager exte
         SchemeRegistry registry = new SchemeRegistry();
         registry.register(scheme);
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(registry);
+        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(registry);
         mgr.setMaxTotal(1);
 
         HttpHost target = getServerHttp();
@@ -556,14 +503,15 @@ public class TestPoolingConnManager exte
         HttpContext context = new BasicHttpContext();
         HttpParams params = new BasicHttpParams();
 
-        final ManagedClientConnection conn = getConnection(mgr, route);
+        final HttpClientConnection conn = getConnection(mgr, route);
 
         final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
         Thread abortingThread = new Thread(new Runnable() {
             public void run() {
                 try {
                     stallingSocketFactory.waitForState();
-                    conn.abortConnection();
+                    conn.shutdown();
+                    mgr.releaseConnection(conn, null, -1, null);
                     connectLatch.countDown();
                 } catch (Throwable e) {
                     throwRef.set(e);
@@ -573,7 +521,7 @@ public class TestPoolingConnManager exte
         abortingThread.start();
 
         try {
-            conn.open(route, context, params);
+            mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
             Assert.fail("expected exception");
         } catch(IOException expected) {
             Assert.assertEquals("Connection already shutdown", expected.getMessage());
@@ -587,10 +535,10 @@ public class TestPoolingConnManager exte
         Assert.assertEquals(0, localServer.getAcceptedConnectionCount());
 
         // the connection is expected to be released back to the manager
-        ManagedClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
+        HttpClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
         Assert.assertFalse("connection should have been closed", conn2.isOpen());
 
-        mgr.releaseConnection(conn2, -1, null);
+        mgr.releaseConnection(conn2, null, -1, null);
         mgr.shutdown();
     }
 
@@ -603,7 +551,7 @@ public class TestPoolingConnManager exte
         SchemeRegistry registry = new SchemeRegistry();
         registry.register(scheme);
 
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(registry);
+        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(registry);
         mgr.setMaxTotal(1);
 
         HttpHost target = getServerHttp();
@@ -611,14 +559,15 @@ public class TestPoolingConnManager exte
         HttpContext context = new BasicHttpContext();
         HttpParams params = new BasicHttpParams();
 
-        final ManagedClientConnection conn = getConnection(mgr, route);
+        final HttpClientConnection conn = getConnection(mgr, route);
 
         final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
         Thread abortingThread = new Thread(new Runnable() {
             public void run() {
                 try {
                     stallingSocketFactory.waitForState();
-                    conn.abortConnection();
+                    conn.shutdown();
+                    mgr.releaseConnection(conn, null, -1, null);
                     connectLatch.countDown();
                 } catch (Throwable e) {
                     throwRef.set(e);
@@ -628,7 +577,7 @@ public class TestPoolingConnManager exte
         abortingThread.start();
 
         try {
-            conn.open(route, context, params);
+            mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context, params);
             Assert.fail("expected SocketException");
         } catch(SocketException expected) {}
 
@@ -647,79 +596,15 @@ public class TestPoolingConnManager exte
         Assert.assertEquals(1, localServer.getAcceptedConnectionCount());
 
         // the connection is expected to be released back to the manager
-        ManagedClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
+        HttpClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
         Assert.assertFalse("connection should have been closed", conn2.isOpen());
 
-        mgr.releaseConnection(conn2, -1, null);
+        mgr.releaseConnection(conn2, null, -1, null);
         mgr.shutdown();
     }
 
-    @Test
-    public void testAbortAfterOperatorOpen() throws Exception {
-        final CountDownLatch connectLatch = new CountDownLatch(1);
-        final AtomicReference<StallingOperator> operatorRef = new AtomicReference<StallingOperator>();
-
-        PoolingClientConnectionManager mgr = new PoolingClientConnectionManager() {
-            @Override
-            protected ClientConnectionOperator createConnectionOperator(
-                    SchemeRegistry schreg) {
-                operatorRef.set(new StallingOperator(connectLatch, WaitPolicy.AFTER_OPEN, super.createConnectionOperator(schreg)));
-                return operatorRef.get();
-            }
-        };
-        mgr.setMaxTotal(1);
-        Assert.assertNotNull(operatorRef.get());
-
-        HttpHost target = getServerHttp();
-        HttpRoute route = new HttpRoute(target, null, false);
-        HttpContext context = new BasicHttpContext();
-        HttpParams params = new BasicHttpParams();
-
-        final ManagedClientConnection conn = getConnection(mgr, route);
-
-        final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
-        Thread abortingThread = new Thread(new Runnable() {
-            public void run() {
-                try {
-                    operatorRef.get().waitForState();
-                    conn.abortConnection();
-                    connectLatch.countDown();
-                } catch (Throwable e) {
-                    throwRef.set(e);
-                }
-            }
-        });
-        abortingThread.start();
-
-        try {
-            conn.open(route, context, params);
-            Assert.fail("expected exception");
-        } catch(IOException iox) {
-        }
-
-        abortingThread.join(5000);
-        if(throwRef.get() != null)
-            throw new RuntimeException(throwRef.get());
-
-        Assert.assertFalse(conn.isOpen());
-        // Give the server a bit of time to accept the connection, but
-        // ensure that it can accept it.
-        for(int i = 0; i < 10; i++) {
-            if(localServer.getAcceptedConnectionCount() == 1)
-                break;
-            Thread.sleep(100);
-        }
-        Assert.assertEquals(1, localServer.getAcceptedConnectionCount());
+    static class LatchSupport {
 
-        // the connection is expected to be released back to the manager
-        ManagedClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
-        Assert.assertFalse("connection should have been closed", conn2.isOpen());
-
-        mgr.releaseConnection(conn2, -1, null);
-        mgr.shutdown();
-    }
-
-    private static class LatchSupport {
         private final CountDownLatch continueLatch;
         private final CountDownLatch waitLatch = new CountDownLatch(1);
         protected final WaitPolicy waitPolicy;
@@ -745,34 +630,6 @@ public class TestPoolingConnManager exte
         }
     }
 
-    private static class StallingOperator extends LatchSupport implements ClientConnectionOperator {
-        private final ClientConnectionOperator delegate;
-
-        public StallingOperator(CountDownLatch continueLatch,
-                WaitPolicy waitPolicy, ClientConnectionOperator delegate) {
-            super(continueLatch, waitPolicy);
-            this.delegate = delegate;
-        }
-
-        public OperatedClientConnection createConnection() {
-            return delegate.createConnection();
-        }
-
-        public void openConnection(OperatedClientConnection conn,
-                HttpHost target, InetAddress local, HttpContext context,
-                HttpParams params) throws IOException {
-            delegate.openConnection(conn, target, local, context, params);
-            if(waitPolicy == WaitPolicy.AFTER_OPEN)
-                latch();
-        }
-
-        public void updateSecureConnection(OperatedClientConnection conn,
-                HttpHost target, HttpContext context, HttpParams params)
-                throws IOException {
-            delegate.updateSecureConnection(conn, target, context, params);
-        }
-    }
-
     private static class StallingSocketFactory extends LatchSupport implements SchemeSocketFactory {
 
         private final SchemeSocketFactory delegate;

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message