Class PoolingHttpClientConnectionManager
- All Implemented Interfaces:
Closeable, AutoCloseable, HttpClientConnectionManager, org.apache.hc.core5.io.ModalCloseable, org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>, org.apache.hc.core5.pool.ConnPoolStats<HttpRoute>
ClientConnectionPoolManager maintains a pool of
ManagedHttpClientConnections 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 serviced by leasing
a connection from the pool rather than creating a new connection.
ClientConnectionPoolManager maintains a maximum limit of connection
on a per route basis and in total. 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.
- Since:
- 4.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanprivate org.apache.hc.core5.function.Resolver<HttpRoute, ConnectionConfig> private final HttpClientConnectionOperatorprivate final org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> static final intstatic final intprivate static final PrefixedIncrementingIdprivate static final org.slf4j.Loggerprivate final org.apache.hc.core5.pool.ManagedConnPool<HttpRoute, ManagedHttpClientConnection> private org.apache.hc.core5.function.Resolver<HttpRoute, org.apache.hc.core5.http.io.SocketConfig> private org.apache.hc.core5.function.Resolver<org.apache.hc.core5.http.HttpHost, TlsConfig> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPoolingHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, org.apache.hc.core5.pool.ManagedConnPool<HttpRoute, ManagedHttpClientConnection> pool, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) protectedPoolingHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry) PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive) PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive, SchemePortResolver schemePortResolver, DnsResolver dnsResolver, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.util.TimeValue timeToLive, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) -
Method Summary
Modifier and TypeMethodDescriptioncast(ConnectionEndpoint endpoint) voidclose()voidclose(org.apache.hc.core5.io.CloseMode closeMode) voidvoidcloseIdle(org.apache.hc.core5.util.TimeValue idleTime) (package private) voidcloseIfExpired(org.apache.hc.core5.pool.PoolEntry<HttpRoute, ManagedHttpClientConnection> entry) voidconnect(ConnectionEndpoint endpoint, org.apache.hc.core5.util.TimeValue timeout, org.apache.hc.core5.http.protocol.HttpContext context) Connects the endpoint to the initial hop (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).intorg.apache.hc.core5.http.io.SocketConfigDeprecated.intgetMaxPerRoute(HttpRoute route) intorg.apache.hc.core5.pool.PoolStatsorg.apache.hc.core5.pool.PoolStatsorg.apache.hc.core5.util.TimeValueDeprecated.Returns aLeaseRequestobject which can be used to obtain aConnectionEndpointto cancel the request by callingCancellable.cancel().voidrelease(ConnectionEndpoint endpoint, Object state, org.apache.hc.core5.util.TimeValue keepAlive) Releases the endpoint back to the manager making it potentially re-usable by other consumers.private ConnectionConfigresolveConnectionConfig(HttpRoute route) private org.apache.hc.core5.http.io.SocketConfigresolveSocketConfig(HttpRoute route) private TlsConfigresolveTlsConfig(org.apache.hc.core5.http.HttpHost host) private org.apache.hc.core5.util.TimeValueresolveValidateAfterInactivity(ConnectionConfig connectionConfig) voidsetConnectionConfigResolver(org.apache.hc.core5.function.Resolver<HttpRoute, ConnectionConfig> connectionConfigResolver) SetsResolverofConnectionConfigon a per route basis.voidSets the sameConnectionConfigfor all routesvoidsetDefaultMaxPerRoute(int max) voidsetDefaultSocketConfig(org.apache.hc.core5.http.io.SocketConfig config) Sets the sameSocketConfigfor all routesvoidsetDefaultTlsConfig(TlsConfig config) Sets the sameConnectionConfigfor all hostsvoidsetMaxPerRoute(HttpRoute route, int max) voidsetMaxTotal(int max) voidsetSocketConfigResolver(org.apache.hc.core5.function.Resolver<HttpRoute, org.apache.hc.core5.http.io.SocketConfig> socketConfigResolver) SetsResolverofSocketConfigon a per route basis.voidsetTlsConfigResolver(org.apache.hc.core5.function.Resolver<org.apache.hc.core5.http.HttpHost, TlsConfig> tlsConfigResolver) SetsResolverofTlsConfigon a per host basis.voidsetValidateAfterInactivity(org.apache.hc.core5.util.TimeValue validateAfterInactivity) Deprecated.voidupgrade(ConnectionEndpoint endpoint, org.apache.hc.core5.http.protocol.HttpContext context) Upgrades transport security of the given endpoint by using the TLS security protocol.
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
DEFAULT_MAX_TOTAL_CONNECTIONS
public static final int DEFAULT_MAX_TOTAL_CONNECTIONS- See Also:
-
DEFAULT_MAX_CONNECTIONS_PER_ROUTE
public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE- See Also:
-
connectionOperator
-
pool
-
connFactory
private final org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory -
closed
-
socketConfigResolver
private volatile org.apache.hc.core5.function.Resolver<HttpRoute, org.apache.hc.core5.http.io.SocketConfig> socketConfigResolver -
connectionConfigResolver
private volatile org.apache.hc.core5.function.Resolver<HttpRoute, ConnectionConfig> connectionConfigResolver -
tlsConfigResolver
private volatile org.apache.hc.core5.function.Resolver<org.apache.hc.core5.http.HttpHost, TlsConfig> tlsConfigResolver -
INCREMENTING_ID
-
-
Constructor Details
-
PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager() -
PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry) -
PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) -
PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.util.TimeValue timeToLive, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) -
PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive) -
PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) -
PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager(org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive, SchemePortResolver schemePortResolver, DnsResolver dnsResolver, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) -
PoolingHttpClientConnectionManager
@Internal protected PoolingHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) -
PoolingHttpClientConnectionManager
@Internal protected PoolingHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, org.apache.hc.core5.pool.ManagedConnPool<HttpRoute, ManagedHttpClientConnection> pool, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory)
-
-
Method Details
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
close
public void close(org.apache.hc.core5.io.CloseMode closeMode) - Specified by:
closein interfaceorg.apache.hc.core5.io.ModalCloseable
-
cast
private PoolingHttpClientConnectionManager.InternalConnectionEndpoint cast(ConnectionEndpoint endpoint) -
resolveSocketConfig
-
resolveConnectionConfig
-
resolveTlsConfig
-
resolveValidateAfterInactivity
private org.apache.hc.core5.util.TimeValue resolveValidateAfterInactivity(ConnectionConfig connectionConfig) -
lease
-
lease
public LeaseRequest lease(String id, HttpRoute route, org.apache.hc.core5.util.Timeout requestTimeout, Object state) Description copied from interface:HttpClientConnectionManagerReturns aLeaseRequestobject which can be used to obtain aConnectionEndpointto cancel the request by callingCancellable.cancel().Please note that newly allocated endpoints can be leased
disconnected. The consumer of the endpoint is responsible for fully establishing the route to the endpoint target by callingHttpClientConnectionManager.connect(ConnectionEndpoint, TimeValue, HttpContext)in order to connect directly to the target or to the first proxy hop, and optionally callingHttpClientConnectionManager.upgrade(ConnectionEndpoint, HttpContext)method to upgrade the underlying transport to Transport Layer Security after having executed aCONNECTmethod to all intermediate proxy hops.- Specified by:
leasein interfaceHttpClientConnectionManager- Parameters:
id- unique operation ID ornull.route- HTTP route of the requested connection.requestTimeout- lease request timeout.state- expected state of the connection ornullif the connection is not expected to carry any state.
-
release
public void release(ConnectionEndpoint endpoint, Object state, org.apache.hc.core5.util.TimeValue keepAlive) Description copied from interface:HttpClientConnectionManagerReleases the endpoint back to the manager making it potentially re-usable by other consumers. Optionally, the maximum period of how long the manager should keep the connection alive can be defined usingvalidDurationandtimeUnitparameters.- Specified by:
releasein interfaceHttpClientConnectionManager- Parameters:
endpoint- the managed endpoint.state- the new connection state ofnullif state-less.keepAlive- the duration of time this connection is valid for reuse.
-
connect
public void connect(ConnectionEndpoint endpoint, org.apache.hc.core5.util.TimeValue timeout, org.apache.hc.core5.http.protocol.HttpContext context) throws IOException Description copied from interface:HttpClientConnectionManagerConnects the endpoint to the initial hop (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).- Specified by:
connectin interfaceHttpClientConnectionManager- Parameters:
endpoint- the managed endpoint.timeout- connect timeout.context- the actual HTTP context.- Throws:
IOException
-
upgrade
public void upgrade(ConnectionEndpoint endpoint, org.apache.hc.core5.http.protocol.HttpContext context) throws IOException Description copied from interface:HttpClientConnectionManagerUpgrades transport security of the given endpoint by using the TLS security protocol.- Specified by:
upgradein interfaceHttpClientConnectionManager- Parameters:
endpoint- the managed endpoint.context- the actual HTTP context.- Throws:
IOException
-
closeIdle
public void closeIdle(org.apache.hc.core5.util.TimeValue idleTime) - Specified by:
closeIdlein interfaceorg.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
-
closeExpired
public void closeExpired()- Specified by:
closeExpiredin interfaceorg.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
-
getRoutes
-
getMaxTotal
public int getMaxTotal()- Specified by:
getMaxTotalin interfaceorg.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
-
setMaxTotal
public void setMaxTotal(int max) - Specified by:
setMaxTotalin interfaceorg.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
-
getDefaultMaxPerRoute
public int getDefaultMaxPerRoute()- Specified by:
getDefaultMaxPerRoutein interfaceorg.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
-
setDefaultMaxPerRoute
public void setDefaultMaxPerRoute(int max) - Specified by:
setDefaultMaxPerRoutein interfaceorg.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
-
getMaxPerRoute
-
setMaxPerRoute
-
getTotalStats
public org.apache.hc.core5.pool.PoolStats getTotalStats()- Specified by:
getTotalStatsin interfaceorg.apache.hc.core5.pool.ConnPoolStats<HttpRoute>
-
getStats
-
setDefaultSocketConfig
public void setDefaultSocketConfig(org.apache.hc.core5.http.io.SocketConfig config) Sets the sameSocketConfigfor all routes -
setSocketConfigResolver
public void setSocketConfigResolver(org.apache.hc.core5.function.Resolver<HttpRoute, org.apache.hc.core5.http.io.SocketConfig> socketConfigResolver) SetsResolverofSocketConfigon a per route basis.- Since:
- 5.2
-
setDefaultConnectionConfig
Sets the sameConnectionConfigfor all routes- Since:
- 5.2
-
setConnectionConfigResolver
public void setConnectionConfigResolver(org.apache.hc.core5.function.Resolver<HttpRoute, ConnectionConfig> connectionConfigResolver) SetsResolverofConnectionConfigon a per route basis.- Since:
- 5.2
-
setDefaultTlsConfig
Sets the sameConnectionConfigfor all hosts- Since:
- 5.2
-
setTlsConfigResolver
-
closeIfExpired
void closeIfExpired(org.apache.hc.core5.pool.PoolEntry<HttpRoute, ManagedHttpClientConnection> entry) -
getDefaultSocketConfig
Deprecated.Use customsetConnectionConfigResolver(Resolver) -
getValidateAfterInactivity
Deprecated.- Since:
- 4.4
-
setValidateAfterInactivity
@Deprecated public void setValidateAfterInactivity(org.apache.hc.core5.util.TimeValue validateAfterInactivity) Deprecated.Defines period of inactivity after which persistent connections must be re-validated prior to beinglease(String, HttpRoute, Object)leased} to the consumer. Negative values passed to this method disable connection validation. This check helps detect connections that have become stale (half-closed) while kept inactive in the pool.- Since:
- 4.4
-
setConnectionConfigResolver(Resolver)