public static class ResourceLimits.Basic extends java.lang.Object implements ResourceLimits.Limit
Constructor and Description |
---|
Basic(long limit) |
Modifier and Type | Method and Description |
---|---|
void |
allocate(long amount)
Allocates an amount independent of permits available from this limit.
|
long |
limit() |
ResourceLimits.Outcome |
release(long amount) |
long |
remaining() |
long |
setLimit(long newLimit)
Sets the total amount of permits represented by this
ResourceLimits.Limit - the capacity
If the old limit has been reached and the new limit is large enough to allow for more
permits to be aqcuired, subsequent calls to ResourceLimits.Limit.allocate(long) or ResourceLimits.Limit.tryAllocate(long)
will succeed. |
boolean |
tryAllocate(long amount)
Attempts to allocate an amount of permits from this limit.
|
long |
using() |
public long limit()
limit
in interface ResourceLimits.Limit
ResourceLimits.Limit
- the capacitypublic long setLimit(long newLimit)
ResourceLimits.Limit
ResourceLimits.Limit
- the capacity
If the old limit has been reached and the new limit is large enough to allow for more
permits to be aqcuired, subsequent calls to ResourceLimits.Limit.allocate(long)
or ResourceLimits.Limit.tryAllocate(long)
will succeed.
If the new limit is lower than the current amount of allocated permits then subsequent calls
to ResourceLimits.Limit.allocate(long)
or ResourceLimits.Limit.tryAllocate(long)
will block or fail respectively.setLimit
in interface ResourceLimits.Limit
public long remaining()
remaining
in interface ResourceLimits.Limit
public long using()
using
in interface ResourceLimits.Limit
public boolean tryAllocate(long amount)
ResourceLimits.Limit
ResourceLimits.Limit.release(long)
.tryAllocate
in interface ResourceLimits.Limit
true
if the allocation was successful, false
otherwisepublic void allocate(long amount)
ResourceLimits.Limit
ResourceLimits.Limit.release(long)
.allocate
in interface ResourceLimits.Limit
public ResourceLimits.Outcome release(long amount)
release
in interface ResourceLimits.Limit
amount
- return the amount of permits back to this limitABOVE_LIMIT
if there aren't enough permits available even after the release, or
BELOW_LIMIT
if there are enough permits available after the releaese.Copyright © 2009-2021 The Apache Software Foundation