Class CapacityManager

java.lang.Object
software.amazon.awssdk.core.internal.util.CapacityManager

public class CapacityManager extends Object
Manages capacity of a finite resource. Capacity can be acquired and released.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CapacityManager(int maxCapacity)
    Creates a CapacityManager.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Attempts to acquire a single capacity unit.
    boolean
    acquire(int capacity)
    Attempts to acquire a given amount of capacity.
    int
    Returns the currently available capacity.
    int
    Returns the currently consumed capacity.
    void
    Releases a single unit of capacity back to the pool, making it available to consumers.
    void
    release(int capacity)
    Releases a given amount of capacity back to the pool, making it available to consumers.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CapacityManager

      public CapacityManager(int maxCapacity)
      Creates a CapacityManager.
      Parameters:
      maxCapacity - maximum capacity of this resource. available capacity will initially be set to this value. if a negative value is provided the capacity manager will operate in a no-op passthrough mode in which all acquire calls will return true.
  • Method Details

    • acquire

      public boolean acquire()
      Attempts to acquire a single capacity unit. If acquired, capacity will be consumed from the available pool.
      Returns:
      true if capacity can be acquired, false if not
    • acquire

      public boolean acquire(int capacity)
      Attempts to acquire a given amount of capacity. If acquired, capacity will be consumed from the available pool.
      Parameters:
      capacity - capacity to acquire
      Returns:
      true if capacity can be acquired, false if not
      Throws:
      IllegalArgumentException - if given capacity is negative
    • release

      public void release()
      Releases a single unit of capacity back to the pool, making it available to consumers.
    • release

      public void release(int capacity)
      Releases a given amount of capacity back to the pool, making it available to consumers.
      Parameters:
      capacity - capacity to release
      Throws:
      IllegalArgumentException - if given capacity is negative
    • consumedCapacity

      public int consumedCapacity()
      Returns the currently consumed capacity.
      Returns:
      consumed capacity
    • availableCapacity

      public int availableCapacity()
      Returns the currently available capacity.
      Returns:
      available capacity