@Contract(threading=SAFE_CONDITIONAL) public class BasicHttpClientConnectionManager extends Object implements HttpClientConnectionManager, Closeable
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
.
Constructor and Description |
---|
BasicHttpClientConnectionManager() |
BasicHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator,
HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory) |
BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry) |
BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry,
HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory) |
BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry,
HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory,
SchemePortResolver schemePortResolver,
DnsResolver dnsResolver) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
closeExpiredConnections()
Closes all expired connections in the pool.
|
void |
closeIdleConnections(long idletime,
TimeUnit timeUnit)
Closes idle connections in the pool.
|
void |
connect(org.apache.http.HttpClientConnection conn,
HttpRoute route,
int connectTimeout,
org.apache.http.protocol.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).
|
protected void |
finalize() |
org.apache.http.config.ConnectionConfig |
getConnectionConfig() |
org.apache.http.config.SocketConfig |
getSocketConfig() |
void |
releaseConnection(org.apache.http.HttpClientConnection conn,
Object state,
long keepalive,
TimeUnit timeUnit)
Releases the connection back to the manager making it potentially
re-usable by other consumers.
|
ConnectionRequest |
requestConnection(HttpRoute route,
Object state)
Returns a new
ConnectionRequest , from which a
HttpClientConnection can be obtained or the request can be
aborted. |
void |
routeComplete(org.apache.http.HttpClientConnection conn,
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.config.ConnectionConfig connConfig) |
void |
setSocketConfig(org.apache.http.config.SocketConfig socketConfig) |
void |
shutdown()
Shuts down this connection manager and releases allocated resources.
|
void |
upgrade(org.apache.http.HttpClientConnection conn,
HttpRoute route,
org.apache.http.protocol.HttpContext context)
Upgrades the underlying connection socket to TLS/SSL (or another layering
protocol) after having executed
CONNECT method to all
intermediate proxy hops |
public BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver)
public BasicHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory)
public BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<HttpRoute,ManagedHttpClientConnection> connFactory)
public BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry)
public BasicHttpClientConnectionManager()
protected void finalize() throws Throwable
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public org.apache.http.config.SocketConfig getSocketConfig()
public void setSocketConfig(org.apache.http.config.SocketConfig socketConfig)
public org.apache.http.config.ConnectionConfig getConnectionConfig()
public void setConnectionConfig(org.apache.http.config.ConnectionConfig connConfig)
public final ConnectionRequest requestConnection(HttpRoute route, Object state)
HttpClientConnectionManager
ConnectionRequest
, from which a
HttpClientConnection
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 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 HttpClientConnectionManager
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.public void releaseConnection(org.apache.http.HttpClientConnection conn, Object state, long keepalive, TimeUnit timeUnit)
HttpClientConnectionManager
validDuration
and timeUnit
parameters.releaseConnection
in interface HttpClientConnectionManager
conn
- the managed connection to release.keepalive
- the duration of time this connection is valid for reuse.timeUnit
- the time unit.HttpClientConnectionManager.closeExpiredConnections()
public void connect(org.apache.http.HttpClientConnection conn, HttpRoute route, int connectTimeout, org.apache.http.protocol.HttpContext context) throws IOException
HttpClientConnectionManager
connect
in interface HttpClientConnectionManager
conn
- the managed connection.route
- the route of the connection.connectTimeout
- connect timeout in milliseconds.context
- the actual HTTP context.IOException
public void upgrade(org.apache.http.HttpClientConnection conn, HttpRoute route, org.apache.http.protocol.HttpContext context) throws IOException
HttpClientConnectionManager
CONNECT
method to all
intermediate proxy hopsupgrade
in interface HttpClientConnectionManager
conn
- the managed connection.route
- the route of the connection.context
- the actual HTTP context.IOException
public void routeComplete(org.apache.http.HttpClientConnection conn, HttpRoute route, org.apache.http.protocol.HttpContext context) throws IOException
HttpClientConnectionManager
routeComplete
in interface HttpClientConnectionManager
conn
- the managed connection.route
- the route of the connection.context
- the actual HTTP context.IOException
public void closeExpiredConnections()
HttpClientConnectionManager
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 HttpClientConnectionManager
public void closeIdleConnections(long idletime, TimeUnit timeUnit)
HttpClientConnectionManager
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 HttpClientConnectionManager
idletime
- the idle time of connections to be closedtimeUnit
- the unit for the idletime
HttpClientConnectionManager.closeExpiredConnections()
public void shutdown()
HttpClientConnectionManager
shutdown
in interface HttpClientConnectionManager
Copyright © 1999–2022 The Apache Software Foundation. All rights reserved.