@Contract(threading=SAFE) public class BasicHttpClientConnectionManager extends Object implements 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
.
Constructor and Description |
---|
BasicHttpClientConnectionManager() |
BasicHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator,
HttpConnectionFactory<ManagedHttpClientConnection> connFactory) |
BasicHttpClientConnectionManager(Lookup<ConnectionSocketFactory> socketFactoryRegistry) |
BasicHttpClientConnectionManager(Lookup<ConnectionSocketFactory> socketFactoryRegistry,
HttpConnectionFactory<ManagedHttpClientConnection> connFactory) |
BasicHttpClientConnectionManager(Lookup<ConnectionSocketFactory> socketFactoryRegistry,
HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
SchemePortResolver schemePortResolver,
DnsResolver dnsResolver) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this stream and releases any system resources associated with it.
|
void |
close(CloseMode closeMode)
Closes this process or endpoint and releases any system resources associated
with it.
|
void |
closeExpired() |
void |
closeIdle(TimeValue idleTime) |
void |
connect(ConnectionEndpoint endpoint,
TimeValue connectTimeout,
HttpContext context)
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).
|
SocketConfig |
getSocketConfig() |
LeaseRequest |
lease(String id,
HttpRoute route,
Object state) |
LeaseRequest |
lease(String id,
HttpRoute route,
Timeout requestTimeout,
Object state)
Returns a
LeaseRequest object which can be used to obtain
a ConnectionEndpoint to cancel the request by calling
Cancellable.cancel() . |
void |
release(ConnectionEndpoint endpoint,
Object state,
TimeValue keepAlive)
Releases the endpoint back to the manager making it potentially
re-usable by other consumers.
|
void |
setSocketConfig(SocketConfig socketConfig) |
void |
upgrade(ConnectionEndpoint endpoint,
HttpContext context)
Upgrades transport security of the given endpoint by using the TLS security protocol.
|
public BasicHttpClientConnectionManager()
public BasicHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, HttpConnectionFactory<ManagedHttpClientConnection> connFactory)
public BasicHttpClientConnectionManager(Lookup<ConnectionSocketFactory> socketFactoryRegistry)
public BasicHttpClientConnectionManager(Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<ManagedHttpClientConnection> connFactory)
public BasicHttpClientConnectionManager(Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver)
public void close()
Closeable
close
in interface Closeable
close
in interface AutoCloseable
public void close(CloseMode closeMode)
ModalCloseable
close
in interface ModalCloseable
closeMode
- How to close the receiver.public void closeExpired()
public void closeIdle(TimeValue idleTime)
public void connect(ConnectionEndpoint endpoint, TimeValue connectTimeout, HttpContext context) throws IOException
HttpClientConnectionManager
connect
in interface HttpClientConnectionManager
endpoint
- the managed endpoint.connectTimeout
- connect timeout.context
- the actual HTTP context.IOException
public SocketConfig getSocketConfig()
public LeaseRequest lease(String id, HttpRoute route, Object state)
public LeaseRequest lease(String id, HttpRoute route, Timeout requestTimeout, Object state)
HttpClientConnectionManager
LeaseRequest
object which can be used to obtain
a ConnectionEndpoint
to cancel the request by calling
Cancellable.cancel()
.
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 HttpClientConnectionManager.connect(ConnectionEndpoint, TimeValue, HttpContext)
in order to connect directly to the target or to the first proxy hop,
and optionally calling HttpClientConnectionManager.upgrade(ConnectionEndpoint, HttpContext)
method
to upgrade the underlying transport to Transport Layer Security after having
executed a CONNECT
method to all intermediate proxy hops.
lease
in interface HttpClientConnectionManager
id
- unique operation ID or null
.route
- HTTP route of the requested connection.requestTimeout
- lease request timeout.state
- expected state of the connection or null
if the connection is not expected to carry any state.public void release(ConnectionEndpoint endpoint, Object state, TimeValue keepAlive)
HttpClientConnectionManager
validDuration
and timeUnit
parameters.release
in interface HttpClientConnectionManager
endpoint
- 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 void setSocketConfig(SocketConfig socketConfig)
public void upgrade(ConnectionEndpoint endpoint, HttpContext context) throws IOException
HttpClientConnectionManager
upgrade
in interface HttpClientConnectionManager
endpoint
- the managed endpoint.context
- the actual HTTP context.IOException