@ThreadSafe public class PoolingHttpClientConnectionManager extends java.lang.Object implements HttpClientConnectionManager, ConnPoolControl<HttpRoute>, java.io.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.| 限定符和类型 | 方法和说明 |
|---|---|
void |
close() |
void |
closeExpiredConnections()
Closes all expired connections in the pool.
|
void |
closeIdleConnections(long idleTimeout,
java.util.concurrent.TimeUnit tunit)
Closes idle connections in the pool.
|
void |
connect(HttpClientConnection managedConn,
HttpRoute route,
int connectTimeout,
HttpContext context)
Connects the underlying connection socket to the connection target in case
of a direct route or to the first proxy hop in case of a route via a proxy
(or multiple proxies).
|
protected void |
finalize() |
ConnectionConfig |
getConnectionConfig(HttpHost host) |
ConnectionConfig |
getDefaultConnectionConfig() |
int |
getDefaultMaxPerRoute() |
SocketConfig |
getDefaultSocketConfig() |
int |
getMaxPerRoute(HttpRoute route) |
int |
getMaxTotal() |
SocketConfig |
getSocketConfig(HttpHost host) |
PoolStats |
getStats(HttpRoute route) |
PoolStats |
getTotalStats() |
protected HttpClientConnection |
leaseConnection(java.util.concurrent.Future<depends.org.apache.http.impl.conn.CPoolEntry> future,
long timeout,
java.util.concurrent.TimeUnit tunit) |
void |
releaseConnection(HttpClientConnection managedConn,
java.lang.Object state,
long keepalive,
java.util.concurrent.TimeUnit tunit)
Releases the connection back to the manager making it potentially
re-usable by extension consumers.
|
ConnectionRequest |
requestConnection(HttpRoute route,
java.lang.Object state)
Returns a new
ConnectionRequest, from which a
HttpClientConnection can be obtained or the request can be
aborted. |
void |
routeComplete(HttpClientConnection managedConn,
HttpRoute route,
HttpContext context)
Marks the connection as fully established with all its intermediate
hops completed.
|
void |
setConnectionConfig(HttpHost host,
ConnectionConfig connectionConfig) |
void |
setDefaultConnectionConfig(ConnectionConfig defaultConnectionConfig) |
void |
setDefaultMaxPerRoute(int max) |
void |
setDefaultSocketConfig(SocketConfig defaultSocketConfig) |
void |
setMaxPerRoute(HttpRoute route,
int max) |
void |
setMaxTotal(int max) |
void |
setSocketConfig(HttpHost host,
SocketConfig socketConfig) |
void |
shutdown()
Shuts down this connection manager and releases tlb resources.
|
void |
upgrade(HttpClientConnection managedConn,
HttpRoute route,
HttpContext context)
Upgrades the underlying connection socket to TLS/SSL (or another layering
protocol) after having executed
CONNECT method to all
intermediate proxy hops |
public PoolingHttpClientConnectionManager()
public PoolingHttpClientConnectionManager(long timeToLive,
java.util.concurrent.TimeUnit tunit)
public PoolingHttpClientConnectionManager(Registry<ConnectionSocketFactory> socketFactoryRegistry)
public PoolingHttpClientConnectionManager(Registry<ConnectionSocketFactory> socketFactoryRegistry, DnsResolver dnsResolver)
public PoolingHttpClientConnectionManager(Registry<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory)
public PoolingHttpClientConnectionManager(HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory)
public PoolingHttpClientConnectionManager(Registry<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory, DnsResolver dnsResolver)
public PoolingHttpClientConnectionManager(Registry<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver, long timeToLive, java.util.concurrent.TimeUnit tunit)
protected void finalize()
throws java.lang.Throwable
finalize 在类中 java.lang.Objectjava.lang.Throwablepublic void close()
close 在接口中 java.io.Closeableclose 在接口中 java.lang.AutoCloseablepublic ConnectionRequest requestConnection(HttpRoute route, java.lang.Object state)
HttpClientConnectionManagerConnectionRequest, from which a
HttpClientConnection can be obtained or the request can be
aborted.
Please note that newly tlb connections can be returned
in the closed state. The consumer of that connection is responsible
for fully establishing the route the to the connection target
by calling connect in order to connect
directly to the target or to the first proxy hop, optionally calling
upgrade method to upgrade
the connection after having executed CONNECT method to
all intermediate proxy hops and and finally calling routeComplete to mark the route
as fully completed.requestConnection 在接口中 HttpClientConnectionManagerroute - HTTP route of the requested connection.state - expected state of the connection or null
if the connection is not expected to carry any state.protected HttpClientConnection leaseConnection(java.util.concurrent.Future<depends.org.apache.http.impl.conn.CPoolEntry> future, long timeout, java.util.concurrent.TimeUnit tunit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, ConnectionPoolTimeoutException
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionConnectionPoolTimeoutExceptionpublic void releaseConnection(HttpClientConnection managedConn, java.lang.Object state, long keepalive, java.util.concurrent.TimeUnit tunit)
HttpClientConnectionManagervalidDuration and timeUnit
parameters.releaseConnection 在接口中 HttpClientConnectionManagermanagedConn - the managed connection to release.keepalive - the duration of time this connection is valid for reuse.tunit - the time unit.HttpClientConnectionManager.closeExpiredConnections()public void connect(HttpClientConnection managedConn, HttpRoute route, int connectTimeout, HttpContext context) throws java.io.IOException
HttpClientConnectionManagerconnect 在接口中 HttpClientConnectionManagermanagedConn - the managed connection.route - the route of the connection.connectTimeout - connect timeout in milliseconds.context - the actual HTTP context.java.io.IOExceptionpublic void upgrade(HttpClientConnection managedConn, HttpRoute route, HttpContext context) throws java.io.IOException
HttpClientConnectionManagerCONNECT method to all
intermediate proxy hopsupgrade 在接口中 HttpClientConnectionManagermanagedConn - the managed connection.route - the route of the connection.context - the actual HTTP context.java.io.IOExceptionpublic void routeComplete(HttpClientConnection managedConn, HttpRoute route, HttpContext context) throws java.io.IOException
HttpClientConnectionManagerrouteComplete 在接口中 HttpClientConnectionManagermanagedConn - the managed connection.route - the route of the connection.context - the actual HTTP context.java.io.IOExceptionpublic void shutdown()
HttpClientConnectionManagershutdown 在接口中 HttpClientConnectionManagerpublic void closeIdleConnections(long idleTimeout,
java.util.concurrent.TimeUnit tunit)
HttpClientConnectionManagercloseIdleConnections 在接口中 HttpClientConnectionManageridleTimeout - the idle time of connections to be closedtunit - the unit for the idletimeHttpClientConnectionManager.closeExpiredConnections()public void closeExpiredConnections()
HttpClientConnectionManagerpublic int getMaxTotal()
getMaxTotal 在接口中 ConnPoolControl<HttpRoute>public void setMaxTotal(int max)
setMaxTotal 在接口中 ConnPoolControl<HttpRoute>public int getDefaultMaxPerRoute()
getDefaultMaxPerRoute 在接口中 ConnPoolControl<HttpRoute>public void setDefaultMaxPerRoute(int max)
setDefaultMaxPerRoute 在接口中 ConnPoolControl<HttpRoute>public int getMaxPerRoute(HttpRoute route)
getMaxPerRoute 在接口中 ConnPoolControl<HttpRoute>public void setMaxPerRoute(HttpRoute route, int max)
setMaxPerRoute 在接口中 ConnPoolControl<HttpRoute>public PoolStats getTotalStats()
getTotalStats 在接口中 ConnPoolControl<HttpRoute>public PoolStats getStats(HttpRoute route)
getStats 在接口中 ConnPoolControl<HttpRoute>public SocketConfig getDefaultSocketConfig()
public void setDefaultSocketConfig(SocketConfig defaultSocketConfig)
public ConnectionConfig getDefaultConnectionConfig()
public void setDefaultConnectionConfig(ConnectionConfig defaultConnectionConfig)
public SocketConfig getSocketConfig(HttpHost host)
public void setSocketConfig(HttpHost host, SocketConfig socketConfig)
public ConnectionConfig getConnectionConfig(HttpHost host)
public void setConnectionConfig(HttpHost host, ConnectionConfig connectionConfig)