public static final class ConnectionProvider.Builder extends ConnectionProvider.ConnectionPoolSpec<ConnectionProvider.Builder>
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.Modifier and Type | Method and Description |
---|---|
ConnectionProvider |
build()
Builds new ConnectionProvider.
|
ConnectionProvider.Builder |
disposeInactivePoolsInBackground(Duration disposeInterval,
Duration poolInactivity)
Set the options to use for configuring
ConnectionProvider background disposal for inactive connection pools. |
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. |
ConnectionProvider.Builder |
forRemoteHost(SocketAddress remoteHost,
Consumer<ConnectionProvider.HostSpecificSpec> spec)
Connection pool configuration for a specific remote host.
|
ConnectionProvider.Builder |
name(String name)
ConnectionProvider name is used for metrics. |
allocationStrategy, evictInBackground, evictionPredicate, fifo, get, lifo, maxConnections, maxIdleTime, maxLifeTime, metrics, metrics, pendingAcquireMaxCount, pendingAcquireTimeout, pendingAcquireTimer
public final ConnectionProvider.Builder name(String name)
ConnectionProvider
name is used for metrics.name
- ConnectionProvider
nameNullPointerException
- if name is nullpublic final ConnectionProvider.Builder disposeInactivePoolsInBackground(Duration disposeInterval, Duration poolInactivity)
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.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)public final ConnectionProvider.Builder disposeTimeout(Duration timeout)
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.
timeout
- the maximum Duration
for graceful shutdown before full shutdown is forced (resolution: ms)public final ConnectionProvider.Builder forRemoteHost(SocketAddress remoteHost, Consumer<ConnectionProvider.HostSpecificSpec> spec)
remoteHost
- the remote hostspec
- connection pool configuration for this remote hostNullPointerException
- if remoteHost or/and spec are nullpublic ConnectionProvider build()