public class DefaultPoolConfig<POOLABLE> extends Object implements PoolConfig<POOLABLE>
PoolConfig
that can be extended to bear more configuration options
with access to a copy constructor for the basic options.Modifier and Type | Field and Description |
---|---|
protected Scheduler |
acquisitionScheduler |
protected AllocationStrategy |
allocationStrategy |
protected Mono<POOLABLE> |
allocator |
protected Clock |
clock |
protected Function<POOLABLE,? extends Publisher<Void>> |
destroyHandler |
protected Duration |
evictInBackgroundInterval |
protected Scheduler |
evictInBackgroundScheduler |
protected BiPredicate<POOLABLE,PooledRefMetadata> |
evictionPredicate |
protected boolean |
isIdleLRU |
protected int |
maxPending |
protected PoolMetricsRecorder |
metricsRecorder |
protected BiFunction<Runnable,Duration,Disposable> |
pendingAcquireTimer |
protected Function<POOLABLE,? extends Publisher<Void>> |
releaseHandler |
Modifier | Constructor and Description |
---|---|
|
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) |
protected |
DefaultPoolConfig(PoolConfig<POOLABLE> toCopy)
Copy constructor for the benefit of specializations of
PoolConfig . |
Modifier and Type | Method and Description |
---|---|
Scheduler |
acquisitionScheduler()
When set,
Pool implementation MAY decide to use the Scheduler
to publish resources in a more deterministic way: the publishing thread would then
always be the same, independently of which thread called Pool.acquire() or
PooledRef.release() or on which thread the PoolConfig.allocator() produced new
resources. |
AllocationStrategy |
allocationStrategy()
AllocationStrategy defines a strategy / limit for the number of pooled object to allocate. |
Mono<POOLABLE> |
allocator()
The asynchronous factory that produces new resources, represented as a
Mono . |
Clock |
clock()
The
Clock to use to timestamp pool lifecycle events like allocation
and eviction, which can influence eg. |
Function<POOLABLE,? extends Publisher<Void>> |
destroyHandler()
Defines a mechanism of resource destruction, cleaning up state and OS resources it could maintain (eg.
|
Duration |
evictInBackgroundInterval()
If the pool is configured to perform regular eviction checks on the background, returns the
Duration representing
the interval at which such checks are made. |
Scheduler |
evictInBackgroundScheduler()
If the pool is configured to perform regular eviction checks on the background, returns the
Scheduler on
which these checks are made. |
BiPredicate<POOLABLE,PooledRefMetadata> |
evictionPredicate()
A
BiPredicate that checks if a resource should be destroyed (true ) or is still in a valid state
for recycling. |
int |
maxPending()
The maximum number of pending borrowers to enqueue before failing fast.
|
PoolMetricsRecorder |
metricsRecorder()
The
PoolMetricsRecorder to use to collect instrumentation data of the Pool
implementations. |
BiFunction<Runnable,Duration,Disposable> |
pendingAcquireTimer()
The function that defines how timeouts are scheduled when a
Pool.acquire(Duration) call is made and the acquisition is pending. |
Function<POOLABLE,? extends Publisher<Void>> |
releaseHandler()
When a resource is
released , defines a mechanism of resetting any lingering state of
the resource in order for it to become usable again. |
boolean |
reuseIdleResourcesInLruOrder()
The order in which idle (aka available) resources should be used when the pool was
under-utilized and a new
Pool.acquire() is performed. |
protected final BiFunction<Runnable,Duration,Disposable> pendingAcquireTimer
protected final AllocationStrategy allocationStrategy
protected final int maxPending
protected final BiPredicate<POOLABLE,PooledRefMetadata> evictionPredicate
protected final Duration evictInBackgroundInterval
protected final Scheduler evictInBackgroundScheduler
protected final Scheduler acquisitionScheduler
protected final PoolMetricsRecorder metricsRecorder
protected final Clock clock
protected final boolean isIdleLRU
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)
protected DefaultPoolConfig(PoolConfig<POOLABLE> toCopy)
PoolConfig
.toCopy
- the original PoolConfig
to copy (only standard PoolConfig
options are copied)public Mono<POOLABLE> allocator()
PoolConfig
Mono
.allocator
in interface PoolConfig<POOLABLE>
public AllocationStrategy allocationStrategy()
PoolConfig
AllocationStrategy
defines a strategy / limit for the number of pooled object to allocate.allocationStrategy
in interface PoolConfig<POOLABLE>
public int maxPending()
PoolConfig
maxPending
in interface PoolConfig<POOLABLE>
public BiFunction<Runnable,Duration,Disposable> pendingAcquireTimer()
PoolConfig
Pool.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.
pendingAcquireTimer
in interface PoolConfig<POOLABLE>
public Function<POOLABLE,? extends Publisher<Void>> releaseHandler()
PoolConfig
released
, defines a mechanism of resetting any lingering state of
the resource in order for it to become usable again. The PoolConfig.evictionPredicate()
is applied AFTER this reset.
For example, a buffer could have a readerIndex and writerIndex that need to be flipped back to zero.
releaseHandler
in interface PoolConfig<POOLABLE>
public Function<POOLABLE,? extends Publisher<Void>> destroyHandler()
PoolConfig
For example, a database connection could need to cleanly sever the connection link by sending a message to the database.
destroyHandler
in interface PoolConfig<POOLABLE>
public BiPredicate<POOLABLE,PooledRefMetadata> evictionPredicate()
PoolConfig
BiPredicate
that 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 some metrics
about the resource's life within the pool are provided.evictionPredicate
in interface PoolConfig<POOLABLE>
public Duration evictInBackgroundInterval()
PoolConfig
Duration
representing
the interval at which such checks are made. Otherwise returns Duration.ZERO
(the default).evictInBackgroundInterval
in interface PoolConfig<POOLABLE>
public Scheduler evictInBackgroundScheduler()
PoolConfig
Scheduler
on
which these checks are made. Otherwise returns Schedulers.immediate()
(the default).evictInBackgroundScheduler
in interface PoolConfig<POOLABLE>
public Scheduler acquisitionScheduler()
PoolConfig
Pool
implementation MAY decide to use the Scheduler
to publish resources in a more deterministic way: the publishing thread would then
always be the same, independently of which thread called Pool.acquire()
or
PooledRef.release()
or on which thread the PoolConfig.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.
acquisitionScheduler
in interface PoolConfig<POOLABLE>
public PoolMetricsRecorder metricsRecorder()
PoolConfig
PoolMetricsRecorder
to use to collect instrumentation data of the Pool
implementations.metricsRecorder
in interface PoolConfig<POOLABLE>
public Clock clock()
PoolConfig
Clock
to use to timestamp pool lifecycle events like allocation
and eviction, which can influence eg. the PoolConfig.evictionPredicate()
.clock
in interface PoolConfig<POOLABLE>
public boolean reuseIdleResourcesInLruOrder()
PoolConfig
Pool.acquire()
is performed. Returns true
if LRU (Least-Recently Used, the resource that was released first is emitted) or
false
for MRU (Most-Recently Used, the resource that was released last is
emitted).reuseIdleResourcesInLruOrder
in interface PoolConfig<POOLABLE>
true
for LRU, false
for MRU