Top Description Fields Constructors Methods
reactor.pool

public Class DefaultPoolConfig<POOLABLE>

extends Object
implements PoolConfig<POOLABLE>
Class Inheritance
All Implemented Interfaces
reactor.pool.PoolConfig
Imports
java.time.Clock, .Duration, java.util.function.BiFunction, .BiPredicate, .Function, org.reactivestreams.Publisher, reactor.core.Disposable, reactor.core.publisher.Mono, reactor.core.scheduler.Scheduler, .Schedulers

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

Modifier and TypeField and Description
protected final Scheduler
protected final AllocationStrategy
protected final Mono<POOLABLE>
protected final Clock
protected final Function<POOLABLE, ? extends Publisher<Void>>
protected final Duration
protected final Scheduler
protected final BiPredicate<POOLABLE, PooledRefMetadata>
protected final boolean
protected final int
protected final PoolMetricsRecorder
protected final BiFunction<Runnable, Duration, Disposable>
protected final Function<POOLABLE, ? extends Publisher<Void>>

Constructor Summary

AccessConstructor and Description
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>
the original PoolConfig to copy (only standard PoolConfig options are copied)
toCopy
)

Copy constructor for the benefit of specializations of PoolConfig.

Method Summary

Modifier and TypeMethod and Description
public Scheduler
acquisitionScheduler()

Implements reactor.pool.PoolConfig.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 allocator produced new resources.
public AllocationStrategy
allocationStrategy()

Implements reactor.pool.PoolConfig.allocationStrategy.

AllocationStrategy defines a strategy / limit for the number of pooled object to allocate.
public Mono<POOLABLE>
allocator()

Implements reactor.pool.PoolConfig.allocator.

The asynchronous factory that produces new resources, represented as a Mono.
public Clock
clock()

Implements reactor.pool.PoolConfig.clock.

The java.time.Clock to use to timestamp pool lifecycle events like allocation and eviction, which can influence eg.
public Function<POOLABLE, ? extends Publisher<Void>>
destroyHandler()

Implements reactor.pool.PoolConfig.destroyHandler.

Defines a mechanism of resource destruction, cleaning up state and OS resources it could maintain (eg.
public Duration
evictInBackgroundInterval()

Overrides default reactor.pool.PoolConfig.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.
public Scheduler
evictInBackgroundScheduler()

Overrides default reactor.pool.PoolConfig.evictInBackgroundScheduler.

If the pool is configured to perform regular eviction checks on the background, returns the Scheduler on which these checks are made.
public BiPredicate<POOLABLE, PooledRefMetadata>
evictionPredicate()

Implements reactor.pool.PoolConfig.evictionPredicate.

A BiPredicate that checks if a resource should be destroyed (true) or is still in a valid state for recycling.
public int
maxPending()

Implements reactor.pool.PoolConfig.maxPending.

The maximum number of pending borrowers to enqueue before failing fast.
public PoolMetricsRecorder
metricsRecorder()

Implements reactor.pool.PoolConfig.metricsRecorder.

The PoolMetricsRecorder to use to collect instrumentation data of the Pool implementations.
public BiFunction<Runnable, Duration, Disposable>
pendingAcquireTimer()

Overrides default reactor.pool.PoolConfig.pendingAcquireTimer.

The function that defines how timeouts are scheduled when a Pool#acquire(Duration) call is made and the acquisition is pending.
public Function<POOLABLE, ? extends Publisher<Void>>
releaseHandler()

Implements reactor.pool.PoolConfig.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.
public boolean
reuseIdleResourcesInLruOrder()

Implements reactor.pool.PoolConfig.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.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

acquisitionSchedulerback to summary
protected final Scheduler acquisitionScheduler
allocationStrategyback to summary
protected final AllocationStrategy allocationStrategy
allocatorback to summary
protected final Mono<POOLABLE> allocator
clockback to summary
protected final Clock clock
destroyHandlerback to summary
protected final Function<POOLABLE, ? extends Publisher<Void>> destroyHandler
evictInBackgroundIntervalback to summary
protected final Duration evictInBackgroundInterval
evictInBackgroundSchedulerback to summary
protected final Scheduler evictInBackgroundScheduler
evictionPredicateback to summary
protected final BiPredicate<POOLABLE, PooledRefMetadata> evictionPredicate
isIdleLRUback to summary
protected final boolean isIdleLRU
maxPendingback to summary
protected final int maxPending
metricsRecorderback to summary
protected final PoolMetricsRecorder metricsRecorder
pendingAcquireTimerback to summary
protected final BiFunction<Runnable, Duration, Disposable> pendingAcquireTimer
releaseHandlerback to summary
protected final Function<POOLABLE, ? extends Publisher<Void>> releaseHandler

Constructor Detail

DefaultPoolConfigback to summary
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)
DefaultPoolConfigback to summary
protected DefaultPoolConfig(PoolConfig<POOLABLE> toCopy)

