public interface AllocationStrategy
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.
| Modifier and Type | Method and Description |
|---|---|
int |
estimatePermitCount()
Best-effort peek at the state of the strategy which indicates roughly how many more resources can currently be
allocated.
|
int |
getPermits(int desired)
Try to get the permission to allocate a
desired positive number of new resources. |
int |
permitGranted() |
int |
permitMaximum() |
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. |
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. |
int estimatePermitCount()
getPermits(int) for an atomic permission.int getPermits(int desired)
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.
desired - the desired number of new resourcesdesiredint permitGranted()
Integer.MAX_VALUEint permitMinimum()
0 for scale-to-zero.0int permitMaximum()
Integer.MAX_VALUE for unboundedvoid returnPermits(int returned)
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.