Class ConnectionProvider.ConnectionPoolSpec<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>
- All Implemented Interfaces:
Supplier<SPEC>
- Direct Known Subclasses:
ConnectionProvider.Builder
,ConnectionProvider.HostSpecificSpec
- Enclosing interface:
- ConnectionProvider
- Since:
- 0.9.5
-
Method Summary
Modifier and TypeMethodDescriptionfinal SPEC
allocationStrategy
(ConnectionProvider.AllocationStrategy<?> allocationStrategy) Limits in how many connections can be allocated and managed by the pool are driven by the providedConnectionProvider.AllocationStrategy
.final SPEC
evictInBackground
(Duration evictionInterval) Set the options to use for configuringConnectionProvider
background eviction.final SPEC
evictionPredicate
(BiPredicate<Connection, ConnectionProvider.ConnectionMetadata> evictionPredicate) Set the options to use for configuringConnectionProvider
custom eviction predicate.final SPEC
fifo()
Configure the pool so that if there are idle connections (i.e.get()
final SPEC
lifo()
Configure the pool so that if there are idle connections (i.e.final SPEC
maxConnections
(int maxConnections) Set the options to use for configuringConnectionProvider
maximum connections per connection pool.final SPEC
maxIdleTime
(Duration maxIdleTime) Set the options to use for configuringConnectionProvider
max idle time (resolution: ms).final SPEC
maxLifeTime
(Duration maxLifeTime) Set the options to use for configuringConnectionProvider
max life time (resolution: ms).final SPEC
metrics
(boolean metricsEnabled) Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry
under the nameMetrics.CONNECTION_PROVIDER_PREFIX
.final SPEC
metrics
(boolean metricsEnabled, Supplier<? extends ConnectionProvider.MeterRegistrar> registrar) Specifies whether the metrics are enabled on theConnectionProvider
.final SPEC
pendingAcquireMaxCount
(int pendingAcquireMaxCount) Set the options to use for configuringConnectionProvider
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.final SPEC
pendingAcquireTimeout
(Duration pendingAcquireTimeout) Set the options to use for configuringConnectionProvider
acquire timeout (resolution: ms).final SPEC
pendingAcquireTimer
(BiFunction<Runnable, Duration, Disposable> pendingAcquireTimer) Set the option to use for configuringConnectionProvider
pending acquire timer.
-
Method Details
-
pendingAcquireTimeout
Set the options to use for configuringConnectionProvider
acquire timeout (resolution: ms). Default toConnectionProvider.DEFAULT_POOL_ACQUIRE_TIMEOUT
.- Parameters:
pendingAcquireTimeout
- the maximum time after which a pending acquire must complete or theTimeoutException
will be thrown (resolution: ms)- Returns:
- this
- Throws:
NullPointerException
- if pendingAcquireTimeout is null
-
maxConnections
Set the options to use for configuringConnectionProvider
maximum connections per connection pool. This is a pre-made allocation strategy where only max connections is specified. Custom allocation strategies can be provided viaallocationStrategy(AllocationStrategy)
. Default toConnectionProvider.DEFAULT_POOL_MAX_CONNECTIONS
.- Parameters:
maxConnections
- the maximum number of connections (per connection pool) before start pending- Returns:
- this
- Throws:
IllegalArgumentException
- if maxConnections is negative- See Also:
-
pendingAcquireMaxCount
Set the options to use for configuringConnectionProvider
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 to2 * max connections
.- Parameters:
pendingAcquireMaxCount
- the maximum number of registered requests for acquire to keep in a pending queue- Returns:
- this
- Throws:
IllegalArgumentException
- if pendingAcquireMaxCount is negative
-
maxIdleTime
Set the options to use for configuringConnectionProvider
max idle time (resolution: ms). Default toConnectionProvider.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.- Parameters:
maxIdleTime
- theDuration
after which the channel will be closed when idle (resolution: ms)- Returns:
- this
- Throws:
NullPointerException
- if maxIdleTime is null
-
maxLifeTime
Set the options to use for configuringConnectionProvider
max life time (resolution: ms). Default toConnectionProvider.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.- Parameters:
maxLifeTime
- theDuration
after which the channel will be closed (resolution: ms)- Returns:
- this
- Throws:
NullPointerException
- if maxLifeTime is null
-
evictionPredicate
public final SPEC evictionPredicate(BiPredicate<Connection, ConnectionProvider.ConnectionMetadata> evictionPredicate) Set the options to use for configuringConnectionProvider
custom eviction predicate.Unless a custom eviction predicate is specified, the connection is evicted when not active or not persistent, If
maxLifeTime(Duration)
and/ormaxIdleTime(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.- Parameters:
evictionPredicate
- The predicate function that evaluates whether a connection should be evicted- Returns:
- this
- Throws:
NullPointerException
- if evictionPredicate is null
-
metrics
Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry
under the nameMetrics.CONNECTION_PROVIDER_PREFIX
. Applications can separately register their ownfilters
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.
- Parameters:
metricsEnabled
- true enables metrics collection; false disables it- Returns:
- this
-
metrics
public final SPEC metrics(boolean metricsEnabled, Supplier<? extends ConnectionProvider.MeterRegistrar> registrar) Specifies whether the metrics are enabled on theConnectionProvider
. All generated metrics are provided to the specified registrar which is only instantiated if metrics are being enabled.- Parameters:
metricsEnabled
- true enables metrics collection; false disables itregistrar
- a supplier for theConnectionProvider.MeterRegistrar
- Returns:
- this
- Since:
- 0.9.11
-
lifo
Configure the pool so that if there are idle connections (i.e. pool is under-utilized), the next acquire operation will get the Most Recently Used connection (MRU, i.e. the connection that was released last among the current idle connections).Note: This configuration is not applicable for
TcpClient
. A TCP connection is always closed and never returned to the pool.- Returns:
- this
-
fifo
Configure the pool so that if there are idle connections (i.e. pool is under-utilized), the next acquire operation will get the Least Recently Used connection (LRU, i.e. the connection that was released first among the current idle connections).Note: This configuration is not applicable for
TcpClient
. A TCP connection is always closed and never returned to the pool.- Returns:
- this
-
evictInBackground
Set the options to use for configuringConnectionProvider
background eviction. When a background eviction is enabled, the connection pool is regularly checked for connections, that are applicable for removal. Default toEVICT_IN_BACKGROUND_DISABLED
- the background eviction is disabled. Providing anevictionInterval
ofzero
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.- Parameters:
evictionInterval
- specifies the interval to be used for checking the connection pool, (resolution: ns)- Returns:
- this
-
pendingAcquireTimer
Set the option to use for configuringConnectionProvider
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 aDuration
which is the one configured bypendingAcquireTimeout(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());
- Parameters:
pendingAcquireTimer
- the function to apply when scheduling pending acquire timers- Returns:
- this
- Throws:
NullPointerException
- if pendingAcquireTimer is null- Since:
- 1.0.20
- See Also:
-
allocationStrategy
Limits in how many connections can be allocated and managed by the pool are driven by the providedConnectionProvider.AllocationStrategy
. This is a customization escape hatch that replaces the last configured strategy, but most cases should be covered by theConnectionProvider.maxConnections()
pre-made allocation strategy.- Parameters:
allocationStrategy
- theConnectionProvider.AllocationStrategy
to use- Returns:
- this
- Since:
- 1.0.20
- See Also:
-
get
- Specified by:
get
in interfaceSupplier<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>
-