Top Description Methods
reactor.pool

public Interface AllocationStrategy

Known Direct Implementers
reactor.pool.introspection.SamplingAllocationStrategy, reactor.pool.AllocationStrategies.UnboundedAllocationStrategy, reactor.pool.AllocationStrategies.SizeBasedAllocationStrategy

A strategy guiding the Pool on whether or not it is possible to invoke the resource allocator.

See PoolBuilder#sizeBetween(int, int) and PoolBuilder#sizeUnbounded() for pre-made strategies.

Author
Simon Baslé

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

an ESTIMATED count of how many more resources can currently be allocated
estimatePermitCount
()

Best-effort peek at the state of the strategy which indicates roughly how many more resources can currently be allocated.

public int

Returns:

the actual number of new resources that MUST be created, can be 0 and can be more than desired
getPermits
(int
the desired number of new resources
desired
)

Try to get the permission to allocate a desired positive number of new resources.

public int

Returns:

a best estimate of the number of permits currently granted, between 0 and Integer#MAX_VALUE
permitGranted
()

public int

Returns:

the maximum number of permits this strategy can grant in total, or Integer#MAX_VALUE for unbounded
permitMaximum
()

public int

Returns:

the minimum number of permits this strategy tries to maintain, or 0
permitMinimum
()

Return the minimum number of permits this strategy tries to maintain granted (reflecting a minimal size for the pool), or 0 for scale-to-zero.

public void
returnPermits(int returned)

Update the strategy to indicate that N resources were discarded from the Pool, potentially leaving space for N new ones to be allocated.

public default int

Returns:

The concurrency level used when the allocator is subscribed to during the warmup phase, must be positive, 1 by default
warmupParallelism
()

Return the concurrency level used when the allocator is subscribed to during the warmup phase, if any.

Method Detail

estimatePermitCountback to summary
public int estimatePermitCount()

Best-effort peek at the state of the strategy which indicates roughly how many more resources can currently be allocated. Should be paired with getPermits(int) for an atomic permission.

Returns:int

an ESTIMATED count of how many more resources can currently be allocated

getPermitsback to summary
public int getPermits(int desired)

Try to get the permission to allocate a desired positive number of new resources. Returns the permissible number of resources which MUST be created (otherwise the internal live counter of the strategy might be off). This permissible number might be zero, and it can also be a greater number than desired, which could for example denote a minimum warmed-up size for the pool to maintain (see below). Once a resource is discarded from the pool, it must update the strategy using returnPermits(int) (which can happen in batches or with value 1).

For the warming up case, the typical pattern would be to call this method with a desired of zero.

Parameters
desired:int

the desired number of new resources

Returns:int

the actual number of new resources that MUST be created, can be 0 and can be more than desired

permitGrantedback to summary
public int permitGranted()
Returns:int

a best estimate of the number of permits currently granted, between 0 and Integer#MAX_VALUE

permitMaximumback to summary
public int permitMaximum()
Returns:int

the maximum number of permits this strategy can grant in total, or Integer#MAX_VALUE for unbounded

permitMinimumback to summary
public int permitMinimum()

Return the minimum number of permits this strategy tries to maintain granted (reflecting a minimal size for the pool), or 0 for scale-to-zero.

Returns:int

the minimum number of permits this strategy tries to maintain, or 0

returnPermitsback to summary
public void returnPermits(int returned)

Update the strategy to indicate that N resources were discarded from the Pool, potentially leaving space for N new ones to be allocated. Users MUST ensure that this method isn't called with a value greater than the number of held permits it has.

Some strategy MIGHT throw an IllegalArgumentException if it can be determined the number of returned permits is not consistent with the strategy's limits and delivered permits.

warmupParallelismback to summary
public default int warmupParallelism()

Return the concurrency level used when the allocator is subscribed to during the warmup phase, if any.

The number of resources created concurrently will not exceed the value returned by warmupParallelism(). If the concurrency level is set to 1, pre-allocation of resources will be performed sequentially by subscribing to the allocator one at a time. The process waits for a resource to be created before subscribing again to the allocator. This sequence continues until all pre-allocated resources have been successfully created.

Defaults to 1

Returns:int

The concurrency level used when the allocator is subscribed to during the warmup phase, must be positive, 1 by default

Since
1.0.1