public class Refill extends Object implements Serializable
Modifier and Type | Method and Description |
---|---|
static Refill |
greedy(long tokens,
Duration period)
Creates the
Refill that does refill of tokens in greedy manner,
it will try to add the tokens to bucket as soon as possible. |
static Refill |
intervally(long tokens,
Duration period)
Creates the
Refill that does refill of tokens in intervally manner. |
static Refill |
of(long tokens,
Duration period)
Deprecated.
|
static Refill |
smooth(long tokens,
Duration period)
Deprecated.
|
String |
toString() |
@Deprecated public static Refill of(long tokens, Duration period)
@Deprecated public static Refill smooth(long tokens, Duration period)
public static Refill greedy(long tokens, Duration period)
Refill
that does refill of tokens in greedy manner,
it will try to add the tokens to bucket as soon as possible.
For example "of" refill "10 tokens per 1 second" will add 1 token per each 100 millisecond,
in other words refill will not wait 1 second to regenerate whole bunch of 10 tokens.
The three refills bellow do refill of tokens with same speed:
Refill.greedy(600, Duration.ofMinutes(1));
Refill.greedy(10, Duration.ofSeconds(1));
Refill.greedy(1, Duration.ofMillis(100));
If greediness is undesired then you can specify the fixed interval refill via intervally(long, Duration)
tokens
- amount of tokensperiod
- the period within tokens
will be fully regeneratedRefill
that does refill of tokens in of mannerpublic static Refill intervally(long tokens, Duration period)
Refill
that does refill of tokens in intervally manner.
"Intervally" in opposite to "greedy" will wait until whole period
will be elapsed before regenerate tokens
tokens
- amount of tokensperiod
- the period within tokens
will be fully regeneratedRefill
that does refill of tokens in intervally mannerCopyright © 2018. All rights reserved.