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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acquire()
Attempts to acquire a single capacity unit.boolean
acquire(int capacity)
Attempts to acquire a given amount of capacity.int
availableCapacity()
Returns the currently available capacity.int
consumedCapacity()
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 Detail
-
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 Detail
-
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
-
-