Class BasicHttpClientConnectionManager
- All Implemented Interfaces:
Closeable, AutoCloseable, HttpClientConnectionManager, org.apache.hc.core5.io.ModalCloseable
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanprivate ManagedHttpClientConnectionprivate ConnectionConfigprivate final HttpClientConnectionOperatorprivate final org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> private static final AtomicLongprivate longprivate longprivate final Stringprivate booleanprivate static final org.slf4j.Loggerprivate HttpRouteprivate org.apache.hc.core5.http.io.SocketConfigprivate Objectprivate TlsConfigprivate long -
Constructor Summary
ConstructorsConstructorDescriptionBasicHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry) BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver) -
Method Summary
Modifier and TypeMethodDescriptioncast(ConnectionEndpoint endpoint) private voidvoidclose()voidclose(org.apache.hc.core5.io.CloseMode closeMode) private voidcloseConnection(org.apache.hc.core5.io.CloseMode closeMode) voidvoidcloseIdle(org.apache.hc.core5.util.TimeValue idleTime) voidconnect(ConnectionEndpoint endpoint, org.apache.hc.core5.util.TimeValue timeout, org.apache.hc.core5.http.protocol.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).(package private) ManagedHttpClientConnectiongetConnection(HttpRoute route, Object state) private static org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> (package private) HttpRoutegetRoute()org.apache.hc.core5.http.io.SocketConfig(package private) ObjectgetState()org.apache.hc.core5.util.TimeValueDeprecated.(package private) booleanisClosed()Method that can be called to determine whether the connection manager has been shut down and is closed or not.Returns aLeaseRequestobject which can be used to obtain aConnectionEndpointto cancel the request by callingCancellable.cancel().voidrelease(ConnectionEndpoint endpoint, Object state, org.apache.hc.core5.util.TimeValue keepAlive) Releases the endpoint back to the manager making it potentially re-usable by other consumers.voidsetConnectionConfig(ConnectionConfig connectionConfig) voidsetSocketConfig(org.apache.hc.core5.http.io.SocketConfig socketConfig) voidsetTlsConfig(TlsConfig tlsConfig) voidsetValidateAfterInactivity(org.apache.hc.core5.util.TimeValue validateAfterInactivity) Deprecated.voidupgrade(ConnectionEndpoint endpoint, org.apache.hc.core5.http.protocol.HttpContext context) Upgrades transport security of the given endpoint by using the TLS security protocol.private voidvalidate()
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
COUNT
-
connectionOperator
-
connFactory
private final org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory -
id
-
conn
-
route
-
state
-
created
private long created -
updated
private long updated -
expiry
private long expiry -
leased
private boolean leased -
socketConfig
private org.apache.hc.core5.http.io.SocketConfig socketConfig -
connectionConfig
-
tlsConfig
-
closed
-
-
Constructor Details
-
BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver) -
BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) - Since:
- 4.4
-
BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory) -
BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry) -
BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager()
-
-
Method Details
-
getDefaultRegistry
private static org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> getDefaultRegistry() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
close
public void close(org.apache.hc.core5.io.CloseMode closeMode) - Specified by:
closein interfaceorg.apache.hc.core5.io.ModalCloseable
-
getRoute
HttpRoute getRoute() -
getState
Object getState() -
getSocketConfig
public org.apache.hc.core5.http.io.SocketConfig getSocketConfig() -
setSocketConfig
public void setSocketConfig(org.apache.hc.core5.http.io.SocketConfig socketConfig) -
getConnectionConfig
- Since:
- 5.2
-
setConnectionConfig
- Since:
- 5.2
-
getTlsConfig
- Since:
- 5.2
-
setTlsConfig
- Since:
- 5.2
-
lease
-
lease
public LeaseRequest lease(String id, HttpRoute route, org.apache.hc.core5.util.Timeout requestTimeout, Object state) Description copied from interface:HttpClientConnectionManagerReturns aLeaseRequestobject which can be used to obtain aConnectionEndpointto cancel the request by callingCancellable.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 callingHttpClientConnectionManager.connect(ConnectionEndpoint, TimeValue, HttpContext)in order to connect directly to the target or to the first proxy hop, and optionally callingHttpClientConnectionManager.upgrade(ConnectionEndpoint, HttpContext)method to upgrade the underlying transport to Transport Layer Security after having executed aCONNECTmethod to all intermediate proxy hops.- Specified by:
leasein interfaceHttpClientConnectionManager- Parameters:
id- unique operation ID ornull.route- HTTP route of the requested connection.requestTimeout- lease request timeout.state- expected state of the connection ornullif the connection is not expected to carry any state.
-
closeConnection
private void closeConnection(org.apache.hc.core5.io.CloseMode closeMode) -
checkExpiry
private void checkExpiry() -
validate
private void validate() -
getConnection
- Throws:
IOException
-
cast
private BasicHttpClientConnectionManager.InternalConnectionEndpoint cast(ConnectionEndpoint endpoint) -
release
public void release(ConnectionEndpoint endpoint, Object state, org.apache.hc.core5.util.TimeValue keepAlive) Description copied from interface:HttpClientConnectionManagerReleases the endpoint 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 usingvalidDurationandtimeUnitparameters.- Specified by:
releasein interfaceHttpClientConnectionManager- Parameters:
endpoint- the managed endpoint.state- the new connection state ofnullif state-less.keepAlive- the duration of time this connection is valid for reuse.
-
connect
public void connect(ConnectionEndpoint endpoint, org.apache.hc.core5.util.TimeValue timeout, org.apache.hc.core5.http.protocol.HttpContext context) throws IOException Description copied from interface:HttpClientConnectionManagerConnects 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).- Specified by:
connectin interfaceHttpClientConnectionManager- Parameters:
endpoint- the managed endpoint.timeout- connect timeout.context- the actual HTTP context.- Throws:
IOException
-
upgrade
public void upgrade(ConnectionEndpoint endpoint, org.apache.hc.core5.http.protocol.HttpContext context) throws IOException Description copied from interface:HttpClientConnectionManagerUpgrades transport security of the given endpoint by using the TLS security protocol.- Specified by:
upgradein interfaceHttpClientConnectionManager- Parameters:
endpoint- the managed endpoint.context- the actual HTTP context.- Throws:
IOException
-
closeExpired
public void closeExpired() -
closeIdle
public void closeIdle(org.apache.hc.core5.util.TimeValue idleTime) -
getValidateAfterInactivity
Deprecated.- Since:
- 5.1
- See Also:
-
setValidateAfterInactivity
@Deprecated public void setValidateAfterInactivity(org.apache.hc.core5.util.TimeValue validateAfterInactivity) Deprecated.Defines period of inactivity after which persistent connections must be re-validated prior to beinglease(String, HttpRoute, Object)leased} to the consumer. Negative values passed to this method disable connection validation. This check helps detect connections that have become stale (half-closed) while kept inactive in the pool.- Since:
- 5.1
-
isClosed
boolean isClosed()Method that can be called to determine whether the connection manager has been shut down and is closed or not.- Returns:
trueif the connection manager has been shut down and is closed, otherwise returnfalse.
-
getConnectionConfig()