Class BasicHttpClientConnectionManager

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, HttpClientConnectionManager, org.apache.hc.core5.io.ModalCloseable

    @Contract(threading=SAFE)
    public class BasicHttpClientConnectionManager
    extends java.lang.Object
    implements HttpClientConnectionManager
    A connection manager for a single connection. This connection manager maintains only one active connection. Even though this class is fully thread-safe it ought to be used by one execution thread only, as only one thread a time can lease the connection at a time.

    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
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • COUNT

        private static final java.util.concurrent.atomic.AtomicLong COUNT
      • id

        private final java.lang.String id
      • state

        private java.lang.Object 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
      • closed

        private final java.util.concurrent.atomic.AtomicBoolean closed
    • Constructor Detail

      • 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 Detail

      • getDefaultRegistry

        private static org.apache.hc.core5.http.config.Registry<ConnectionSocketFactory> getDefaultRegistry()
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • close

        public void close​(org.apache.hc.core5.io.CloseMode closeMode)
        Specified by:
        close in interface org.apache.hc.core5.io.ModalCloseable
      • getState

        java.lang.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

        public ConnectionConfig getConnectionConfig()
        Since:
        5.2
      • setConnectionConfig

        public void setConnectionConfig​(ConnectionConfig connectionConfig)
        Since:
        5.2
      • getTlsConfig

        public TlsConfig getTlsConfig()
        Since:
        5.2
      • setTlsConfig

        public void setTlsConfig​(TlsConfig tlsConfig)
        Since:
        5.2
      • closeConnection

        private void closeConnection​(org.apache.hc.core5.io.CloseMode closeMode)
      • checkExpiry

        private void checkExpiry()
      • validate

        private void validate()
      • release

        public void release​(ConnectionEndpoint endpoint,
                            java.lang.Object state,
                            org.apache.hc.core5.util.TimeValue keepAlive)
        Description copied from interface: HttpClientConnectionManager
        Releases 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 using validDuration and timeUnit parameters.
        Specified by:
        release in interface HttpClientConnectionManager
        Parameters:
        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.
      • connect

        public void connect​(ConnectionEndpoint endpoint,
                            org.apache.hc.core5.util.TimeValue timeout,
                            org.apache.hc.core5.http.protocol.HttpContext context)
                     throws java.io.IOException
        Description copied from interface: HttpClientConnectionManager
        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).
        Specified by:
        connect in interface HttpClientConnectionManager
        Parameters:
        endpoint - the managed endpoint.
        timeout - connect timeout.
        context - the actual HTTP context.
        Throws:
        java.io.IOException
      • upgrade

        public void upgrade​(ConnectionEndpoint endpoint,
                            org.apache.hc.core5.http.protocol.HttpContext context)
                     throws java.io.IOException
        Description copied from interface: HttpClientConnectionManager
        Upgrades transport security of the given endpoint by using the TLS security protocol.
        Specified by:
        upgrade in interface HttpClientConnectionManager
        Parameters:
        endpoint - the managed endpoint.
        context - the actual HTTP context.
        Throws:
        java.io.IOException
      • closeExpired

        public void closeExpired()
      • closeIdle

        public void closeIdle​(org.apache.hc.core5.util.TimeValue idleTime)
      • setValidateAfterInactivity

        @Deprecated
        public void setValidateAfterInactivity​(org.apache.hc.core5.util.TimeValue validateAfterInactivity)
        Defines period of inactivity after which persistent connections must be re-validated prior to being lease(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:
        true if the connection manager has been shut down and is closed, otherwise return false.