|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager
@Contract(threading=SAFE) public class PoolingNHttpClientConnectionManager
PoolingNHttpClientConnectionManager
maintains a pool of
NHttpClientConnection
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 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.
Constructor Summary | |
---|---|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor)
|
|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory)
|
|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
org.apache.http.conn.DnsResolver dnsResolver)
|
|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry)
|
|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry,
org.apache.http.conn.DnsResolver dnsResolver)
|
|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry,
org.apache.http.conn.SchemePortResolver schemePortResolver,
org.apache.http.conn.DnsResolver dnsResolver,
long timeToLive,
TimeUnit timeUnit)
|
|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry,
org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver)
|
|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry,
org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver,
long timeToLive,
TimeUnit timeUnit)
|
|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver)
|
|
PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry)
|
Method Summary | |
---|---|
void |
closeExpiredConnections()
Closes all expired connections in the pool. |
void |
closeIdleConnections(long idleTimeout,
TimeUnit timeUnit)
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()
|
org.apache.http.config.ConnectionConfig |
getConnectionConfig(org.apache.http.HttpHost host)
|
org.apache.http.config.ConnectionConfig |
getDefaultConnectionConfig()
|
int |
getDefaultMaxPerRoute()
|
int |
getMaxPerRoute(org.apache.http.conn.routing.HttpRoute route)
|
int |
getMaxTotal()
|
Set<org.apache.http.conn.routing.HttpRoute> |
getRoutes()
|
org.apache.http.pool.PoolStats |
getStats(org.apache.http.conn.routing.HttpRoute route)
|
org.apache.http.pool.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 timeUnit)
Releases the connection back to the manager making it potentially re-usable by other consumers. |
Future<org.apache.http.nio.NHttpClientConnection> |
requestConnection(org.apache.http.conn.routing.HttpRoute route,
Object state,
long connectTimeout,
long leaseTimeout,
TimeUnit timeUnit,
org.apache.http.concurrent.FutureCallback<org.apache.http.nio.NHttpClientConnection> callback)
Returns a Future for a NHttpClientConnection . |
void |
routeComplete(org.apache.http.nio.NHttpClientConnection managedConn,
org.apache.http.conn.routing.HttpRoute route,
org.apache.http.protocol.HttpContext context)
Marks the connection as fully established with all its intermediate hops completed. |
void |
setConnectionConfig(org.apache.http.HttpHost host,
org.apache.http.config.ConnectionConfig connectionConfig)
|
void |
setDefaultConnectionConfig(org.apache.http.config.ConnectionConfig defaultConnectionConfig)
|
void |
setDefaultMaxPerRoute(int max)
|
void |
setMaxPerRoute(org.apache.http.conn.routing.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,
org.apache.http.conn.routing.HttpRoute route,
org.apache.http.protocol.HttpContext context)
Starts the process of connection initialization. |
void |
upgrade(org.apache.http.nio.NHttpClientConnection managedConn,
org.apache.http.conn.routing.HttpRoute route,
org.apache.http.protocol.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. |
void |
validatePendingRequests()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.conn.DnsResolver dnsResolver)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry, org.apache.http.conn.DnsResolver dnsResolver)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry, org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry, org.apache.http.conn.SchemePortResolver schemePortResolver, org.apache.http.conn.DnsResolver dnsResolver, long timeToLive, TimeUnit timeUnit)
public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry, org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver, long timeToLive, TimeUnit timeUnit)
Method Detail |
---|
protected void finalize() throws Throwable
finalize
in class Object
Throwable
public void execute(org.apache.http.nio.reactor.IOEventDispatch eventDispatch) throws IOException
NHttpClientConnectionManager
IOEventDispatch
.
execute
in interface NHttpClientConnectionManager
IOException
public void shutdown(long waitMs) throws IOException
IOException
public void shutdown() throws IOException
NHttpClientConnectionManager
shutdown
in interface NHttpClientConnectionManager
IOException
public Future<org.apache.http.nio.NHttpClientConnection> requestConnection(org.apache.http.conn.routing.HttpRoute route, Object state, long connectTimeout, long leaseTimeout, TimeUnit timeUnit, org.apache.http.concurrent.FutureCallback<org.apache.http.nio.NHttpClientConnection> callback)
NHttpClientConnectionManager
Future
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 NHttpClientConnectionManager
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.connectTimeout
- connect timeout.leaseTimeout
- connection request timeout.timeUnit
- 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 timeUnit)
NHttpClientConnectionManager
validDuration
and timeUnit
parameters.
releaseConnection
in interface NHttpClientConnectionManager
managedConn
- the managed connection to release.keepalive
- the duration of time this connection is valid for reuse.timeUnit
- the time unit.NHttpClientConnectionManager.closeExpiredConnections()
public void startRoute(org.apache.http.nio.NHttpClientConnection managedConn, org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context) throws IOException
NHttpClientConnectionManager
routeComplete
method must be called.
startRoute
in interface NHttpClientConnectionManager
managedConn
- the managed connection to initialize.route
- the connection route.context
- the context
IOException
public void upgrade(org.apache.http.nio.NHttpClientConnection managedConn, org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context) throws IOException
NHttpClientConnectionManager
CONNECT
method to all
intermediate proxy hops.
upgrade
in interface NHttpClientConnectionManager
managedConn
- the managed connection to upgrade.route
- the connection route.context
- the context
IOException
public void routeComplete(org.apache.http.nio.NHttpClientConnection managedConn, org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context)
NHttpClientConnectionManager
routeComplete
in interface NHttpClientConnectionManager
managedConn
- the managed connection to mark as route complete.route
- the connection route.context
- the contextpublic boolean isRouteComplete(org.apache.http.nio.NHttpClientConnection managedConn)
NHttpClientConnectionManager
isRouteComplete
in interface NHttpClientConnectionManager
managedConn
- the managed connection.public void closeIdleConnections(long idleTimeout, TimeUnit timeUnit)
NHttpClientConnectionManager
Open 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 NHttpClientConnectionManager
idleTimeout
- the idle time of connections to be closedtimeUnit
- the unit for the idletime
NHttpClientConnectionManager.closeExpiredConnections()
public void closeExpiredConnections()
NHttpClientConnectionManager
Open 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 NHttpClientConnectionManager
public void validatePendingRequests()
public int getMaxTotal()
getMaxTotal
in interface org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>
public void setMaxTotal(int max)
setMaxTotal
in interface org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>
public int getDefaultMaxPerRoute()
getDefaultMaxPerRoute
in interface org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>
public void setDefaultMaxPerRoute(int max)
setDefaultMaxPerRoute
in interface org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>
public int getMaxPerRoute(org.apache.http.conn.routing.HttpRoute route)
getMaxPerRoute
in interface org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>
public void setMaxPerRoute(org.apache.http.conn.routing.HttpRoute route, int max)
setMaxPerRoute
in interface org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>
public org.apache.http.pool.PoolStats getTotalStats()
getTotalStats
in interface org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>
public org.apache.http.pool.PoolStats getStats(org.apache.http.conn.routing.HttpRoute route)
getStats
in interface org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>
public Set<org.apache.http.conn.routing.HttpRoute> getRoutes()
public org.apache.http.config.ConnectionConfig getDefaultConnectionConfig()
public void setDefaultConnectionConfig(org.apache.http.config.ConnectionConfig defaultConnectionConfig)
public org.apache.http.config.ConnectionConfig getConnectionConfig(org.apache.http.HttpHost host)
public void setConnectionConfig(org.apache.http.HttpHost host, org.apache.http.config.ConnectionConfig connectionConfig)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |