@InterfaceStability.Unstable public interface RateLimiter extends java.io.Serializable
This interface supports two categories of policies: tagged and non-tagged. Tagged rate limiter is used, when further differentiation is required within a resource. For example: messages in a stream may be treated differently depending on the overall situation of processing; or read/write operations to a database. Tagging is the mechanism to allow this differentiation.
The following types of invocations are provided
Modifier and Type | Method and Description |
---|---|
void |
acquire(int numberOfCredit)
Attempt to acquire the provided number of credits, blocks indefinitely until
all requested credits become available.
|
int |
acquire(int numberOfCredit,
long timeout,
java.util.concurrent.TimeUnit unit)
Attempt to acquire the provided number of credits, blocks for up to provided amount of
time for credits to become available.
|
void |
acquire(java.util.Map<java.lang.String,java.lang.Integer> tagToCreditMap)
Attempt to acquire the provided number of credits for a number of tags, blocks indefinitely
until all requested credits become available
|
java.util.Map<java.lang.String,java.lang.Integer> |
acquire(java.util.Map<java.lang.String,java.lang.Integer> tagToCreditMap,
long timeout,
java.util.concurrent.TimeUnit unit)
Attempt to acquire the provided number of credits for a number of tags, blocks for up to provided amount of
time for credits to become available.
|
java.util.Set<java.lang.String> |
getSupportedTags()
Get the entire set of tags for which we have configured credits for rate limiting.
|
void |
init(Context context)
Initialize this rate limiter, this method should be called during container initialization.
|
void init(Context context)
context
- Context
that corresponds to this rate limitervoid acquire(int numberOfCredit)
numberOfCredit
- requested number of creditsint acquire(int numberOfCredit, long timeout, java.util.concurrent.TimeUnit unit)
numberOfCredit
- requested number of creditstimeout
- number of time unit to waitunit
- time unit to for timeoutvoid acquire(java.util.Map<java.lang.String,java.lang.Integer> tagToCreditMap)
tagToCreditMap
- a map of requested number of credits keyed by tagjava.util.Map<java.lang.String,java.lang.Integer> acquire(java.util.Map<java.lang.String,java.lang.Integer> tagToCreditMap, long timeout, java.util.concurrent.TimeUnit unit)
tagToCreditMap
- a map of requested number of credits keyed by tagtimeout
- number of time unit to waitunit
- time unit to for timeoutjava.util.Set<java.lang.String> getSupportedTags()