Top Description Inners Fields Constructors Methods
org.apache.http.impl.conn

public Class PoolingHttpClientConnectionManager

extends Object
implements HttpClientConnectionManager, ConnPoolControl<HttpRoute>, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, org.apache.http.pool.ConnPoolControl, org.apache.http.conn.HttpClientConnectionManager
Annotations
@Contract
threading:SAFE_CONDITIONAL
Imports
java.io.Closeable, .IOException, java.util.Map, .Set, java.util.concurrent.CancellationException, .ConcurrentHashMap, .ExecutionException, .Future, .TimeUnit, .TimeoutException, java.util.concurrent.atomic.AtomicBoolean, org.apache.commons.logging.Log, .LogFactory, org.apache.http.HttpClientConnection, .HttpHost, org.apache.http.annotation.Contract, .ThreadingBehavior, org.apache.http.config.ConnectionConfig, .Lookup, .Registry, .RegistryBuilder, .SocketConfig, org.apache.http.conn.ConnectionPoolTimeoutException, .ConnectionRequest, .DnsResolver, .HttpClientConnectionManager, .HttpClientConnectionOperator, .HttpConnectionFactory, .ManagedHttpClientConnection, .SchemePortResolver, org.apache.http.conn.routing.HttpRoute, org.apache.http.conn.socket.ConnectionSocketFactory, .PlainConnectionSocketFactory, org.apache.http.conn.ssl.SSLConnectionSocketFactory, org.apache.http.pool.ConnFactory, .ConnPoolControl, .PoolEntry, .PoolEntryCallback, .PoolStats, org.apache.http.protocol.HttpContext, org.apache.http.util.Args, .Asserts

ClientConnectionPoolManager maintains a pool of 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.

Total time to live (TTL) set at construction time defines maximum life span of persistent connections regardless of their expiration setting. No persistent connection will be re-used past its TTL value.

The handling of stale connections was changed in version 4.4. Previously, the code would check every connection by default before re-using it. The code now only checks the connection if the elapsed time since the last use of the connection exceeds the timeout that has been set. The default timeout is set to 2000ms

Since
4.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final PoolingHttpClientConnectionManager.ConfigData
private final HttpClientConnectionOperator
private final AtomicBoolean
private final Log
private final CPool

Constructor Summary

AccessConstructor and Description
public
public
PoolingHttpClientConnectionManager(final long timeToLive, final TimeUnit timeUnit)

public
public
PoolingHttpClientConnectionManager(final Registry<ConnectionSocketFactory> socketFactoryRegistry, final DnsResolver dnsResolver)

public
public
public
public
PoolingHttpClientConnectionManager(final Registry<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver, final long timeToLive, final TimeUnit timeUnit)

public
PoolingHttpClientConnectionManager(final HttpClientConnectionOperator httpClientConnectionOperator, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final long timeToLive, final TimeUnit timeUnit)

pack-priv
PoolingHttpClientConnectionManager(final CPool pool, final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver)

Visible for test.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
public void
public void
closeIdleConnections(final long
the idle time of connections to be closed
idleTimeout
,
final TimeUnit
the unit for the idletime
timeUnit
)

Implements org.apache.http.conn.HttpClientConnectionManager.closeIdleConnections.

Closes idle connections in the pool.
public void
connect(final HttpClientConnection
the managed connection.
managedConn
,
final HttpRoute
the route of the connection.
route
,
final int
connect timeout in milliseconds.
connectTimeout
,
final HttpContext
the actual HTTP context.
context
)

Implements org.apache.http.conn.HttpClientConnectionManager.connect.

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
protected void
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
private String
format(final HttpRoute route, final Object state)

private String
format(final CPoolEntry entry)

private String
formatStats(final HttpRoute route)

public ConnectionConfig
public ConnectionConfig
public int
private static Registry<ConnectionSocketFactory>
public SocketConfig
public int
public int
public Set<HttpRoute>
public SocketConfig
public PoolStats
public PoolStats
public int
protected HttpClientConnection
leaseConnection(final Future<CPoolEntry> future, final long timeout, final TimeUnit timeUnit)

public void
releaseConnection(final HttpClientConnection
the managed connection to release.
managedConn
,
final Object state, final long
the duration of time this connection is valid for reuse.
keepalive
,
final TimeUnit
the time unit.
timeUnit
)

Implements org.apache.http.conn.HttpClientConnectionManager.releaseConnection.

Releases the connection back to the manager making it potentially re-usable by other consumers.
public ConnectionRequest
requestConnection(final HttpRoute
HTTP route of the requested connection.
route
,
final Object
expected state of the connection or null if the connection is not expected to carry any state.
state
)

Implements org.apache.http.conn.HttpClientConnectionManager.requestConnection.

Returns a new ConnectionRequest, from which a HttpClientConnection can be obtained or the request can be aborted.
private SocketConfig
public void
routeComplete(final HttpClientConnection
the managed connection.
managedConn
,
final HttpRoute
the route of the connection.
route
,
final HttpContext
the actual HTTP context.
context
)

Implements org.apache.http.conn.HttpClientConnectionManager.routeComplete.

Marks the connection as fully established with all its intermediate hops completed.
public void
setConnectionConfig(final HttpHost host, final ConnectionConfig connectionConfig)

public void
setDefaultConnectionConfig(final ConnectionConfig defaultConnectionConfig)

public void
public void
setDefaultSocketConfig(final SocketConfig defaultSocketConfig)

public void
public void
public void
setSocketConfig(final HttpHost host, final SocketConfig socketConfig)

public void
setValidateAfterInactivity(final int ms)

Defines period of inactivity in milliseconds after which persistent connections must be re-validated prior to being leased to the consumer.

public void
shutdown()

Implements org.apache.http.conn.HttpClientConnectionManager.shutdown.

Shuts down this connection manager and releases allocated resources.
public void
upgrade(final HttpClientConnection
the managed connection.
managedConn
,
final HttpRoute
the route of the connection.
route
,
final HttpContext
the actual HTTP context.
context
)

Implements org.apache.http.conn.HttpClientConnectionManager.upgrade.

Upgrades the underlying connection socket to TLS/SSL (or another layering protocol) after having executed CONNECT method to all intermediate proxy hops
Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait