Package reactor.pool
Interface PoolConfig<POOLABLE>
- All Known Implementing Classes:
DefaultPoolConfig
public interface PoolConfig<POOLABLE>
A representation of the common configuration options of a
Pool.
For a default implementation that is open for extension, see DefaultPoolConfig.- Author:
- Simon Baslé
-
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 theallocator()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.default DurationIf the pool is configured to perform regular eviction checks on the background, returns theDurationrepresenting the interval at which such checks are made.default SchedulerIf 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.default longGenerate an effective max lifetime in milliseconds for a single resource, applyingmaxLifeTimeVariance()jitter tomaxLifeTime().default DurationThe maximum lifetime for pooled resources.default doubleA variance percentage (0–100) applied tomaxLifeTime()to introduce per-resource jitter.intThe maximum number of pending borrowers to enqueue before failing fast.ThePoolMetricsRecorderto use to collect instrumentation data of thePoolimplementations.default BiFunction<Runnable, Duration, Disposable> 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.
-
Method Details
-
allocator
The asynchronous factory that produces new resources, represented as aMono. -
allocationStrategy
AllocationStrategy allocationStrategy()AllocationStrategydefines a strategy / limit for the number of pooled object to allocate. -
maxPending
int maxPending()The 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. -
releaseHandler
When a resource isreleased, defines a mechanism of resetting any lingering state of the resource in order for it to become usable again. TheevictionPredicate()is applied AFTER this reset.For example, a buffer could have a readerIndex and writerIndex that need to be flipped back to zero.
-
destroyHandler
Defines 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.
-
evictionPredicate
BiPredicate<POOLABLE,PooledRefMetadata> evictionPredicate()ABiPredicatethat 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. -
evictInBackgroundInterval
If 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). -
evictInBackgroundScheduler
If the pool is configured to perform regular eviction checks on the background, returns theScheduleron which these checks are made. Otherwise returnsSchedulers.immediate()(the default). -
acquisitionScheduler
Scheduler acquisitionScheduler()When 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 theallocator()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. -
metricsRecorder
PoolMetricsRecorder metricsRecorder()ThePoolMetricsRecorderto use to collect instrumentation data of thePoolimplementations. -
clock
Clock clock()TheClockto use to timestamp pool lifecycle events like allocation and eviction, which can influence eg. theevictionPredicate(). -
reuseIdleResourcesInLruOrder
boolean reuseIdleResourcesInLruOrder()The 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).- Returns:
truefor LRU,falsefor MRU
-
pendingAcquireTimer
The 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.- Returns:
- the function to apply when scheduling timers for pending acquisitions
-
maxLifeTime
The 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
evictionPredicate()using OR logic — a resource is evicted if either condition triggers.- Returns:
- the maximum lifetime for pooled resources, or
Duration.ZEROif disabled - Since:
- 1.2.4
- See Also:
-
maxLifeTimeVariance
default double maxLifeTimeVariance()A variance percentage (0–100) applied tomaxLifeTime()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
maxLifeTime()is configured (non-zero). Default is0(no variance — all resources expire at exactlymaxLifeTime()).- Returns:
- the variance percentage, between 0 and 100
- Since:
- 1.2.4
- See Also:
-
generateMaxLifeTimeMs
default long generateMaxLifeTimeMs()Generate an effective max lifetime in milliseconds for a single resource, applyingmaxLifeTimeVariance()jitter tomaxLifeTime(). Each call may return a different value — call once per resource at creation time.- Returns:
- effective max lifetime in milliseconds, or 0L if disabled
- Since:
- 1.2.4
-