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 | Method and Description |
---|---|
static Bandwidth |
classic(long capacity,
Refill refill)
Specifies limitation in classic interpretation of token-bucket algorithm.
|
static Bandwidth |
simple(long capacity,
Duration period)
Specifies simple limitation capacity tokens per period time window.
|
String |
toString() |
public static Bandwidth simple(long capacity, Duration period)
capacity
- period
- public static Bandwidth classic(long capacity, Refill refill)
capacity
- refill
- Copyright © 2017. All rights reserved.