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

    Modifier and Type
    Method
    Description
    void
    allocate(long amount)
    Allocates an amount independent of permits available from this limit.
    long
     
    release(long amount)
     
    long
     
    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 acquired, subsequent calls to allocate(long) or tryAllocate(long) will succeed.
    boolean
    tryAllocate(long amount)
    Attempts to allocate an amount of permits from this limit.
    long
     
  • Method Details

    • 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 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 acquired, subsequent calls to allocate(long) or tryAllocate(long) will succeed. If the new limit is lower than the current amount of allocated permits then subsequent calls to allocate(long) or tryAllocate(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 with release(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 with release(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, or BELOW_LIMIT if there are enough permits available after the releaese.