public abstract class TemporalBucket extends Object
This class represents a token bucket system. One instance represents one recurring bucket with a certain limit of tokens per timespan.
Constructor and Description |
---|
TemporalBucket() |
Modifier and Type | Method and Description |
---|---|
static long |
getAllTokensOrDelay(TemporalBucket... buckets)
Attempts to get a token from every bucket, or no tokens at all.
|
abstract long |
getDelay()
Get the approximate delay til the next available token, or -1 if a token is available.
|
abstract long |
getTimespan()
Get the timespan of this bucket in milliseconds.
|
boolean |
getToken()
Gets a token, regardless of whether one is available.
|
abstract boolean |
getTokens(int n)
Gets n tokens, regardless of whether they are available.
|
abstract int |
getTotalLimit()
Get the total limit of this bucket per timespan.
|
boolean |
isEquivalent(TemporalBucket other)
Checks if this TemporalBucket is equivalent to another TemporalBucket.
|
String |
toLimitString()
Get a string segment formatted as it would appear in a limit header.
|
public abstract long getDelay()
public boolean getToken()
public abstract boolean getTokens(int n)
public abstract long getTimespan()
public abstract int getTotalLimit()
public final boolean isEquivalent(TemporalBucket other)
other
- public final String toLimitString()
public static long getAllTokensOrDelay(TemporalBucket... buckets)
buckets
- Buckets to get tokens from.Copyright © 2019. All rights reserved.