Package org.apache.cassandra.net
Class ResourceLimits.Concurrent
- java.lang.Object
-
- org.apache.cassandra.net.ResourceLimits.Concurrent
-
- All Implemented Interfaces:
ResourceLimits.Limit
- Enclosing class:
- ResourceLimits
public static class ResourceLimits.Concurrent extends java.lang.Object implements ResourceLimits.Limit
A thread-safe permit container.
-
-
Constructor Summary
Constructors Constructor Description Concurrent(long limit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallocate(long amount)Allocates an amount independent of permits available from this limit.longlimit()ResourceLimits.Outcomerelease(long amount)longremaining()longsetLimit(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.booleantryAllocate(long amount)Attempts to allocate an amount of permits from this limit.longusing()
-
-
-
Method Detail
-
limit
public long limit()
- Specified by:
limitin 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.LimitSets 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:
setLimitin interfaceResourceLimits.Limit- Returns:
- the old limit
-
remaining
public long remaining()
- Specified by:
remainingin interfaceResourceLimits.Limit- Returns:
- remaining, unallocated permit amount
-
using
public long using()
- Specified by:
usingin interfaceResourceLimits.Limit- Returns:
- amount of permits currently in use
-
tryAllocate
public boolean tryAllocate(long amount)
Description copied from interface:ResourceLimits.LimitAttempts to allocate an amount of permits from this limit. If allocated, MUST eventually be released back withResourceLimits.Limit.release(long).- Specified by:
tryAllocatein interfaceResourceLimits.Limit- Returns:
trueif the allocation was successful,falseotherwise
-
allocate
public void allocate(long amount)
Description copied from interface:ResourceLimits.LimitAllocates an amount independent of permits available from this limit. MUST eventually be released back withResourceLimits.Limit.release(long).- Specified by:
allocatein interfaceResourceLimits.Limit
-
release
public ResourceLimits.Outcome release(long amount)
- Specified by:
releasein interfaceResourceLimits.Limit- Parameters:
amount- return the amount of permits back to this limit- Returns:
ABOVE_LIMITif there aren't enough permits available even after the release, orBELOW_LIMITif there are enough permits available after the releaese.
-
-