Top Description Inners Constructors Methods
reactor.pool

pack-priv final Class AllocationStrategies

extends Object
Class Inheritance
Imports
java.util.concurrent.atomic.AtomicInteger, .AtomicIntegerFieldUpdater

Various pre-made AllocationStrategy for internal use.
Author
Simon Baslé

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AllocationStrategiesback to summary
pack-priv AllocationStrategies()
reactor.pool back to summary

pack-priv final Class AllocationStrategies.SizeBasedAllocationStrategy

extends Object
implements AllocationStrategy
Class Inheritance
  • java.lang.Object
  • reactor.pool.AllocationStrategies.SizeBasedAllocationStrategy
All Implemented Interfaces
reactor.pool.AllocationStrategy

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final int
pack-priv volatile int
pack-priv static final AtomicIntegerFieldUpdater<AllocationStrategies.SizeBasedAllocationStrategy>
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv
SizeBasedAllocationStrategy(int min, int max)

pack-priv
SizeBasedAllocationStrategy(int min, int max, int warmupParallelism)

Method Summary

Modifier and TypeMethod and Description
public int
estimatePermitCount()

Implements reactor.pool.AllocationStrategy.estimatePermitCount.

Best-effort peek at the state of the strategy which indicates roughly how many more resources can currently be allocated.
public int
getPermits(int
the desired number of new resources
desired
)

Implements reactor.pool.AllocationStrategy.getPermits.

Try to get the permission to allocate a desired positive number of new resources.
public int
public int
public int
permitMinimum()

Implements reactor.pool.AllocationStrategy.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)

Implements reactor.pool.AllocationStrategy.returnPermits.

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

Overrides default reactor.pool.AllocationStrategy.warmupParallelism.

Return the concurrency level used when the allocator is subscribed to during the warmup phase, if any.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

maxback to summary
pack-priv final int max
minback to summary
pack-priv final int min
permitsback to summary
pack-priv volatile int permits
PERMITSback to summary
pack-priv static final AtomicIntegerFieldUpdater<AllocationStrategies.SizeBasedAllocationStrategy> PERMITS
warmupParallelismback to summary
pack-priv final int warmupParallelism

Constructor Detail

SizeBasedAllocationStrategyback to summary
pack-priv SizeBasedAllocationStrategy(int min, int max)
SizeBasedAllocationStrategyback to summary
pack-priv SizeBasedAllocationStrategy(int min, int max, int warmupParallelism)

Method Detail

estimatePermitCountback to summary
public int estimatePermitCount()

Implements reactor.pool.AllocationStrategy.estimatePermitCount.

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

Annotations
@Override
getPermitsback to summary
public int getPermits(int desired)

Implements reactor.pool.AllocationStrategy.getPermits.

Doc from reactor.pool.AllocationStrategy.getPermits.

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

Annotations
@Override
permitGrantedback to summary
public int permitGranted()

Implements reactor.pool.AllocationStrategy.permitGranted.

Returns:int

Doc from reactor.pool.AllocationStrategy.permitGranted.

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

Annotations
@Override
permitMaximumback to summary
public int permitMaximum()

Implements reactor.pool.AllocationStrategy.permitMaximum.

Returns:int

Doc from reactor.pool.AllocationStrategy.permitMaximum.

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

Annotations
@Override
permitMinimumback to summary
public int permitMinimum()

Implements reactor.pool.AllocationStrategy.permitMinimum.

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

Annotations
@Override
returnPermitsback to summary
public void returnPermits(int returned)

Implements reactor.pool.AllocationStrategy.returnPermits.

Doc from reactor.pool.AllocationStrategy.returnPermits.

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.

Annotations
@Override
warmupParallelismback to summary
public int warmupParallelism()

Overrides default reactor.pool.AllocationStrategy.warmupParallelism.

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

Annotations
@Override
reactor.pool back to summary

pack-priv final Class AllocationStrategies.UnboundedAllocationStrategy

extends AtomicInteger
implements AllocationStrategy
Class Inheritance
All Implemented Interfaces
reactor.pool.AllocationStrategy

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
estimatePermitCount()

Implements reactor.pool.AllocationStrategy.estimatePermitCount.

Best-effort peek at the state of the strategy which indicates roughly how many more resources can currently be allocated.
public int
getPermits(int
the desired number of new resources
desired
)

Implements reactor.pool.AllocationStrategy.getPermits.

Try to get the permission to allocate a desired positive number of new resources.
public int
public int
public int
permitMinimum()

Implements reactor.pool.AllocationStrategy.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)

Implements reactor.pool.AllocationStrategy.returnPermits.

Update the strategy to indicate that N resources were discarded from the Pool, potentially leaving space for N new ones to be allocated.
Inherited from java.util.concurrent.atomic.AtomicInteger:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Constructor Detail

UnboundedAllocationStrategyback to summary
pack-priv UnboundedAllocationStrategy()

Method Detail

estimatePermitCountback to summary
public int estimatePermitCount()

Implements reactor.pool.AllocationStrategy.estimatePermitCount.

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

Annotations
@Override
getPermitsback to summary
public int getPermits(int desired)

Implements reactor.pool.AllocationStrategy.getPermits.

Doc from reactor.pool.AllocationStrategy.getPermits.

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

Annotations
@Override
permitGrantedback to summary
public int permitGranted()

Implements reactor.pool.AllocationStrategy.permitGranted.

Returns:int

Doc from reactor.pool.AllocationStrategy.permitGranted.

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

Annotations
@Override
permitMaximumback to summary
public int permitMaximum()

Implements reactor.pool.AllocationStrategy.permitMaximum.

Returns:int

Doc from reactor.pool.AllocationStrategy.permitMaximum.

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

Annotations
@Override
permitMinimumback to summary
public int permitMinimum()

Implements reactor.pool.AllocationStrategy.permitMinimum.

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

Annotations
@Override
returnPermitsback to summary
public void returnPermits(int returned)

Implements reactor.pool.AllocationStrategy.returnPermits.

Doc from reactor.pool.AllocationStrategy.returnPermits.

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.

Annotations
@Override