Copy constructor for the benefit of specializations of PoolConfig.

Parameters
toCopy:PoolConfig<POOLABLE>

the original PoolConfig to copy (only standard PoolConfig options are copied)

Method Detail

acquisitionSchedulerback to summary
public Scheduler acquisitionScheduler()

Implements reactor.pool.PoolConfig.acquisitionScheduler.

Doc from reactor.pool.PoolConfig.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 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.

Annotations
@Override
allocationStrategyback to summary
public AllocationStrategy allocationStrategy()

Implements reactor.pool.PoolConfig.allocationStrategy.

Doc from reactor.pool.PoolConfig.allocationStrategy.

AllocationStrategy defines a strategy / limit for the number of pooled object to allocate.

Annotations
@Override
allocatorback to summary
public Mono<POOLABLE> allocator()

Implements reactor.pool.PoolConfig.allocator.

Doc from reactor.pool.PoolConfig.allocator.

The asynchronous factory that produces new resources, represented as a Mono.

Annotations
@Override
clockback to summary
public Clock clock()

Implements reactor.pool.PoolConfig.clock.

Doc from reactor.pool.PoolConfig.clock.

The java.time.Clock to use to timestamp pool lifecycle events like allocation and eviction, which can influence eg. the evictionPredicate().

Annotations
@Override
destroyHandlerback to summary
public Function<POOLABLE, ? extends Publisher<Void>> destroyHandler()

Implements reactor.pool.PoolConfig.destroyHandler.

Doc from reactor.pool.PoolConfig.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.

Annotations
@Override
evictInBackgroundIntervalback to summary
public Duration evictInBackgroundInterval()

Overrides default reactor.pool.PoolConfig.evictInBackgroundInterval.

Doc from reactor.pool.PoolConfig.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. Otherwise returns Duration#ZERO (the default).

Annotations
@Override
evictInBackgroundSchedulerback to summary
public Scheduler evictInBackgroundScheduler()

Overrides default reactor.pool.PoolConfig.evictInBackgroundScheduler.

Doc from reactor.pool.PoolConfig.evictInBackgroundScheduler.

If the pool is configured to perform regular eviction checks on the background, returns the Scheduler on which these checks are made. Otherwise returns Schedulers#immediate() (the default).

Annotations
@Override
evictionPredicateback to summary
public BiPredicate<POOLABLE, PooledRefMetadata> evictionPredicate()

Implements reactor.pool.PoolConfig.evictionPredicate.

Doc from reactor.pool.PoolConfig.evictionPredicate.

A 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.

Annotations
@Override
maxPendingback to summary
public int maxPending()

Implements reactor.pool.PoolConfig.maxPending.

Doc from reactor.pool.PoolConfig.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.

Annotations
@Override
metricsRecorderback to summary
public PoolMetricsRecorder metricsRecorder()

Implements reactor.pool.PoolConfig.metricsRecorder.

Doc from reactor.pool.PoolConfig.metricsRecorder.

The PoolMetricsRecorder to use to collect instrumentation data of the Pool implementations.

Annotations
@Override
pendingAcquireTimerback to summary
public BiFunction<Runnable, Duration, Disposable> pendingAcquireTimer()

Overrides default reactor.pool.PoolConfig.pendingAcquireTimer.

Doc from reactor.pool.PoolConfig.pendingAcquireTimer.

The function that defines how timeouts are scheduled when a 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.

Returns:BiFunction<Runnable, Duration, Disposable>

the function to apply when scheduling timers for pending acquisitions

Annotations
@Override
releaseHandlerback to summary
public Function<POOLABLE, ? extends Publisher<Void>> releaseHandler()

Implements reactor.pool.PoolConfig.releaseHandler.

Doc from reactor.pool.PoolConfig.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. The evictionPredicate is applied AFTER this reset.

For example, a buffer could have a readerIndex and writerIndex that need to be flipped back to zero.

Annotations
@Override
reuseIdleResourcesInLruOrderback to summary
public boolean reuseIdleResourcesInLruOrder()

Implements reactor.pool.PoolConfig.reuseIdleResourcesInLruOrder.

Doc from reactor.pool.PoolConfig.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. 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).

Returns:boolean

true for LRU, false for MRU

Annotations
@Override