K - type of the budget key@ThreadSafe public class KeyedBudgetManager<K> extends Object
long available budget per key (allocation/release).
This manager gets a certain maximum long budget per key.
Users can acquire some budget for some key and release it later.
The manager keeps track of acquired/released budget and prevents from over-allocating.
There is also a paged type of allocation where a certain number of pages can be acquired from a set of keys. The page has its budget size. The manager acquires randomly from all keys of a given set. At the end, sum of pages acquired from each key is either requested number of pages or none. Only integer number of pages are acquired from each key respecting its available budget (no page spans two or more keys) or nothing is acquired reporting the maximum number of pages which could be acquired per each given key at the moment.
| Modifier and Type | Class and Description |
|---|---|
static class |
KeyedBudgetManager.AcquisitionResult<K>
Result of budget acquisition to return from acquisition functions.
|
| Constructor and Description |
|---|
KeyedBudgetManager(Map<K,Long> maxBudgetByKey,
long defaultPageSize) |
| Modifier and Type | Method and Description |
|---|---|
long |
acquireBudgetForKey(K key,
long size)
Tries to acquire budget for a given key.
|
KeyedBudgetManager.AcquisitionResult<K> |
acquirePagedBudget(Iterable<K> keys,
long numberOfPages)
Tries to acquire budget for given keys which equals to the number of pages times default page size.
|
long |
availableBudgetForKey(K key) |
long |
getDefaultPageSize() |
long |
maxTotalBudget() |
long |
maxTotalBudgetForKey(K key) |
long |
maxTotalNumberOfPages() |
void |
releaseAll() |
void |
releaseBudgetForKey(K key,
long size) |
void |
releaseBudgetForKeys(Map<K,Long> sizeByKey) |
void |
releasePageForKey(K key) |
long |
totalAvailableBudget() |
public long getDefaultPageSize()
public long acquireBudgetForKey(K key, long size)
No budget is acquired if it was not possible to fully acquire the requested budget.
key - the key to acquire budget fromsize - the size of budget to acquire from the given keypublic KeyedBudgetManager.AcquisitionResult<K> acquirePagedBudget(Iterable<K> keys, long numberOfPages)
public void releasePageForKey(K key)
public void releaseBudgetForKey(K key, long size)
public void releaseAll()
public long maxTotalBudget()
public long maxTotalNumberOfPages()
public long maxTotalBudgetForKey(K key)
public long totalAvailableBudget()
public long availableBudgetForKey(K key)
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.