@ThreadSafe public class PoolingNHttpClientConnectionManager extends Object implements NHttpClientConnectionManager, ConnPoolControl<HttpRoute>
PoolingNHttpClientConnectionManager maintains a pool of
NHttpClientConnections 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.
PoolingNHttpClientConnectionManager 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.
| Modifier and Type | Method and Description |
|---|---|
void |
closeExpiredConnections()
Closes all expired connections in the pool.
|
void |
closeIdleConnections(long idleTimeout,
TimeUnit tunit)
Closes idle connections in the pool.
|
void |
execute(org.apache.http.nio.reactor.IOEventDispatch eventDispatch)
Starts the underlying I/O reactor and initiates the dispatch of
I/O event notifications to the given
IOEventDispatch. |
protected void |
finalize() |
ConnectionConfig |
getConnectionConfig(HttpHost host) |
ConnectionConfig |
getDefaultConnectionConfig() |
int |
getDefaultMaxPerRoute() |
int |
getMaxPerRoute(HttpRoute route) |
int |
getMaxTotal() |
Set<HttpRoute> |
getRoutes() |
PoolStats |
getStats(HttpRoute route) |
PoolStats |
getTotalStats() |
boolean |
isRouteComplete(org.apache.http.nio.NHttpClientConnection managedConn)
Determines if the given connection has been fully established and
marked as route complete.
|
void |
releaseConnection(org.apache.http.nio.NHttpClientConnection managedConn,
Object state,
long keepalive,
TimeUnit tunit)
Releases the connection back to the manager making it potentially
re-usable by other consumers.
|
Future<org.apache.http.nio.NHttpClientConnection> |
requestConnection(HttpRoute route,
Object state,
long connectTimeout,
long leaseTimeout,
TimeUnit tunit,
FutureCallback<org.apache.http.nio.NHttpClientConnection> callback)
Returns a
Future for a NHttpClientConnection. |
void |
routeComplete(org.apache.http.nio.NHttpClientConnection 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 |
setMaxPerRoute(HttpRoute route,
int max) |
void |
setMaxTotal(int max) |
void |
shutdown()
Shuts down this connection manager and releases allocated resources.
|
void |
shutdown(long waitMs) |
void |
startRoute(org.apache.http.nio.NHttpClientConnection managedConn,
HttpRoute route,
HttpContext context)
Starts the process of connection initialization.
|
void |
upgrade(org.apache.http.nio.NHttpClientConnection managedConn,
HttpRoute route,
HttpContext context)
Upgrades the underlying connection I/O session to TLS/SSL (or another layering
protocol) after having executed
CONNECT method to all
intermediate proxy hops. |
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioreactor)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioreactor, Registry<SchemeIOSessionStrategy> iosessionFactoryRegistry)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioreactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, DnsResolver dnsResolver)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioreactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioreactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, Registry<SchemeIOSessionStrategy> iosessionFactoryRegistry)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioreactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, Registry<SchemeIOSessionStrategy> iosessionFactoryRegistry, DnsResolver dnsResolver)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioreactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, Registry<SchemeIOSessionStrategy> iosessionFactoryRegistry, SchemePortResolver schemePortResolver, DnsResolver dnsResolver, long timeToLive, TimeUnit tunit)
protected void finalize()
throws Throwable
public void execute(org.apache.http.nio.reactor.IOEventDispatch eventDispatch) throws IOException
NHttpClientConnectionManagerIOEventDispatch.execute in interface NHttpClientConnectionManagerIOExceptionpublic void shutdown(long waitMs)
throws IOException
IOExceptionpublic void shutdown()
throws IOException
NHttpClientConnectionManagershutdown in interface NHttpClientConnectionManagerIOExceptionpublic Future<org.apache.http.nio.NHttpClientConnection> requestConnection(HttpRoute route, Object state, long connectTimeout, long leaseTimeout, TimeUnit tunit, FutureCallback<org.apache.http.nio.NHttpClientConnection> callback)
NHttpClientConnectionManagerFuture for a NHttpClientConnection.
Please note that the consumer of that connection is responsible
for fully establishing the route the to the connection target
by calling startRoute in order to start
the process of connection initialization, 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 in interface NHttpClientConnectionManagerroute - HTTP route of the requested connection.state - expected state of the connection or null
if the connection is not expected to carry any state.connectTimeout - connect timeout.leaseTimeout - connection request timeout.tunit - time unit of the previous two timeout values.callback - future callback.public void releaseConnection(org.apache.http.nio.NHttpClientConnection managedConn, Object state, long keepalive, TimeUnit tunit)
NHttpClientConnectionManagervalidDuration and timeUnit
parameters.releaseConnection in interface NHttpClientConnectionManagermanagedConn - the managed connection to release.keepalive - the duration of time this connection is valid for reuse.tunit - the time unit.NHttpClientConnectionManager.closeExpiredConnections()public void startRoute(org.apache.http.nio.NHttpClientConnection managedConn, HttpRoute route, HttpContext context) throws IOException
NHttpClientConnectionManagerrouteComplete method must be called.startRoute in interface NHttpClientConnectionManagermanagedConn - the managed connection to initialize.route - the connection route.context - the contextIOExceptionpublic void upgrade(org.apache.http.nio.NHttpClientConnection managedConn, HttpRoute route, HttpContext context) throws IOException
NHttpClientConnectionManagerCONNECT method to all
intermediate proxy hops.upgrade in interface NHttpClientConnectionManagermanagedConn - the managed connection to upgrade.route - the connection route.context - the contextIOExceptionpublic void routeComplete(org.apache.http.nio.NHttpClientConnection managedConn, HttpRoute route, HttpContext context)
NHttpClientConnectionManagerrouteComplete in interface NHttpClientConnectionManagermanagedConn - the managed connection to mark as route complete.route - the connection route.context - the contextpublic boolean isRouteComplete(org.apache.http.nio.NHttpClientConnection managedConn)
NHttpClientConnectionManagerisRouteComplete in interface NHttpClientConnectionManagermanagedConn - the managed connection.public void closeIdleConnections(long idleTimeout,
TimeUnit tunit)
NHttpClientConnectionManagerOpen connections in the pool that have not been used for the timespan given by the argument will be closed. Currently allocated connections are not subject to this method. Times will be checked with milliseconds precision All expired connections will also be closed.
closeIdleConnections in interface NHttpClientConnectionManageridleTimeout - the idle time of connections to be closedtunit - the unit for the idletimeNHttpClientConnectionManager.closeExpiredConnections()public void closeExpiredConnections()
NHttpClientConnectionManagerOpen connections in the pool that have not been used for the timespan defined when the connection was released will be closed. Currently allocated connections are not subject to this method. Times will be checked with milliseconds precision.
closeExpiredConnections in interface NHttpClientConnectionManagerpublic int getMaxTotal()
getMaxTotal in interface ConnPoolControl<HttpRoute>public void setMaxTotal(int max)
setMaxTotal in interface ConnPoolControl<HttpRoute>public int getDefaultMaxPerRoute()
getDefaultMaxPerRoute in interface ConnPoolControl<HttpRoute>public void setDefaultMaxPerRoute(int max)
setDefaultMaxPerRoute in interface ConnPoolControl<HttpRoute>public int getMaxPerRoute(HttpRoute route)
getMaxPerRoute in interface ConnPoolControl<HttpRoute>public void setMaxPerRoute(HttpRoute route, int max)
setMaxPerRoute in interface ConnPoolControl<HttpRoute>public PoolStats getTotalStats()
getTotalStats in interface ConnPoolControl<HttpRoute>public PoolStats getStats(HttpRoute route)
getStats in interface ConnPoolControl<HttpRoute>public ConnectionConfig getDefaultConnectionConfig()
public void setDefaultConnectionConfig(ConnectionConfig defaultConnectionConfig)
public ConnectionConfig getConnectionConfig(HttpHost host)
public void setConnectionConfig(HttpHost host, ConnectionConfig connectionConfig)
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.