Class BasicHttpClientConnectionManager
- All Implemented Interfaces:
Closeable
,AutoCloseable
,HttpClientConnectionManager
This connection manager will make an effort to reuse the connection for subsequent requests
with the same route
. It will, however, close the existing connection and
open it for the given route, if the route of the persistent connection does not match that
of the connection request. If the connection has been already been allocated
IllegalStateException
is thrown.
This connection manager implementation should be used inside an EJB container instead of
PoolingHttpClientConnectionManager
.
- Since:
- 4.3
-
Constructor Summary
ConstructorsConstructorDescriptionBasicHttpClientConnectionManager
(Lookup<ConnectionSocketFactory> socketFactoryRegistry) BasicHttpClientConnectionManager
(Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) BasicHttpClientConnectionManager
(Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver) BasicHttpClientConnectionManager
(HttpClientConnectionOperator httpClientConnectionOperator, HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
Closes all expired connections in the pool.void
closeIdleConnections
(long idletime, TimeUnit timeUnit) Closes idle connections in the pool.void
connect
(HttpClientConnection conn, HttpRoute route, int connectTimeout, HttpContext context) Connects the underlying connection socket to the 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).void
releaseConnection
(HttpClientConnection conn, Object state, long keepalive, TimeUnit timeUnit) Releases the connection back to the manager making it potentially re-usable by other consumers.final ConnectionRequest
requestConnection
(HttpRoute route, Object state) Returns a newConnectionRequest
, from which aHttpClientConnection
can be obtained or the request can be aborted.void
routeComplete
(HttpClientConnection conn, HttpRoute route, HttpContext context) Marks the connection as fully established with all its intermediate hops completed.void
setConnectionConfig
(ConnectionConfig connConfig) void
setSocketConfig
(SocketConfig socketConfig) void
shutdown()
Shuts down this connection manager and releases allocated resources.void
upgrade
(HttpClientConnection conn, HttpRoute route, HttpContext context) Upgrades the underlying connection socket to TLS/SSL (or another layering protocol) after having executedCONNECT
method to all intermediate proxy hops
-
Constructor Details
-
BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager(Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver) -
BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) - Since:
- 4.4
-
BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager(Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) -
BasicHttpClientConnectionManager
-
BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager()
-
-
Method Details
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getSocketConfig
-
setSocketConfig
-
getConnectionConfig
-
setConnectionConfig
-
requestConnection
Description copied from interface:HttpClientConnectionManager
Returns a newConnectionRequest
, from which aHttpClientConnection
can be obtained or the request can be aborted.Please note that newly allocated connections can be returned in the closed state. The consumer of that connection is responsible for fully establishing the route the to the connection target by calling
connect
in order to connect directly to the target or to the first proxy hop, optionally callingupgrade
method to upgrade the connection after having executedCONNECT
method to all intermediate proxy hops and and finally callingrouteComplete
to mark the route as fully completed.- Specified by:
requestConnection
in interfaceHttpClientConnectionManager
- Parameters:
route
- HTTP route of the requested connection.state
- expected state of the connection ornull
if the connection is not expected to carry any state.
-
releaseConnection
public void releaseConnection(HttpClientConnection conn, Object state, long keepalive, TimeUnit timeUnit) Description copied from interface:HttpClientConnectionManager
Releases the connection 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 usingvalidDuration
andtimeUnit
parameters.- Specified by:
releaseConnection
in interfaceHttpClientConnectionManager
- Parameters:
conn
- the managed connection to release.keepalive
- the duration of time this connection is valid for reuse.timeUnit
- the time unit.- See Also:
-
connect
public void connect(HttpClientConnection conn, HttpRoute route, int connectTimeout, HttpContext context) throws IOException Description copied from interface:HttpClientConnectionManager
Connects the underlying connection socket to the 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:
connect
in interfaceHttpClientConnectionManager
- Parameters:
conn
- the managed connection.route
- the route of the connection.connectTimeout
- connect timeout in milliseconds.context
- the actual HTTP context.- Throws:
IOException
-
upgrade
public void upgrade(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException Description copied from interface:HttpClientConnectionManager
Upgrades the underlying connection socket to TLS/SSL (or another layering protocol) after having executedCONNECT
method to all intermediate proxy hops- Specified by:
upgrade
in interfaceHttpClientConnectionManager
- Parameters:
conn
- the managed connection.route
- the route of the connection.context
- the actual HTTP context.- Throws:
IOException
-
routeComplete
public void routeComplete(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException Description copied from interface:HttpClientConnectionManager
Marks the connection as fully established with all its intermediate hops completed.- Specified by:
routeComplete
in interfaceHttpClientConnectionManager
- Parameters:
conn
- the managed connection.route
- the route of the connection.context
- the actual HTTP context.- Throws:
IOException
-
closeExpiredConnections
public void closeExpiredConnections()Description copied from interface:HttpClientConnectionManager
Closes all expired connections in the pool.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.
- Specified by:
closeExpiredConnections
in interfaceHttpClientConnectionManager
-
closeIdleConnections
Description copied from interface:HttpClientConnectionManager
Closes idle connections in the pool.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.
- Specified by:
closeIdleConnections
in interfaceHttpClientConnectionManager
- Parameters:
idletime
- the idle time of connections to be closedtimeUnit
- the unit for theidletime
- See Also:
-
shutdown
public void shutdown()Description copied from interface:HttpClientConnectionManager
Shuts down this connection manager and releases allocated resources. This includes closing all connections, whether they are currently used or not.- Specified by:
shutdown
in interfaceHttpClientConnectionManager
-