public class Bandwidth extends Object implements Serializable
capacity
and refill
. Where:
Simple
- most popular way, which does not require from you to fully understand the token-bucket algorithm.
Use this way when you just want to specify easy limitation N tokens per M time window.
See this example of usage.
classic(long, Refill)
Classic} - hard way to specify limitation,
use it when you want to utilize the whole power of token-bucket. See this example of usage.
// Adds bandwidth that restricts to consume not often 1000 tokens per 1 minute and not often than 100 tokens per second
Bucket bucket = Bucket4j.builder().
.addLimit(Bandwidth.create(1000, Duration.ofMinutes(1)));
.addLimit(Bandwidth.create(100, Duration.ofSeconds(1)));
.build()
Modifier and Type | Field and Description |
---|---|
static SerializationHandle<Bandwidth> |
SERIALIZATION_HANDLE |
Modifier and Type | Method and Description |
---|---|
static Bandwidth |
classic(long capacity,
Refill refill)
Specifies limitation in classic interpretation of token-bucket algorithm.
|
boolean |
equals(Object o) |
long |
getCapacity() |
long |
getInitialTokens() |
long |
getRefillPeriodNanos() |
long |
getRefillTokens() |
static long |
getSerialVersionUID() |
long |
getTimeOfFirstRefillMillis() |
int |
hashCode() |
boolean |
isIntervallyAligned() |
boolean |
isRefillIntervally() |
boolean |
isUseAdaptiveInitialTokens() |
static Bandwidth |
simple(long capacity,
Duration period)
Specifies simple limitation capacity tokens per period time window.
|
String |
toString() |
Bandwidth |
withInitialTokens(long initialTokens)
By default new created bandwidth has amount tokens that equals its capacity.
|
public static SerializationHandle<Bandwidth> SERIALIZATION_HANDLE
public static Bandwidth simple(long capacity, Duration period)
capacity
- period
- public static Bandwidth classic(long capacity, Refill refill)
capacity
- refill
- public Bandwidth withInitialTokens(long initialTokens)
initialTokens
- public boolean isIntervallyAligned()
public long getCapacity()
public long getInitialTokens()
public long getRefillPeriodNanos()
public long getRefillTokens()
public boolean isRefillIntervally()
public boolean isUseAdaptiveInitialTokens()
public static long getSerialVersionUID()
public long getTimeOfFirstRefillMillis()
Copyright © 2020. All rights reserved.