@Contract(threading=SAFE_CONDITIONAL) public class PoolingAsyncClientConnectionManager extends Object implements AsyncClientConnectionManager, org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
PoolingAsyncClientConnectionManager
maintains a pool of non-blocking
HttpConnection
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 new connection.
PoolingAsyncClientConnectionManager
maintains a maximum limit
of connection on a per route basis and in total. Connection limits
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.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_CONNECTIONS_PER_ROUTE |
static int |
DEFAULT_MAX_TOTAL_CONNECTIONS |
Modifier | Constructor and Description |
---|---|
|
PoolingAsyncClientConnectionManager() |
|
PoolingAsyncClientConnectionManager(AsyncClientConnectionOperator connectionOperator,
org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy,
org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy,
org.apache.hc.core5.util.TimeValue timeToLive) |
|
PoolingAsyncClientConnectionManager(org.apache.hc.core5.http.config.Lookup<org.apache.hc.core5.http.nio.ssl.TlsStrategy> tlsStrategyLookup) |
|
PoolingAsyncClientConnectionManager(org.apache.hc.core5.http.config.Lookup<org.apache.hc.core5.http.nio.ssl.TlsStrategy> tlsStrategyLookup,
org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy,
org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy,
org.apache.hc.core5.util.TimeValue timeToLive) |
|
PoolingAsyncClientConnectionManager(org.apache.hc.core5.http.config.Lookup<org.apache.hc.core5.http.nio.ssl.TlsStrategy> tlsStrategyLookup,
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) |
|
PoolingAsyncClientConnectionManager(org.apache.hc.core5.http.config.Lookup<org.apache.hc.core5.http.nio.ssl.TlsStrategy> tlsStrategyLookup,
org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy,
org.apache.hc.core5.util.TimeValue timeToLive) |
protected |
PoolingAsyncClientConnectionManager(org.apache.hc.core5.pool.ManagedConnPool<HttpRoute,ManagedAsyncClientConnection> pool,
AsyncClientConnectionOperator connectionOperator) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
close(org.apache.hc.core5.io.CloseMode closeMode) |
void |
closeExpired() |
void |
closeIdle(org.apache.hc.core5.util.TimeValue idletime) |
Future<AsyncConnectionEndpoint> |
connect(AsyncConnectionEndpoint endpoint,
org.apache.hc.core5.reactor.ConnectionInitiator connectionInitiator,
org.apache.hc.core5.util.Timeout timeout,
Object attachment,
org.apache.hc.core5.http.protocol.HttpContext context,
org.apache.hc.core5.concurrent.FutureCallback<AsyncConnectionEndpoint> callback)
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).
|
int |
getDefaultMaxPerRoute() |
int |
getMaxPerRoute(HttpRoute route) |
int |
getMaxTotal() |
Set<HttpRoute> |
getRoutes() |
org.apache.hc.core5.pool.PoolStats |
getStats(HttpRoute route) |
org.apache.hc.core5.pool.PoolStats |
getTotalStats() |
org.apache.hc.core5.util.TimeValue |
getValidateAfterInactivity()
Deprecated.
Use custom
setConnectionConfigResolver(Resolver) |
boolean |
isClosed()
Method that can be called to determine whether the connection manager has been shut down and
is closed or not.
|
Future<AsyncConnectionEndpoint> |
lease(String id,
HttpRoute route,
Object state,
org.apache.hc.core5.util.Timeout requestTimeout,
org.apache.hc.core5.concurrent.FutureCallback<AsyncConnectionEndpoint> callback)
Returns a
Future object which can be used to obtain
an AsyncConnectionEndpoint or to cancel the request by calling
Future.cancel(boolean) . |
void |
release(AsyncConnectionEndpoint 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.
|
void |
setConnectionConfigResolver(org.apache.hc.core5.function.Resolver<HttpRoute,ConnectionConfig> connectionConfigResolver)
Sets
Resolver of ConnectionConfig on a per route basis. |
void |
setDefaultConnectionConfig(ConnectionConfig config)
Sets the same
ConnectionConfig for all routes |
void |
setDefaultMaxPerRoute(int max) |
void |
setDefaultTlsConfig(TlsConfig config)
Sets the same
ConnectionConfig for all hosts |
void |
setMaxPerRoute(HttpRoute route,
int max) |
void |
setMaxTotal(int max) |
void |
setTlsConfigResolver(org.apache.hc.core5.function.Resolver<org.apache.hc.core5.http.HttpHost,TlsConfig> tlsConfigResolver)
Sets
Resolver of TlsConfig on a per host basis. |
void |
setValidateAfterInactivity(org.apache.hc.core5.util.TimeValue validateAfterInactivity)
Deprecated.
|
void |
upgrade(AsyncConnectionEndpoint endpoint,
Object attachment,
org.apache.hc.core5.http.protocol.HttpContext context)
Upgrades transport security of the given endpoint by using the TLS security protocol.
|
void |
upgrade(AsyncConnectionEndpoint endpoint,
Object attachment,
org.apache.hc.core5.http.protocol.HttpContext context,
org.apache.hc.core5.concurrent.FutureCallback<AsyncConnectionEndpoint> callback)
Upgrades transport security of the given endpoint by using the TLS security protocol.
|
public static final int DEFAULT_MAX_TOTAL_CONNECTIONS
public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE
public PoolingAsyncClientConnectionManager()
public PoolingAsyncClientConnectionManager(org.apache.hc.core5.http.config.Lookup<org.apache.hc.core5.http.nio.ssl.TlsStrategy> tlsStrategyLookup)
public PoolingAsyncClientConnectionManager(org.apache.hc.core5.http.config.Lookup<org.apache.hc.core5.http.nio.ssl.TlsStrategy> tlsStrategyLookup, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.util.TimeValue timeToLive)
public PoolingAsyncClientConnectionManager(org.apache.hc.core5.http.config.Lookup<org.apache.hc.core5.http.nio.ssl.TlsStrategy> tlsStrategyLookup, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive)
public PoolingAsyncClientConnectionManager(org.apache.hc.core5.http.config.Lookup<org.apache.hc.core5.http.nio.ssl.TlsStrategy> tlsStrategyLookup, 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)
@Internal public PoolingAsyncClientConnectionManager(AsyncClientConnectionOperator connectionOperator, org.apache.hc.core5.pool.PoolConcurrencyPolicy poolConcurrencyPolicy, org.apache.hc.core5.pool.PoolReusePolicy poolReusePolicy, org.apache.hc.core5.util.TimeValue timeToLive)
@Internal protected PoolingAsyncClientConnectionManager(org.apache.hc.core5.pool.ManagedConnPool<HttpRoute,ManagedAsyncClientConnection> pool, AsyncClientConnectionOperator connectionOperator)
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public void close(org.apache.hc.core5.io.CloseMode closeMode)
close
in interface org.apache.hc.core5.io.ModalCloseable
public Future<AsyncConnectionEndpoint> lease(String id, HttpRoute route, Object state, org.apache.hc.core5.util.Timeout requestTimeout, org.apache.hc.core5.concurrent.FutureCallback<AsyncConnectionEndpoint> callback)
AsyncClientConnectionManager
Future
object which can be used to obtain
an AsyncConnectionEndpoint
or to cancel the request by calling
Future.cancel(boolean)
.
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 calling AsyncClientConnectionManager.connect(AsyncConnectionEndpoint,
ConnectionInitiator, Timeout, Object, HttpContext, FutureCallback)
in order to connect directly to the target or to the first proxy hop,
and optionally calling AsyncClientConnectionManager.upgrade(AsyncConnectionEndpoint, Object, HttpContext)
method to upgrade the underlying transport to Transport Layer Security
after having executed a CONNECT
method to all intermediate
proxy hops.
lease
in interface AsyncClientConnectionManager
id
- unique operation ID or null
.route
- HTTP route of the requested connection.state
- expected state of the connection or null
if the connection is not expected to carry any state.requestTimeout
- lease request timeout.callback
- result callback.public void release(AsyncConnectionEndpoint endpoint, Object state, org.apache.hc.core5.util.TimeValue keepAlive)
AsyncClientConnectionManager
validDuration
and timeUnit
parameters.release
in interface AsyncClientConnectionManager
endpoint
- the managed endpoint.state
- the new connection state of null
if state-less.keepAlive
- the duration of time this connection is valid for reuse.public Future<AsyncConnectionEndpoint> connect(AsyncConnectionEndpoint endpoint, org.apache.hc.core5.reactor.ConnectionInitiator connectionInitiator, org.apache.hc.core5.util.Timeout timeout, Object attachment, org.apache.hc.core5.http.protocol.HttpContext context, org.apache.hc.core5.concurrent.FutureCallback<AsyncConnectionEndpoint> callback)
AsyncClientConnectionManager
connect
in interface AsyncClientConnectionManager
endpoint
- the managed endpoint.timeout
- connect timeout.attachment
- connect request attachment.context
- the actual HTTP context.callback
- result callback.public void upgrade(AsyncConnectionEndpoint endpoint, Object attachment, org.apache.hc.core5.http.protocol.HttpContext context, org.apache.hc.core5.concurrent.FutureCallback<AsyncConnectionEndpoint> callback)
AsyncClientConnectionManager
upgrade
in interface AsyncClientConnectionManager
endpoint
- the managed endpoint.attachment
- the attachment the upgrade attachment object.context
- the actual HTTP context.callback
- result callback.public void upgrade(AsyncConnectionEndpoint endpoint, Object attachment, org.apache.hc.core5.http.protocol.HttpContext context)
AsyncClientConnectionManager
upgrade
in interface AsyncClientConnectionManager
endpoint
- the managed endpoint.attachment
- the attachment the upgrade attachment object.context
- the actual HTTP context.public Set<HttpRoute> getRoutes()
getRoutes
in interface org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
public void setMaxTotal(int max)
setMaxTotal
in interface org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
public int getMaxTotal()
getMaxTotal
in interface org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
public void setDefaultMaxPerRoute(int max)
setDefaultMaxPerRoute
in interface org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
public int getDefaultMaxPerRoute()
getDefaultMaxPerRoute
in interface org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
public void setMaxPerRoute(HttpRoute route, int max)
setMaxPerRoute
in interface org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
public int getMaxPerRoute(HttpRoute route)
getMaxPerRoute
in interface org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
public void closeIdle(org.apache.hc.core5.util.TimeValue idletime)
closeIdle
in interface org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
public void closeExpired()
closeExpired
in interface org.apache.hc.core5.pool.ConnPoolControl<HttpRoute>
public org.apache.hc.core5.pool.PoolStats getTotalStats()
getTotalStats
in interface org.apache.hc.core5.pool.ConnPoolStats<HttpRoute>
public org.apache.hc.core5.pool.PoolStats getStats(HttpRoute route)
getStats
in interface org.apache.hc.core5.pool.ConnPoolStats<HttpRoute>
public void setDefaultConnectionConfig(ConnectionConfig config)
ConnectionConfig
for all routespublic void setConnectionConfigResolver(org.apache.hc.core5.function.Resolver<HttpRoute,ConnectionConfig> connectionConfigResolver)
Resolver
of ConnectionConfig
on a per route basis.public void setDefaultTlsConfig(TlsConfig config)
ConnectionConfig
for all hostspublic void setTlsConfigResolver(org.apache.hc.core5.function.Resolver<org.apache.hc.core5.http.HttpHost,TlsConfig> tlsConfigResolver)
Resolver
of TlsConfig
on a per host basis.@Deprecated public org.apache.hc.core5.util.TimeValue getValidateAfterInactivity()
setConnectionConfigResolver(Resolver)
@Deprecated public void setValidateAfterInactivity(org.apache.hc.core5.util.TimeValue validateAfterInactivity)
setConnectionConfigResolver(Resolver)
.lease(String, HttpRoute, Object, Timeout,
FutureCallback)
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.public boolean isClosed()
true
if the connection manager has been shut down and is closed, otherwise
return false
.Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.