Class ConnectionConfig.Builder

java.lang.Object
org.apache.hc.client5.http.config.ConnectionConfig.Builder
Enclosing class:
ConnectionConfig

public static class ConnectionConfig.Builder extends Object
Builder for ConnectionConfig.
Since:
5.2
  • Field Details

    • socketTimeout

      private org.apache.hc.core5.util.Timeout socketTimeout
    • connectTimeout

      private org.apache.hc.core5.util.Timeout connectTimeout
    • idleTimeout

      private org.apache.hc.core5.util.Timeout idleTimeout
    • validateAfterInactivity

      private org.apache.hc.core5.util.TimeValue validateAfterInactivity
    • timeToLive

      private org.apache.hc.core5.util.TimeValue timeToLive
  • Constructor Details

    • Builder

      Builder()
  • Method Details

    • setSocketTimeout

      public ConnectionConfig.Builder setSocketTimeout(int soTimeout, TimeUnit timeUnit)
      Sets the default socket timeout value for I/O operations on connections created by this configuration.
      Parameters:
      soTimeout - The default socket timeout value for I/O operations.
      timeUnit - The time unit of the soTimeout parameter.
      Returns:
      this instance.
      See Also:
    • setSocketTimeout

      public ConnectionConfig.Builder setSocketTimeout(org.apache.hc.core5.util.Timeout soTimeout)
      Sets the default socket timeout value for I/O operations on connections created by this configuration. A timeout value of zero is interpreted as an infinite timeout.

      This value acts as a baseline at the connection management layer. This parameter overrides the socket timeout setting applied at the I/O layer and in its tuen can overridden by settings applied at the protocol layer for the duration of a message exchange.

      Default: null (undefined)

      Parameters:
      soTimeout - The default socket timeout value for I/O operations.
      Returns:
      this instance.
    • setConnectTimeout

      public ConnectionConfig.Builder setConnectTimeout(org.apache.hc.core5.util.Timeout connectTimeout)
      Sets the timeout until a new connection is fully established.

      A timeout value of zero is interpreted as an infinite timeout.

      Default: 3 minutes

      Parameters:
      connectTimeout - The timeout until a new connection is fully established.
      Returns:
      this instance.
    • setConnectTimeout

      public ConnectionConfig.Builder setConnectTimeout(long connectTimeout, TimeUnit timeUnit)
      Sets the timeout until a new connection is fully established.
      Parameters:
      connectTimeout - The timeout until a new connection is fully established.
      timeUnit - The time unit of the timeout parameter.
      Returns:
      this instance.
      See Also:
    • setIdleTimeout

      public ConnectionConfig.Builder setIdleTimeout(org.apache.hc.core5.util.Timeout idleTimeout)
      Determines the maximum period of idleness for a connection. Connections that are idle for longer than idleTimeout are no longer eligible for reuse.

      A timeout value of zero is interpreted as an infinite timeout.

      Default: null (undefined)

      Parameters:
      idleTimeout - The maximum period of idleness for a connection.
      Returns:
      this instance.
      Since:
      5.6
    • setIdleTimeout

      public ConnectionConfig.Builder setIdleTimeout(long idleTimeout, TimeUnit timeUnit)
      Sets the maximum period of idleness for a connection.

      Connections that are idle for longer than idleTimeout are no longer eligible for reuse.

      Parameters:
      idleTimeout - The maximum period of idleness for a connection.
      timeUnit -
      Returns:
      this instance.
      See Also:
    • setValidateAfterInactivity

      public ConnectionConfig.Builder setValidateAfterInactivity(org.apache.hc.core5.util.TimeValue validateAfterInactivity)
      Sets the period of inactivity after which persistent connections must be re-validated prior to being leased to the consumer. Negative values passed to this method disable connection validation.

      Default: null (undefined)

      Parameters:
      validateAfterInactivity - The period of inactivity after which persistent connections must be re-validated.
      Returns:
      this instance.
    • setValidateAfterInactivity

      public ConnectionConfig.Builder setValidateAfterInactivity(long validateAfterInactivity, TimeUnit timeUnit)
      Sets the period of inactivity after which persistent connections must be re-validated prior to being leased to the consumer.
      Parameters:
      validateAfterInactivity - The period of inactivity after which persistent connections must be re-validated.
      timeUnit - The time unit of the validateAfterInactivity parameter.
      Returns:
      this instance.
      See Also:
    • setTimeToLive

      public ConnectionConfig.Builder setTimeToLive(org.apache.hc.core5.util.TimeValue timeToLive)
      Defines the total span of time connections can be kept alive or execute requests.

      Default: null (undefined)

      Parameters:
      timeToLive - The total span of time connections can be kept alive or execute requests.
      Returns:
      this instance.
    • setTimeToLive

      public ConnectionConfig.Builder setTimeToLive(long timeToLive, TimeUnit timeUnit)
      Sets the total span of time connections can be kept alive or execute requests.
      Parameters:
      timeToLive - The total span of time connections can be kept alive or execute requests.
      timeUnit - The time unit of the timeToLive parameter.
      Returns:
      this instance.
      See Also:
    • build

      public ConnectionConfig build()
      Builds a new ConnectionConfig instance based on the values provided to the setters methods.
      Returns:
      a new ConnectionConfig instance.