Package org.apache.cassandra.net
Class ResourceLimits.Basic
- java.lang.Object
-
- org.apache.cassandra.net.ResourceLimits.Basic
-
- All Implemented Interfaces:
ResourceLimits.Limit
- Enclosing class:
- ResourceLimits
public static class ResourceLimits.Basic extends java.lang.Object implements ResourceLimits.Limit
A cheaper, thread-unsafe permit container to be used for unshared limits.
-
-
Constructor Summary
Constructors Constructor Description Basic(long limit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 thisResourceLimits.Limit
- the capacity If the old limit has been reached and the new limit is large enough to allow for more permits to be acquired, subsequent calls toResourceLimits.Limit.allocate(long)
orResourceLimits.Limit.tryAllocate(long)
will succeed.boolean
tryAllocate(long amount)
Attempts to allocate an amount of permits from this limit.long
using()
-
-
-
Method Detail
-
limit
public long limit()
- Specified by:
limit
in interfaceResourceLimits.Limit
- Returns:
- total amount of permits represented by this
ResourceLimits.Limit
- the capacity
-
setLimit
public long setLimit(long newLimit)
Description copied from interface:ResourceLimits.Limit
Sets the total amount of permits represented by thisResourceLimits.Limit
- the capacity If the old limit has been reached and the new limit is large enough to allow for more permits to be acquired, subsequent calls toResourceLimits.Limit.allocate(long)
orResourceLimits.Limit.tryAllocate(long)
will succeed. If the new limit is lower than the current amount of allocated permits then subsequent calls toResourceLimits.Limit.allocate(long)
orResourceLimits.Limit.tryAllocate(long)
will block or fail respectively.- Specified by:
setLimit
in interfaceResourceLimits.Limit
- Returns:
- the old limit
-
remaining
public long remaining()
- Specified by:
remaining
in interfaceResourceLimits.Limit
- Returns:
- remaining, unallocated permit amount
-
using
public long using()
- Specified by:
using
in interfaceResourceLimits.Limit
- Returns:
- amount of permits currently in use
-
tryAllocate
public boolean tryAllocate(long amount)
Description copied from interface:ResourceLimits.Limit
Attempts to allocate an amount of permits from this limit. If allocated, MUST eventually be released back withResourceLimits.Limit.release(long)
.- Specified by:
tryAllocate
in interfaceResourceLimits.Limit
- Returns:
true
if the allocation was successful,false
otherwise
-
allocate
public void allocate(long amount)
Description copied from interface:ResourceLimits.Limit
Allocates an amount independent of permits available from this limit. MUST eventually be released back withResourceLimits.Limit.release(long)
.- Specified by:
allocate
in interfaceResourceLimits.Limit
-
release
public ResourceLimits.Outcome release(long amount)
- Specified by:
release
in interfaceResourceLimits.Limit
- Parameters:
amount
- return the amount of permits back to this limit- Returns:
ABOVE_LIMIT
if there aren't enough permits available even after the release, orBELOW_LIMIT
if there are enough permits available after the releaese.
-
-