public static class ConnectionProvider.ConnectionPoolSpec<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>> extends Object implements Supplier<SPEC>
Modifier and Type | Method and Description |
---|---|
SPEC |
allocationStrategy(ConnectionProvider.AllocationStrategy<?> allocationStrategy)
Limits in how many connections can be allocated and managed by the pool are driven by the
provided
ConnectionProvider.AllocationStrategy . |
SPEC |
evictInBackground(Duration evictionInterval)
Set the options to use for configuring
ConnectionProvider background eviction. |
SPEC |
evictionPredicate(BiPredicate<Connection,ConnectionProvider.ConnectionMetadata> evictionPredicate)
Set the options to use for configuring
ConnectionProvider custom eviction predicate. |
SPEC |
fifo()
Configure the pool so that if there are idle connections (i.e.
|
SPEC |
get() |
SPEC |
lifo()
Configure the pool so that if there are idle connections (i.e.
|
SPEC |
maxConnections(int maxConnections)
Set the options to use for configuring
ConnectionProvider maximum connections per connection pool. |
SPEC |
maxIdleTime(Duration maxIdleTime)
Set the options to use for configuring
ConnectionProvider max idle time (resolution: ms). |
SPEC |
maxLifeTime(Duration maxLifeTime)
Set the options to use for configuring
ConnectionProvider max life time (resolution: ms). |
SPEC |
metrics(boolean metricsEnabled)
Whether to enable metrics to be collected and registered in Micrometer's
globalRegistry
under the name Metrics.CONNECTION_PROVIDER_PREFIX . |
SPEC |
metrics(boolean metricsEnabled,
Supplier<? extends ConnectionProvider.MeterRegistrar> registrar)
Specifies whether the metrics are enabled on the
ConnectionProvider . |
SPEC |
pendingAcquireMaxCount(int pendingAcquireMaxCount)
Set the options to use for configuring
ConnectionProvider the maximum number of registered
requests for acquire to keep in a pending queue
When invoked with -1 the pending queue will not have upper limit. |
SPEC |
pendingAcquireTimeout(Duration pendingAcquireTimeout)
Set the options to use for configuring
ConnectionProvider acquire timeout (resolution: ms). |
SPEC |
pendingAcquireTimer(BiFunction<Runnable,Duration,Disposable> pendingAcquireTimer)
Set the option to use for configuring
ConnectionProvider pending acquire timer. |
public final SPEC pendingAcquireTimeout(Duration pendingAcquireTimeout)
ConnectionProvider
acquire timeout (resolution: ms).
Default to ConnectionProvider.DEFAULT_POOL_ACQUIRE_TIMEOUT
.pendingAcquireTimeout
- the maximum time after which a pending acquire
must complete or the TimeoutException
will be thrown (resolution: ms)NullPointerException
- if pendingAcquireTimeout is nullpublic final SPEC maxConnections(int maxConnections)
ConnectionProvider
maximum connections per connection pool.
This is a pre-made allocation strategy where only max connections is specified.
Custom allocation strategies can be provided via #allocationStrategy(AllocationStrategy)
.
Default to ConnectionProvider.DEFAULT_POOL_MAX_CONNECTIONS
.maxConnections
- the maximum number of connections (per connection pool) before start pendingIllegalArgumentException
- if maxConnections is negative#allocationStrategy(AllocationStrategy)
public final SPEC pendingAcquireMaxCount(int pendingAcquireMaxCount)
ConnectionProvider
the maximum number of registered
requests for acquire to keep in a pending queue
When invoked with -1 the pending queue will not have upper limit.
Default to 2 * max connections
.pendingAcquireMaxCount
- the maximum number of registered requests for acquire to keep
in a pending queueIllegalArgumentException
- if pendingAcquireMaxCount is negativepublic final SPEC maxIdleTime(Duration maxIdleTime)
ConnectionProvider
max idle time (resolution: ms).
Default to ConnectionProvider.DEFAULT_POOL_MAX_IDLE_TIME
if specified otherwise - no max idle time.
Note: This configuration is not applicable for TcpClient
.
A TCP connection is always closed and never returned to the pool.
maxIdleTime
- the Duration
after which the channel will be closed when idle (resolution: ms)NullPointerException
- if maxIdleTime is nullpublic final SPEC maxLifeTime(Duration maxLifeTime)
ConnectionProvider
max life time (resolution: ms).
Default to ConnectionProvider.DEFAULT_POOL_MAX_LIFE_TIME
if specified otherwise - no max life time.
Note: This configuration is not applicable for TcpClient
.
A TCP connection is always closed and never returned to the pool.
maxLifeTime
- the Duration
after which the channel will be closed (resolution: ms)NullPointerException
- if maxLifeTime is nullpublic final SPEC evictionPredicate(BiPredicate<Connection,ConnectionProvider.ConnectionMetadata> evictionPredicate)
ConnectionProvider
custom eviction predicate.
Unless a custom eviction predicate is specified, the connection is evicted when not active or not persistent,
If maxLifeTime(Duration)
and/or maxIdleTime(Duration)
settings are configured,
they are also taken into account.
Otherwise only the custom eviction predicate is invoked.
Note: This configuration is not applicable for TcpClient
.
A TCP connection is always closed and never returned to the pool.
evictionPredicate
- The predicate function that evaluates whether a connection should be evictedNullPointerException
- if evictionPredicate is nullpublic final SPEC metrics(boolean metricsEnabled)
globalRegistry
under the name Metrics.CONNECTION_PROVIDER_PREFIX
.
Applications can separately register their own
filters
associated with this name.
For example, to put an upper bound on the number of tags produced:
MeterFilter filter = ... ; Metrics.globalRegistry.config().meterFilter(MeterFilter.maximumAllowableTags(CONNECTION_PROVIDER_PREFIX, 100, filter));
By default this is not enabled.
metricsEnabled
- true enables metrics collection; false disables itpublic final SPEC metrics(boolean metricsEnabled, Supplier<? extends ConnectionProvider.MeterRegistrar> registrar)
ConnectionProvider
.
All generated metrics are provided to the specified registrar
which is only instantiated if metrics are being enabled.metricsEnabled
- true enables metrics collection; false disables itregistrar
- a supplier for the ConnectionProvider.MeterRegistrar
public final SPEC lifo()
Note: This configuration is not applicable for TcpClient
.
A TCP connection is always closed and never returned to the pool.
public final SPEC fifo()
Note: This configuration is not applicable for TcpClient
.
A TCP connection is always closed and never returned to the pool.
public final SPEC evictInBackground(Duration evictionInterval)
ConnectionProvider
background eviction.
When a background eviction is enabled, the connection pool is regularly checked for connections,
that are applicable for removal.
Default to EVICT_IN_BACKGROUND_DISABLED
- the background eviction is disabled.
Providing an evictionInterval
of zero
means the background eviction is disabled.
Note: This configuration is not applicable for TcpClient
.
A TCP connection is always closed and never returned to the pool.
evictionInterval
- specifies the interval to be used for checking the connection pool, (resolution: ns)public final SPEC pendingAcquireTimer(BiFunction<Runnable,Duration,Disposable> pendingAcquireTimer)
ConnectionProvider
pending acquire timer.
The pending acquire timer must be specified as a function which is used to schedule a pending acquire timeout
when there is no idle connection and no new connection can be created currently.
The function takes as argument a Duration
which is the one configured by pendingAcquireTimeout(Duration)
.
Use this function if you want to specify your own implementation for scheduling pending acquire timers.
Default to Schedulers.parallel()
.
Examples using Netty HashedWheelTimer implementation:
final static HashedWheelTimer wheel = new HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024);
HttpClient client = HttpClient.create(
ConnectionProvider.builder("myprovider")
.pendingAcquireTimeout(Duration.ofMillis(10000))
.pendingAcquireTimer((r, d) -> {
Timeout t = wheel.newTimeout(timeout -> r.run(), d.toMillis(), TimeUnit.MILLISECONDS);
return () -> t.cancel();
})
.build());
pendingAcquireTimer
- the function to apply when scheduling pending acquire timersNullPointerException
- if pendingAcquireTimer is nullpendingAcquireTimeout(Duration)
public final SPEC allocationStrategy(ConnectionProvider.AllocationStrategy<?> allocationStrategy)
ConnectionProvider.AllocationStrategy
. This is a customization escape hatch that replaces the last
configured strategy, but most cases should be covered by the ConnectionProvider.maxConnections()
pre-made allocation strategy.allocationStrategy
- the ConnectionProvider.AllocationStrategy
to useConnectionProvider.maxConnections()