Package reactor.pool
Class DefaultPoolConfig<POOLABLE>
java.lang.Object
reactor.pool.DefaultPoolConfig<POOLABLE>
- All Implemented Interfaces:
PoolConfig<POOLABLE>
A default
PoolConfig that can be extended to bear more configuration options
with access to a copy constructor for the basic options.- Author:
- Simon Baslé
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Schedulerprotected final AllocationStrategyprotected final Clockprotected final Durationprotected final Schedulerprotected final BiPredicate<POOLABLE, PooledRefMetadata> protected final booleanprotected final Durationprotected final doubleprotected final intprotected final PoolMetricsRecorderprotected final BiFunction<Runnable, Duration, Disposable> -
Constructor Summary
ConstructorsModifierConstructorDescriptionDefaultPoolConfig(Mono<POOLABLE> allocator, AllocationStrategy allocationStrategy, int maxPending, BiFunction<Runnable, Duration, Disposable> pendingAcquireTimer, Function<POOLABLE, ? extends Publisher<Void>> releaseHandler, Function<POOLABLE, ? extends Publisher<Void>> destroyHandler, BiPredicate<POOLABLE, PooledRefMetadata> evictionPredicate, Duration evictInBackgroundInterval, Scheduler evictInBackgroundScheduler, Scheduler acquisitionScheduler, PoolMetricsRecorder metricsRecorder, Clock clock, boolean isIdleLRU) DefaultPoolConfig(Mono<POOLABLE> allocator, AllocationStrategy allocationStrategy, int maxPending, BiFunction<Runnable, Duration, Disposable> pendingAcquireTimer, Function<POOLABLE, ? extends Publisher<Void>> releaseHandler, Function<POOLABLE, ? extends Publisher<Void>> destroyHandler, BiPredicate<POOLABLE, PooledRefMetadata> evictionPredicate, Duration evictInBackgroundInterval, Scheduler evictInBackgroundScheduler, Scheduler acquisitionScheduler, PoolMetricsRecorder metricsRecorder, Clock clock, boolean isIdleLRU, Duration maxLifeTime, double maxLifeTimeVariance) protectedDefaultPoolConfig(PoolConfig<POOLABLE> toCopy) Copy constructor for the benefit of specializations ofPoolConfig. -
Method Summary
Modifier and TypeMethodDescriptionWhen set,Poolimplementation MAY decide to use theSchedulerto publish resources in a more deterministic way: the publishing thread would then always be the same, independently of which thread calledPool.acquire()orPooledRef.release()or on which thread thePoolConfig.allocator()produced new resources.AllocationStrategydefines a strategy / limit for the number of pooled object to allocate.The asynchronous factory that produces new resources, represented as aMono.clock()TheClockto use to timestamp pool lifecycle events like allocation and eviction, which can influence eg.Defines a mechanism of resource destruction, cleaning up state and OS resources it could maintain (eg.If the pool is configured to perform regular eviction checks on the background, returns theDurationrepresenting the interval at which such checks are made.If the pool is configured to perform regular eviction checks on the background, returns theScheduleron which these checks are made.ABiPredicatethat checks if a resource should be destroyed (true) or is still in a valid state for recycling.The maximum lifetime for pooled resources.doubleA variance percentage (0–100) applied toPoolConfig.maxLifeTime()to introduce per-resource jitter.intThe maximum number of pending borrowers to enqueue before failing fast.ThePoolMetricsRecorderto use to collect instrumentation data of thePoolimplementations.The function that defines how timeouts are scheduled when aPool.acquire(Duration)call is made and the acquisition is pending.When a resource isreleased, defines a mechanism of resetting any lingering state of the resource in order for it to become usable again.booleanThe order in which idle (aka available) resources should be used when the pool was under-utilized and a newPool.acquire()is performed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface reactor.pool.PoolConfig
generateMaxLifeTimeMs
-
Field Details
-
pendingAcquireTimer
-
allocator
-
allocationStrategy
-
maxPending
protected final int maxPending -
releaseHandler
-
destroyHandler
-
evictionPredicate
-
evictInBackgroundInterval
-
evictInBackgroundScheduler
-
acquisitionScheduler
-
metricsRecorder
-
clock
-
isIdleLRU
protected final boolean isIdleLRU -
maxLifeTime
-
maxLifeTimeVariance
protected final double maxLifeTimeVariance
-
-
Constructor Details
-
DefaultPoolConfig
public DefaultPoolConfig(Mono<POOLABLE> allocator, AllocationStrategy allocationStrategy, int maxPending, BiFunction<Runnable, Duration, Disposable> pendingAcquireTimer, Function<POOLABLE, ? extends Publisher<Void>> releaseHandler, Function<POOLABLE, ? extends Publisher<Void>> destroyHandler, BiPredicate<POOLABLE, PooledRefMetadata> evictionPredicate, Duration evictInBackgroundInterval, Scheduler evictInBackgroundScheduler, Scheduler acquisitionScheduler, PoolMetricsRecorder metricsRecorder, Clock clock, boolean isIdleLRU) -
DefaultPoolConfig
public DefaultPoolConfig(Mono<POOLABLE> allocator, AllocationStrategy allocationStrategy, int maxPending, BiFunction<Runnable, Duration, Disposable> pendingAcquireTimer, Function<POOLABLE, ? extends Publisher<Void>> releaseHandler, Function<POOLABLE, ? extends Publisher<Void>> destroyHandler, BiPredicate<POOLABLE, PooledRefMetadata> evictionPredicate, Duration evictInBackgroundInterval, Scheduler evictInBackgroundScheduler, Scheduler acquisitionScheduler, PoolMetricsRecorder metricsRecorder, Clock clock, boolean isIdleLRU, Duration maxLifeTime, double maxLifeTimeVariance) -
DefaultPoolConfig
Copy constructor for the benefit of specializations ofPoolConfig.- Parameters:
toCopy- the originalPoolConfigto copy (only standardPoolConfigoptions are copied)
-
-
Method Details
-
allocator
Description copied from interface:PoolConfigThe asynchronous factory that produces new resources, represented as aMono.- Specified by:
allocatorin interfacePoolConfig<POOLABLE>
-
allocationStrategy
Description copied from interface:PoolConfigAllocationStrategydefines a strategy / limit for the number of pooled object to allocate.- Specified by:
allocationStrategyin interfacePoolConfig<POOLABLE>
-
maxPending
public int maxPending()Description copied from interface:PoolConfigThe maximum number of pending borrowers to enqueue before failing fast. 0 will immediately fail any acquire when no idle resource is available and the pool cannot grow. Use a negative number to deactivate.- Specified by:
maxPendingin interfacePoolConfig<POOLABLE>
-
pendingAcquireTimer
Description copied from interface:PoolConfigThe function that defines how timeouts are scheduled when aPool.acquire(Duration)call is made and the acquisition is pending. i.e. there is no idle resource and no new resource can be created currently, so a timeout is scheduled using the returned function.By default, the
Schedulers.parallel()scheduler is used.- Specified by:
pendingAcquireTimerin interfacePoolConfig<POOLABLE>- Returns:
- the function to apply when scheduling timers for pending acquisitions
-
releaseHandler
Description copied from interface:PoolConfigWhen a resource isreleased, defines a mechanism of resetting any lingering state of the resource in order for it to become usable again. ThePoolConfig.evictionPredicate()is applied AFTER this reset.For example, a buffer could have a readerIndex and writerIndex that need to be flipped back to zero.
- Specified by:
releaseHandlerin interfacePoolConfig<POOLABLE>
-
destroyHandler
Description copied from interface:PoolConfigDefines a mechanism of resource destruction, cleaning up state and OS resources it could maintain (eg. off-heap objects, file handles, socket connections, etc...).For example, a database connection could need to cleanly sever the connection link by sending a message to the database.
- Specified by:
destroyHandlerin interfacePoolConfig<POOLABLE>
-
evictionPredicate
Description copied from interface:PoolConfigABiPredicatethat checks if a resource should be destroyed (true) or is still in a valid state for recycling. This is primarily applied when a resource is released, to check whether or not it can immediately be recycled, but could also be applied during an acquire attempt (detecting eg. idle resources) or by a background reaping process. Both the resource and somemetricsabout the resource's life within the pool are provided.- Specified by:
evictionPredicatein interfacePoolConfig<POOLABLE>
-
evictInBackgroundInterval
Description copied from interface:PoolConfigIf the pool is configured to perform regular eviction checks on the background, returns theDurationrepresenting the interval at which such checks are made. Otherwise returnsDuration.ZERO(the default).- Specified by:
evictInBackgroundIntervalin interfacePoolConfig<POOLABLE>
-
evictInBackgroundScheduler
Description copied from interface:PoolConfigIf the pool is configured to perform regular eviction checks on the background, returns theScheduleron which these checks are made. Otherwise returnsSchedulers.immediate()(the default).- Specified by:
evictInBackgroundSchedulerin interfacePoolConfig<POOLABLE>
-
acquisitionScheduler
Description copied from interface:PoolConfigWhen set,Poolimplementation MAY decide to use theSchedulerto publish resources in a more deterministic way: the publishing thread would then always be the same, independently of which thread calledPool.acquire()orPooledRef.release()or on which thread thePoolConfig.allocator()produced new resources. Note that not all pool implementations are guaranteed to enforce this, as they might have their own thread publishing semantics.Defaults to
Schedulers.immediate(), which inhibits this behavior.- Specified by:
acquisitionSchedulerin interfacePoolConfig<POOLABLE>
-
metricsRecorder
Description copied from interface:PoolConfigThePoolMetricsRecorderto use to collect instrumentation data of thePoolimplementations.- Specified by:
metricsRecorderin interfacePoolConfig<POOLABLE>
-
clock
Description copied from interface:PoolConfigTheClockto use to timestamp pool lifecycle events like allocation and eviction, which can influence eg. thePoolConfig.evictionPredicate().- Specified by:
clockin interfacePoolConfig<POOLABLE>
-
reuseIdleResourcesInLruOrder
public boolean reuseIdleResourcesInLruOrder()Description copied from interface:PoolConfigThe order in which idle (aka available) resources should be used when the pool was under-utilized and a newPool.acquire()is performed. Returnstrueif LRU (Least-Recently Used, the resource that was released first is emitted) orfalsefor MRU (Most-Recently Used, the resource that was released last is emitted).- Specified by:
reuseIdleResourcesInLruOrderin interfacePoolConfig<POOLABLE>- Returns:
truefor LRU,falsefor MRU
-
maxLifeTime
Description copied from interface:PoolConfigThe maximum lifetime for pooled resources. Resources that have been alive for longer than this duration will be evicted on acquire, release, or during background eviction.Duration.ZEROdisables lifetime-based eviction (the default).When configured, this is composed with the
PoolConfig.evictionPredicate()using OR logic — a resource is evicted if either condition triggers.- Specified by:
maxLifeTimein interfacePoolConfig<POOLABLE>- Returns:
- the maximum lifetime for pooled resources, or
Duration.ZEROif disabled - See Also:
-
maxLifeTimeVariance
public double maxLifeTimeVariance()Description copied from interface:PoolConfigA variance percentage (0–100) applied toPoolConfig.maxLifeTime()to introduce per-resource jitter. Each resource's effective max lifetime will fall in the range[maxLifeTime * (1 - variance/100), maxLifeTime], spreading resource renewal over a window instead of a single point in time.Only meaningful when
PoolConfig.maxLifeTime()is configured (non-zero). Default is0(no variance — all resources expire at exactlyPoolConfig.maxLifeTime()).- Specified by:
maxLifeTimeVariancein interfacePoolConfig<POOLABLE>- Returns:
- the variance percentage, between 0 and 100
- See Also:
-