@Contract(threading=SAFE_CONDITIONAL) public class PoolingAsyncClientConnectionManager extends Object implements AsyncClientConnectionManager, ConnPoolControl<HttpRoute>
PoolingAsyncClientConnectionManager maintains a pool of non-blocking
HttpConnections 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.
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_MAX_CONNECTIONS_PER_ROUTE |
static int |
DEFAULT_MAX_TOTAL_CONNECTIONS |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close() |
void |
close(CloseMode closeMode)
Closes this process or endpoint and releases any system resources associated
with it.
|
void |
closeExpired() |
void |
closeIdle(TimeValue idletime) |
Future<AsyncConnectionEndpoint> |
connect(AsyncConnectionEndpoint endpoint,
ConnectionInitiator connectionInitiator,
Timeout timeout,
Object attachment,
HttpContext context,
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() |
PoolStats |
getStats(HttpRoute route) |
PoolStats |
getTotalStats() |
TimeValue |
getValidateAfterInactivity()
已过时。
Use custom
setConnectionConfigResolver(Resolver) |
Future<AsyncConnectionEndpoint> |
lease(String id,
HttpRoute route,
Object state,
Timeout requestTimeout,
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,
TimeValue keepAlive)
Releases the endpoint back to the manager making it potentially
re-usable by other consumers.
|
void |
setConnectionConfigResolver(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(Resolver<HttpHost,TlsConfig> tlsConfigResolver)
|
void |
setValidateAfterInactivity(TimeValue validateAfterInactivity)
已过时。
|
void |
upgrade(AsyncConnectionEndpoint endpoint,
Object attachment,
HttpContext context)
Upgrades transport security of the given endpoint by using the TLS security protocol.
|
void |
upgrade(AsyncConnectionEndpoint endpoint,
Object attachment,
HttpContext context,
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(Lookup<TlsStrategy> tlsStrategyLookup)
public PoolingAsyncClientConnectionManager(Lookup<TlsStrategy> tlsStrategyLookup, PoolConcurrencyPolicy poolConcurrencyPolicy, TimeValue timeToLive)
public PoolingAsyncClientConnectionManager(Lookup<TlsStrategy> tlsStrategyLookup, PoolConcurrencyPolicy poolConcurrencyPolicy, PoolReusePolicy poolReusePolicy, TimeValue timeToLive)
public PoolingAsyncClientConnectionManager(Lookup<TlsStrategy> tlsStrategyLookup, PoolConcurrencyPolicy poolConcurrencyPolicy, PoolReusePolicy poolReusePolicy, TimeValue timeToLive, SchemePortResolver schemePortResolver, DnsResolver dnsResolver)
@Internal protected PoolingAsyncClientConnectionManager(AsyncClientConnectionOperator connectionOperator, PoolConcurrencyPolicy poolConcurrencyPolicy, PoolReusePolicy poolReusePolicy, TimeValue timeToLive)
@Internal protected PoolingAsyncClientConnectionManager(ManagedConnPool<HttpRoute,ManagedAsyncClientConnection> pool, AsyncClientConnectionOperator connectionOperator)
public void close()
close 在接口中 Closeableclose 在接口中 AutoCloseablepublic void close(CloseMode closeMode)
ModalCloseableclose 在接口中 ModalCloseablecloseMode - How to close the receiver.public Future<AsyncConnectionEndpoint> lease(String id, HttpRoute route, Object state, Timeout requestTimeout, FutureCallback<AsyncConnectionEndpoint> callback)
AsyncClientConnectionManagerFuture 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 在接口中 AsyncClientConnectionManagerid - 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, TimeValue keepAlive)
AsyncClientConnectionManagervalidDuration and timeUnit
parameters.release 在接口中 AsyncClientConnectionManagerendpoint - 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, ConnectionInitiator connectionInitiator, Timeout timeout, Object attachment, HttpContext context, FutureCallback<AsyncConnectionEndpoint> callback)
AsyncClientConnectionManagerconnect 在接口中 AsyncClientConnectionManagerendpoint - 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, HttpContext context, FutureCallback<AsyncConnectionEndpoint> callback)
AsyncClientConnectionManagerupgrade 在接口中 AsyncClientConnectionManagerendpoint - 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, HttpContext context)
AsyncClientConnectionManagerupgrade 在接口中 AsyncClientConnectionManagerendpoint - the managed endpoint.attachment - the attachment the upgrade attachment object.context - the actual HTTP context.public Set<HttpRoute> getRoutes()
getRoutes 在接口中 ConnPoolControl<HttpRoute>public void setMaxTotal(int max)
setMaxTotal 在接口中 ConnPoolControl<HttpRoute>public int getMaxTotal()
getMaxTotal 在接口中 ConnPoolControl<HttpRoute>public void setDefaultMaxPerRoute(int max)
setDefaultMaxPerRoute 在接口中 ConnPoolControl<HttpRoute>public int getDefaultMaxPerRoute()
getDefaultMaxPerRoute 在接口中 ConnPoolControl<HttpRoute>public void setMaxPerRoute(HttpRoute route, int max)
setMaxPerRoute 在接口中 ConnPoolControl<HttpRoute>public int getMaxPerRoute(HttpRoute route)
getMaxPerRoute 在接口中 ConnPoolControl<HttpRoute>public void closeIdle(TimeValue idletime)
closeIdle 在接口中 ConnPoolControl<HttpRoute>public void closeExpired()
closeExpired 在接口中 ConnPoolControl<HttpRoute>public PoolStats getTotalStats()
getTotalStats 在接口中 ConnPoolStats<HttpRoute>public PoolStats getStats(HttpRoute route)
getStats 在接口中 ConnPoolStats<HttpRoute>public void setDefaultConnectionConfig(ConnectionConfig config)
ConnectionConfig for all routespublic void setConnectionConfigResolver(Resolver<HttpRoute,ConnectionConfig> connectionConfigResolver)
Resolver of ConnectionConfig on a per route basis.public void setDefaultTlsConfig(TlsConfig config)
ConnectionConfig for all hostspublic void setTlsConfigResolver(Resolver<HttpHost,TlsConfig> tlsConfigResolver)
@Deprecated public TimeValue getValidateAfterInactivity()
setConnectionConfigResolver(Resolver)@Deprecated public void setValidateAfterInactivity(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.Copyright © 2023. All rights reserved.