I want to set Refill, Bandwidth capacity to 0.
See original GitHub issueI took below error stack.
java.lang.IllegalArgumentException: 0 is wrong value for period tokens, because tokens should be positive
at io.github.bucket4j.BucketExceptions.nonPositivePeriodTokens(BucketExceptions.java:106)
at io.github.bucket4j.Refill.<init>(Refill.java:46)
at io.github.bucket4j.Refill.greedy(Refill.java:95)
I read code related this issue. And find when capacity is set to 0, this library make exception.
public static Bandwidth classic(long capacity, Refill refill) {
if (capacity <= 0) {
throw BucketExceptions.nonPositiveCapacity(capacity);
}
if (refill == null) {
throw BucketExceptions.nullBandwidthRefill();
}
return new Bandwidth(capacity, refill.periodNanos, refill.tokens, capacity, refill.refillIntervally, refill.timeOfFirstRefillMillis, refill.useAdaptiveInitialTokens);
}
private Refill(long tokens, Duration period, boolean refillIntervally, long timeOfFirstRefillMillis, boolean useAdaptiveInitialTokens) {
if (period == null) {
throw BucketExceptions.nullRefillPeriod();
}
if (tokens <= 0) {
throw BucketExceptions.nonPositivePeriodTokens(tokens);
}
this.periodNanos = period.toNanos();
if (periodNanos <= 0) {
throw BucketExceptions.nonPositivePeriod(periodNanos);
}
...
}
Now I can set dynamically bucket size set. I sometimes want to stop to generate token.
How can I do this situation? Do you have any ideas?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top Results From Across the Web
I want to set Refill, Bandwidth capacity to 0. · Issue #135 - GitHub
I took below error stack. java.lang.IllegalArgumentException: 0 is wrong value for period tokens, because tokens should be positive at ...
Read more >Bandwidth (bucket4j-core 4.1.0 API) - javadoc.io
Capacity - defines the maximum count of tokens which can be hold by bucket. Refill - defines the speed in which tokens are...
Read more >About TRON bandwidth and energy - Medium
Rules for obtaining bandwidth and energy by freezing TRX in TronLink wallet. If you want to obtain the bandwidth by freezing TRX, the...
Read more >Rate Limiting a Spring API Using Bucket4j - Baeldung
We use Bandwidth to configure the capacity of the bucket and the rate of refill. The Refill class is used to define the...
Read more >What is Bandwidth - Definition, Meaning & Explanation - Verizon
Definition. The maximum amount of data transmitted over an internet connection in a given amount of time. Bandwidth is often mistaken for ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Desired behaviour is already implemented, but it does not work because of bug.
According to this issue, I am going to fix it by myself, because it needs to be combined with another enhancement that was described in this thread https://github.com/vladimir-bukhtoyarov/bucket4j/issues/133
If you want to fix a documentation just fork and provide pull-request.