question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I want to set Refill, Bandwidth capacity to 0.

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
vladimir-bukhtoyarovcommented, Dec 14, 2020

Desired behaviour is already implemented, but it does not work because of bug.

1reaction
vladimir-bukhtoyarovcommented, Dec 15, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found