@ThreadSafe public class PoolingHttpClientConnectionManager extends Object implements HttpClientConnectionManager, ConnPoolControl<HttpRoute>, Closeable
HttpClientConnections 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.
ClientConnectionPoolManager 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 ConnPoolControl methods.public PoolingHttpClientConnectionManager()
public PoolingHttpClientConnectionManager(long timeToLive,
TimeUnit tunit)
public PoolingHttpClientConnectionManager(org.apache.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry)
public PoolingHttpClientConnectionManager(org.apache.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, DnsResolver dnsResolver)
public PoolingHttpClientConnectionManager(org.apache.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<ManagedHttpClientConnection> connFactory)
public PoolingHttpClientConnectionManager(HttpConnectionFactory<ManagedHttpClientConnection> connFactory)
public PoolingHttpClientConnectionManager(org.apache.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<ManagedHttpClientConnection> connFactory, DnsResolver dnsResolver)
public PoolingHttpClientConnectionManager(org.apache.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver, long timeToLive, TimeUnit tunit)
protected void finalize()
throws Throwable
public void close()
close in interface Closeableclose in interface AutoCloseablepublic ConnectionRequest requestConnection(HttpRoute route, Object state)
HttpClientConnectionManagerClientConnectionRequest, from which a
HttpClientConnection can be obtained or the request can be
aborted.requestConnection in interface HttpClientConnectionManagerprotected HttpClientConnection leaseConnection(Future<org.apache.http.impl.conn.CPoolEntry> future, long timeout, TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException
public void releaseConnection(HttpClientConnection managedConn, Object state, long keepalive, TimeUnit tunit)
HttpClientConnectionManagerreleaseConnection in interface HttpClientConnectionManagermanagedConn - the connection to releasekeepalive - the duration of time this connection is valid for reusetunit - the unit of time validDuration is measured inHttpClientConnectionManager.closeExpiredConnections()public void connect(HttpClientConnection managedConn, HttpRoute route, int connectTimeout, HttpContext context) throws IOException
connect in interface HttpClientConnectionManagerIOExceptionpublic void upgrade(HttpClientConnection managedConn, HttpRoute route, HttpContext context) throws IOException
upgrade in interface HttpClientConnectionManagerIOExceptionpublic void routeComplete(HttpClientConnection managedConn, HttpRoute route, HttpContext context) throws IOException
routeComplete in interface HttpClientConnectionManagerIOExceptionpublic void shutdown()
HttpClientConnectionManagershutdown in interface HttpClientConnectionManagerpublic void closeIdleConnections(long idleTimeout,
TimeUnit tunit)
HttpClientConnectionManagercloseIdleConnections in interface HttpClientConnectionManageridleTimeout - the idle time of connections to be closedtunit - the unit for the idletimeHttpClientConnectionManager.closeExpiredConnections()public void closeExpiredConnections()
HttpClientConnectionManagercloseExpiredConnections in interface HttpClientConnectionManagerpublic int getMaxTotal()
getMaxTotal in interface ConnPoolControl<HttpRoute>public void setMaxTotal(int max)
setMaxTotal in interface ConnPoolControl<HttpRoute>public int getDefaultMaxPerRoute()
getDefaultMaxPerRoute in interface ConnPoolControl<HttpRoute>public void setDefaultMaxPerRoute(int max)
setDefaultMaxPerRoute in interface ConnPoolControl<HttpRoute>public int getMaxPerRoute(HttpRoute route)
getMaxPerRoute in interface ConnPoolControl<HttpRoute>public void setMaxPerRoute(HttpRoute route, int max)
setMaxPerRoute in interface ConnPoolControl<HttpRoute>public PoolStats getTotalStats()
getTotalStats in interface ConnPoolControl<HttpRoute>public PoolStats getStats(HttpRoute route)
getStats in interface ConnPoolControl<HttpRoute>public org.apache.http.config.SocketConfig getDefaultSocketConfig()
public void setDefaultSocketConfig(org.apache.http.config.SocketConfig defaultSocketConfig)
public org.apache.http.config.ConnectionConfig getDefaultConnectionConfig()
public void setDefaultConnectionConfig(org.apache.http.config.ConnectionConfig defaultConnectionConfig)
public org.apache.http.config.SocketConfig getSocketConfig(HttpHost host)
public void setSocketConfig(HttpHost host, org.apache.http.config.SocketConfig socketConfig)
public org.apache.http.config.ConnectionConfig getConnectionConfig(HttpHost host)
public void setConnectionConfig(HttpHost host, org.apache.http.config.ConnectionConfig connectionConfig)
Copyright © 1999-2013 The Apache Software Foundation. All Rights Reserved.