Class CapacityManager
java.lang.Object
software.amazon.awssdk.core.internal.util.CapacityManager
Manages capacity of a finite resource. Capacity can be acquired and
released.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
acquire()
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
release()
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.
-
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
-