org.apache.hc.client5.http.impl.io

## Class BasicHttpClientConnectionManager

- java.lang.Object
- - org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager

- All Implemented Interfaces:
    Closeable, AutoCloseable, HttpClientConnectionManager, org.apache.hc.core5.io.ModalCloseable

      @Contract(threading=SAFE)
      public class BasicHttpClientConnectionManager
      extends 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

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicHttpClientConnectionManager()`
    `BasicHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory)`
    `BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry)` Deprecated. Use `create(Lookup)`
    `BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory)` Deprecated. Use `create(Lookup, HttpConnectionFactory)`
    `BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver)` Deprecated. Use `create(SchemePortResolver, DnsResolver, Lookup, HttpConnectionFactory)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `void` | `close(org.apache.hc.core5.io.CloseMode closeMode)`
    `void` | `closeExpired()`
    `void` | `closeIdle(org.apache.hc.core5.util.TimeValue idleTime)`
    `void` | `connect(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).
    `static BasicHttpClientConnectionManager` | `create(org.apache.hc.core5.http.config.Lookup<TlsSocketStrategy> tlsSocketStrategyRegistry)`
    `static BasicHttpClientConnectionManager` | `create(org.apache.hc.core5.http.config.Lookup<TlsSocketStrategy> tlsSocketStrategyRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory)`
    `static BasicHttpClientConnectionManager` | `create(SchemePortResolver schemePortResolver, DnsResolver dnsResolver, org.apache.hc.core5.http.config.Lookup<TlsSocketStrategy> tlsSocketStrategyRegistry, org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory)`
    `ConnectionConfig` | `getConnectionConfig()`
    `org.apache.hc.core5.http.io.SocketConfig` | `getSocketConfig()`
    `TlsConfig` | `getTlsConfig()`
    `org.apache.hc.core5.util.TimeValue` | `getValidateAfterInactivity()` Deprecated. Use `getConnectionConfig()`
    `boolean` | `isClosed()` Method that can be called to determine whether the connection manager has been shut down and is closed or not.
    `LeaseRequest` | `lease(String id, HttpRoute route, Object state)`
    `LeaseRequest` | `lease(String id, HttpRoute route, org.apache.hc.core5.util.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, org.apache.hc.core5.util.TimeValue keepAlive)` Releases the endpoint back to the manager making it potentially re-usable by other consumers.
    `void` | `setConnectionConfig(ConnectionConfig connectionConfig)`
    `void` | `setSocketConfig(org.apache.hc.core5.http.io.SocketConfig socketConfig)`
    `void` | `setTlsConfig(TlsConfig tlsConfig)`
    `void` | `setValidateAfterInactivity(org.apache.hc.core5.util.TimeValue validateAfterInactivity)` Deprecated. Use `setConnectionConfig(ConnectionConfig)`
    `void` | `upgrade(ConnectionEndpoint endpoint, org.apache.hc.core5.http.protocol.HttpContext context)` Upgrades transport security of the given endpoint by using the TLS security protocol.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BasicHttpClientConnectionManager

          public BasicHttpClientConnectionManager(HttpClientConnectionOperator httpClientConnectionOperator,
                                                  org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory)

      Since:
        4.4

    - #### BasicHttpClientConnectionManager

          @Deprecated
          public BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry,
                                                              org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
                                                              SchemePortResolver schemePortResolver,
                                                              DnsResolver dnsResolver)

      Deprecated. Use `create(SchemePortResolver, DnsResolver, Lookup, HttpConnectionFactory)`

    - #### BasicHttpClientConnectionManager

          @Deprecated
          public BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry,
                                                              org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory)

      Deprecated. Use `create(Lookup, HttpConnectionFactory)`

    - #### BasicHttpClientConnectionManager

          @Deprecated
          public BasicHttpClientConnectionManager(org.apache.hc.core5.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry)

      Deprecated. Use `create(Lookup)`

    - #### BasicHttpClientConnectionManager

          public BasicHttpClientConnectionManager()

  - ### Method Detail

    - #### create

          public static BasicHttpClientConnectionManager create(SchemePortResolver schemePortResolver,
                                                                DnsResolver dnsResolver,
                                                                org.apache.hc.core5.http.config.Lookup<TlsSocketStrategy> tlsSocketStrategyRegistry,
                                                                org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory)

      Since:
        5.4

    - #### create

          public static BasicHttpClientConnectionManager create(org.apache.hc.core5.http.config.Lookup<TlsSocketStrategy> tlsSocketStrategyRegistry,
                                                                org.apache.hc.core5.http.io.HttpConnectionFactory<ManagedHttpClientConnection> connFactory)

      Since:
        5.4

    - #### create

          public static BasicHttpClientConnectionManager create(org.apache.hc.core5.http.config.Lookup<TlsSocketStrategy> tlsSocketStrategyRegistry)

      Since:
        5.4

    - #### close

          public void close()

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`

    - #### close

          public void close(org.apache.hc.core5.io.CloseMode closeMode)

      Specified by:
        `close` in interface `org.apache.hc.core5.io.ModalCloseable`

    - #### 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

    - #### lease

          public LeaseRequest lease(String id,
                                    HttpRoute route,
                                    Object state)

    - #### lease

          public LeaseRequest lease(String id,
                                    HttpRoute route,
                                    org.apache.hc.core5.util.Timeout requestTimeout,
                                    Object state)

      Description copied from interface: `HttpClientConnectionManager`
      Returns a `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.

      Specified by:
        `lease` in interface `HttpClientConnectionManager`
      Parameters:
        `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.

    - #### release

          public void release(ConnectionEndpoint endpoint,
                              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 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:
        `IOException`

    - #### upgrade

          public void upgrade(ConnectionEndpoint endpoint,
                              org.apache.hc.core5.http.protocol.HttpContext context)
                       throws 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:
        `IOException`

    - #### closeExpired

          public void closeExpired()

    - #### closeIdle

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

    - #### getValidateAfterInactivity

          @Deprecated
          public org.apache.hc.core5.util.TimeValue getValidateAfterInactivity()

      Deprecated. Use `getConnectionConfig()`
      Since:
        5.1
      See Also:
        `setValidateAfterInactivity(TimeValue)`

    - #### setValidateAfterInactivity

          @Deprecated
          public void setValidateAfterInactivity(org.apache.hc.core5.util.TimeValue validateAfterInactivity)

      Deprecated. Use `setConnectionConfig(ConnectionConfig)`
      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

          public 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`.
      Since:
        5.4

Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.