Class ConnectionProvider.Builder

All Implemented Interfaces:
Supplier<ConnectionProvider.Builder>
Enclosing interface:
ConnectionProvider

public static final class ConnectionProvider.Builder extends ConnectionProvider.ConnectionPoolSpec<ConnectionProvider.Builder>
Build a ConnectionProvider to cache and reuse a fixed maximum number of Connection. Further connections will be pending acquisition depending on pendingAcquireTime. The maximum number of connections is for the connections in a single connection pool, where a connection pool corresponds to a concrete remote host. The configuration can be either global for all connection pools or be tuned for each individual connection pool, per remote host.
Since:
0.9.5
  • Method Details

    • name

      public final ConnectionProvider.Builder name(String name)
      ConnectionProvider name is used for metrics.
      Parameters:
      name - ConnectionProvider name
      Returns:
      this
      Throws:
      NullPointerException - if name is null
    • disposeInactivePoolsInBackground

      public final ConnectionProvider.Builder disposeInactivePoolsInBackground(Duration disposeInterval, Duration poolInactivity)
      Set the options to use for configuring ConnectionProvider background disposal for inactive connection pools. When this option is enabled, the connection pools are regularly checked whether they are empty and inactive for a specified time, thus applicable for disposal. Connection pool is considered empty when there are no active connections, idle connections and pending acquisitions. Default to DISPOSE_INACTIVE_POOLS_IN_BACKGROUND_DISABLED - the background disposal is disabled. Providing a disposeInterval of zero means the background disposal is disabled.
      Parameters:
      disposeInterval - specifies the interval to be used for checking the connection pool inactivity, (resolution: ms)
      poolInactivity - specifies the duration after which an empty pool with no recorded interactions is considered inactive (resolution: seconds)
      Returns:
      this
      Since:
      1.0.7
    • disposeTimeout

      public final ConnectionProvider.Builder disposeTimeout(Duration timeout)
      When ConnectionProvider.dispose() or ConnectionProvider.disposeLater() is called, trigger a graceful shutdown for the connection pools, with this grace period timeout. From there on, all calls for acquiring a connection will fail fast with an exception. However, for the provided Duration, pending acquires will get a chance to be served.

      Note: The rejection of new acquires and the grace timer start immediately, irrespective of subscription to the Mono returned by ConnectionProvider.disposeLater(). Subsequent calls return the same Mono, effectively getting notifications from the first graceful shutdown call and ignoring subsequently provided timeouts.

      Parameters:
      timeout - the maximum Duration for graceful shutdown before full shutdown is forced (resolution: ms)
      Returns:
      this
      Since:
      1.0.12
    • forRemoteHost

      Connection pool configuration for a specific remote host.
      Parameters:
      remoteHost - the remote host
      spec - connection pool configuration for this remote host
      Returns:
      this
      Throws:
      NullPointerException - if remoteHost or/and spec are null
    • maxConnectionPools

      public ConnectionProvider.Builder maxConnectionPools(int maxConnectionPools)
      Specifies the maximum number of connection pools that the provider can create. If the number of connection pools created exceeds this value, a warning message is logged. The value must be strictly positive or -1; otherwise, the connection pools check is ignored. Setting the configuration to -1 disables the setting.
      Parameters:
      maxConnectionPools - the maximum number of connection pools that can be created
      Returns:
      the current ConnectionProvider.Builder instance with the updated configuration
      Since:
      1.2.2
    • build

      public ConnectionProvider build()
      Builds new ConnectionProvider.
      Returns:
      builds new ConnectionProvider