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 SPECallocationStrategy(ConnectionProvider.AllocationStrategy<?> allocationStrategy) Limits in how many connections can be allocated and managed by the pool are driven by the providedConnectionProvider.AllocationStrategy.final SPECevictInBackground(Duration evictionInterval) Set the options to use for configuringConnectionProviderbackground eviction.final SPECevictionPredicate(BiPredicate<Connection, ConnectionProvider.ConnectionMetadata> evictionPredicate) Set the options to use for configuringConnectionProvidercustom eviction predicate.final SPECfifo()Configure the pool so that if there are idle connections (i.e.get()final SPEClifo()Configure the pool so that if there are idle connections (i.e.final SPECmaxConnections(int maxConnections) Set the options to use for configuringConnectionProvidermaximum connections per connection pool.final SPECmaxIdleTime(Duration maxIdleTime) Set the options to use for configuringConnectionProvidermax idle time (resolution: ms).final SPECmaxLifeTime(Duration maxLifeTime) Set the options to use for configuringConnectionProvidermax life time (resolution: ms).final SPECmetrics(boolean metricsEnabled) Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistryunder the nameMetrics.CONNECTION_PROVIDER_PREFIX.final SPECmetrics(boolean metricsEnabled, Supplier<? extends ConnectionProvider.MeterRegistrar> registrar) Specifies whether the metrics are enabled on theConnectionProvider.final SPECpendingAcquireMaxCount(int pendingAcquireMaxCount) Set the options to use for configuringConnectionProviderthe 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 SPECpendingAcquireTimeout(Duration pendingAcquireTimeout) Set the options to use for configuringConnectionProvideracquire timeout (resolution: ms).final SPECpendingAcquireTimer(BiFunction<Runnable, Duration, Disposable> pendingAcquireTimer) Set the option to use for configuringConnectionProviderpending acquire timer.
-
Method Details
-
pendingAcquireTimeout
Set the options to use for configuringConnectionProvideracquire timeout (resolution: ms). Default toConnectionProvider.DEFAULT_POOL_ACQUIRE_TIMEOUT.- Parameters:
pendingAcquireTimeout- the maximum time after which a pending acquire must complete or theTimeoutExceptionwill be thrown (resolution: ms)- Returns:
- this
- Throws:
NullPointerException- if pendingAcquireTimeout is null
-
maxConnections
Set the options to use for configuringConnectionProvidermaximum 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 configuringConnectionProviderthe 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 configuringConnectionProvidermax idle time (resolution: ms). Default toConnectionProvider.DEFAULT_POOL_MAX_IDLE_TIMEif 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- theDurationafter 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 configuringConnectionProvidermax life time (resolution: ms). Default toConnectionProvider.DEFAULT_POOL_MAX_LIFE_TIMEif 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- theDurationafter 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 configuringConnectionProvidercustom 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'sglobalRegistryunder the nameMetrics.CONNECTION_PROVIDER_PREFIX. Applications can separately register their ownfiltersassociated 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 configuringConnectionProviderbackground 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 anevictionIntervalofzeromeans 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 configuringConnectionProviderpending 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 aDurationwhich 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.AllocationStrategyto use- Returns:
- this
- Since:
- 1.0.20
- See Also:
-
get
- Specified by:
getin interfaceSupplier<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>
-