Package org.apache.cassandra.net
Interface ResourceLimits.Limit
-
- All Known Implementing Classes:
ResourceLimits.Basic
,ResourceLimits.Concurrent
- Enclosing class:
- ResourceLimits
public static interface ResourceLimits.Limit
Represents permits to utilise a resource and ways to allocate and release them. Two implementations are currently provided: 1.ResourceLimits.Concurrent
, for shared limits, which is thread-safe; 2.ResourceLimits.Basic
, for limits that are not shared between threads, is not thread-safe.
-
-
Method Summary
All Methods Instance Methods Abstract 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 toallocate(long)
ortryAllocate(long)
will succeed.boolean
tryAllocate(long amount)
Attempts to allocate an amount of permits from this limit.long
using()
-
-
-
Method Detail
-
limit
long limit()
- Returns:
- total amount of permits represented by this
ResourceLimits.Limit
- the capacity
-
setLimit
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 toallocate(long)
ortryAllocate(long)
will succeed. If the new limit is lower than the current amount of allocated permits then subsequent calls toallocate(long)
ortryAllocate(long)
will block or fail respectively.- Returns:
- the old limit
-
remaining
long remaining()
- Returns:
- remaining, unallocated permit amount
-
using
long using()
- Returns:
- amount of permits currently in use
-
tryAllocate
boolean tryAllocate(long amount)
Attempts to allocate an amount of permits from this limit. If allocated, MUST eventually be released back withrelease(long)
.- Returns:
true
if the allocation was successful,false
otherwise
-
allocate
void allocate(long amount)
Allocates an amount independent of permits available from this limit. MUST eventually be released back withrelease(long)
.
-
release
ResourceLimits.Outcome release(long amount)
- 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.
-
-