Skip to content

Commit

Permalink
Merge branch '7.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-bukhtoyarov committed Apr 9, 2022
2 parents 2779ee4 + 3feaba0 commit 613cba5
Show file tree
Hide file tree
Showing 50 changed files with 397 additions and 52 deletions.
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -24,11 +24,11 @@ In additional to basic features described above, ```Bucket4j``` provides ability
In addition to local in-memory buckets, the Bucket4j supports clustered usage scenario on top of following back-ends:
| Back-end | Async supported | Optimized serialization | Thin-client support | Documentation link |
| :--- | :---: | :---: | :---: | :---: |
| ```JCache API (JSR 107)``` | No | No | No | [bucket4j-jcache](https://bucket4j.com/7.3.0/toc.html#bucket4j-jcache) |
| ```Hazelcast``` | Yes | Yes | Planned | [bucket4j-hazelcast](https://bucket4j.com/7.3.0/toc.html#bucket4j-hazelcast) |
| ```Apache Ignite``` | Yes | n/a | Yes | [bucket4j-ignite](https://bucket4j.com/7.3.0/toc.html#bucket4j-ignite) |
| ```Inifinispan``` | Yes | Yes | No | [bucket4j-infinispan](https://bucket4j.com/7.3.0/toc.html#bucket4j-infinispan) |
| ```Oracle Coherence``` | Yes | Yes | No | [bucket4j-coherence](https://bucket4j.com/7.3.0/toc.html#bucket4j-coherence) |
| ```JCache API (JSR 107)``` | No | No | No | [bucket4j-jcache](https://bucket4j.com/7.4.0/toc.html#bucket4j-jcache) |
| ```Hazelcast``` | Yes | Yes | Planned | [bucket4j-hazelcast](https://bucket4j.com/7.4.0/toc.html#bucket4j-hazelcast) |
| ```Apache Ignite``` | Yes | n/a | Yes | [bucket4j-ignite](https://bucket4j.com/7.4.0/toc.html#bucket4j-ignite) |
| ```Inifinispan``` | Yes | Yes | No | [bucket4j-infinispan](https://bucket4j.com/7.4.0/toc.html#bucket4j-infinispan) |
| ```Oracle Coherence``` | Yes | Yes | No | [bucket4j-coherence](https://bucket4j.com/7.4.0/toc.html#bucket4j-coherence) |

### Non-JVM back-ends
Bucket4j authors strongly recommends to use JVM based back-ends when possible,
Expand All @@ -38,8 +38,8 @@ In addition to local in-memory buckets, the Bucket4j supports clustered usage sc
| Back-end | Async supported | Documentation link |
| :--- | :---: | :---: |
| ```Redis``` | Yes | [bucket4j-redis](https://github.com/vladimir-bukhtoyarov/bucket4j/blob/master/bucket4j-redis/src/main/java/io/github/bucket4j/redis/redisson/cas/RedissonBasedProxyManager.java) |
| ```MySQL``` | No | [bucket4j-mysql](https://bucket4j.com/7.3.0/toc.html#mysql-integration) |
| ```PostgreSQL``` | No | [bucket4j-postgresql](https://bucket4j.com/7.3.0/toc.html#postgresql-integration) |
| ```MySQL``` | No | [bucket4j-mysql](https://bucket4j.com/7.4.0/toc.html#mysql-integration) |
| ```PostgreSQL``` | No | [bucket4j-postgresql](https://bucket4j.com/7.4.0/toc.html#postgresql-integration) |
| ```DynamoDb``` | No | [bucket4j-dynamodb](https://github.com/vladimir-bukhtoyarov/bucket4j/blob/master/bucket4j-dynamodb-sdk-v1/src/main/java/io/github/bucket4j/dynamodb/v1/LongDynamoDBProxyManager.java) |

### Local caches support
Expand All @@ -49,8 +49,8 @@ Sometimes you are having deal with bucket per key scenarios but distributed sync
| ```Caffeine``` | [bucket4j-caffeine](https://github.com/vladimir-bukhtoyarov/bucket4j/blob/7.3/bucket4j-caffeine/src/main/java/io/github/bucket4j/caffeine/CaffeineProxyManager.java) |

## [Documentation](https://bucket4j.com)
* [Official reference](https://bucket4j.com/7.3.0/toc.html)
* [Quick start examples](https://bucket4j.com/7.3.0/toc.html#quick-start-examples)
* [Official reference](https://bucket4j.com/7.4.0/toc.html)
* [Quick start examples](https://bucket4j.com/7.4.0/toc.html#quick-start-examples)
* [Third-party articles](https://bucket4j.com/#third-party-articles)

## Get Bucket4j library
Expand All @@ -60,7 +60,7 @@ The Bucket4j is distributed through [Maven Central](http://search.maven.org/):
<dependency>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-core</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
</dependency>
```
#### You can build Bucket4j from sources
Expand Down
2 changes: 1 addition & 1 deletion asciidoc/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<artifactId>asciidoc</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions asciidoc/src/main/docs/asciidoc/basic/api-reference.adoc
Expand Up @@ -146,6 +146,15 @@ boolean tryConsume(long numTokens);
void forceAddTokens(long tokensToAdd);
----

===== reset
[source, java]
----
/**
* Reset all tokens up to maximum capacity.
*/
void reset();
----

===== getAvailableTokens
[source, java]
----
Expand Down
8 changes: 7 additions & 1 deletion asciidoc/src/main/docs/asciidoc/index.adoc
Expand Up @@ -3,7 +3,7 @@ image::./images/white-logo.png[]
endif::[]

== Current version {revnumber} documentation
`04 March 2022` Support for Caffeine.
`09 April 2022` Method for reset bucket.

* http://bucket4j.com/{revnumber}/release-notes.html[{revnumber} Release notes]
* http://bucket4j.com/{revnumber}/toc.html[{revnumber} Reference]
Expand Down Expand Up @@ -43,6 +43,12 @@ image:images/Maxim_Bartkov.jpg[80,80] +

== Documentation for previous versions
=== 2022
==== 7.4.0
`04 March 2022` Support for Caffeine.

* http://bucket4j.com/7.4.0/release-notes.html[7.4.0 Release notes]
* http://bucket4j.com/7.4.0/toc.html[7.4.0 Reference]

==== 7.2.0
`11 Feb 2022` Support for MySQL and PostgreSQL.

Expand Down
6 changes: 5 additions & 1 deletion asciidoc/src/main/docs/asciidoc/release-notes.adoc
Expand Up @@ -2,4 +2,8 @@
Release `{revnumber}`

.The issues in release scope are following:
* https://github.com/vladimir-bukhtoyarov/bucket4j/issues/238[#238 Support for Caffeine]
* https://github.com/vladimir-bukhtoyarov/bucket4j/issues/116[#116 Method for reset bucket]
.The bugfixes in release scope are following:
* https://github.com/vladimir-bukhtoyarov/bucket4j/issues/246[#246 Connection leak in MySQL/PostgreSQL proxy managers]
* https://github.com/vladimir-bukhtoyarov/bucket4j/issues/244[#244 RedisCommands.SETPXNX not exists]
2 changes: 1 addition & 1 deletion bucket4j-benchmarks/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<artifactId>bucket4j-benchmarks</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bucket4j-caffeine/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<artifactId>bucket4j-caffeine</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bucket4j-coherence/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion bucket4j-core/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.vladimir-bukhtoyarov</groupId>
<artifactId>bucket4j-parent</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
<relativePath>../bucket4j-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Expand Up @@ -63,6 +63,8 @@ public abstract class AbstractBucket implements Bucket, BlockingBucket, Scheduli

protected abstract VerboseResult<Nothing> forceAddTokensVerboseImpl(long tokensToAdd);

protected abstract VerboseResult<Nothing> resetVerboseImpl();

protected abstract VerboseResult<Nothing> replaceConfigurationVerboseImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy);

protected abstract VerboseResult<Long> consumeIgnoringRateLimitsVerboseImpl(long tokensToConsume);
Expand Down Expand Up @@ -157,6 +159,11 @@ public VerboseResult<Nothing> addTokens(long tokensToAdd) {
return addTokensVerboseImpl(tokensToAdd);
}

@Override
public VerboseResult<Nothing> reset() {
return resetVerboseImpl();
}

@Override
public VerboseResult<Nothing> forceAddTokens(long tokensToAdd) {
checkTokensToAdd(tokensToAdd);
Expand Down
5 changes: 5 additions & 0 deletions bucket4j-core/src/main/java/io/github/bucket4j/Bucket.java
Expand Up @@ -176,6 +176,11 @@ static LocalBucketBuilder builder() {
*/
void forceAddTokens(long tokensToAdd);

/**
* Reset all tokens up to maximum capacity.
*/
void reset();

/**
* Returns amount of available tokens in this bucket.
Expand Down
Expand Up @@ -49,6 +49,8 @@ public interface BucketState {

void addTokens(long tokensToAdd);

void reset();

void forceAddTokens(long tokensToAdd);

long getCurrentSize(int bandwidth);
Expand Down
Expand Up @@ -325,6 +325,14 @@ public void addTokens(long tokensToAdd) {
}
}

@Override
public void reset() {
Bandwidth[] bandwidths = configuration.getBandwidths();
for (int i = 0; i < bandwidths.length; i++) {
resetBandwidth(i, bandwidths[i].capacity);
}
}

@Override
public void forceAddTokens(long tokensToAdd) {
Bandwidth[] bandwidths = configuration.getBandwidths();
Expand Down
Expand Up @@ -179,6 +179,14 @@ public void addTokens(long tokensToAdd) {
}
}

@Override
public void reset() {
Bandwidth[] bandwidths = configuration.getBandwidths();
for (int i = 0; i < bandwidths.length; i++) {
tokens[i] = bandwidths[i].getCapacity();
}
}

@Override
public void refillAllBandwidth(long currentTimeNanos) {
Bandwidth[] limits = configuration.getBandwidths();
Expand Down
Expand Up @@ -65,6 +65,11 @@ public interface VerboseBucket {
*/
VerboseResult<Nothing> addTokens(long tokensToAdd);

/**
* Does the same that {@link Bucket#reset()}
*/
VerboseResult<Nothing> reset();

/**
* Does the same that {@link Bucket#forceAddTokens(long)}
*/
Expand Down
Expand Up @@ -275,6 +275,11 @@ public interface AsyncBucketProxy {
*/
CompletableFuture<Void> forceAddTokens(long tokensToAdd);

/**
* Reset all tokens up to maximum capacity.
*/
CompletableFuture<Void> reset();

/**
* Has the same semantic with {@link Bucket#replaceConfiguration(BucketConfiguration, TokensInheritanceStrategy)}
*/
Expand Down
Expand Up @@ -73,6 +73,11 @@ public CompletableFuture<VerboseResult<Nothing>> forceAddTokens(long tokensToAdd
return completedFuture(() -> target.asVerbose().forceAddTokens(tokensToAdd));
}

@Override
public CompletableFuture<VerboseResult<Nothing>> reset() {
return completedFuture(() -> target.asVerbose().reset());
}

@Override
public CompletableFuture<VerboseResult<Nothing>> replaceConfiguration(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy) {
LimitChecker.checkConfiguration(newConfiguration);
Expand Down Expand Up @@ -156,6 +161,14 @@ public CompletableFuture<Void> forceAddTokens(long tokensToAdd) {
});
}

@Override
public CompletableFuture<Void> reset() {
return completedFuture(() -> {
target.reset();
return null;
});
}

@Override
public CompletableFuture<Void> replaceConfiguration(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy) {
LimitChecker.checkConfiguration(newConfiguration);
Expand Down
Expand Up @@ -69,6 +69,11 @@ public interface AsyncVerboseBucket {
*/
CompletableFuture<VerboseResult<Nothing>> forceAddTokens(long tokensToAdd);

/**
* Does the same that {@link Bucket#reset()}
*/
CompletableFuture<VerboseResult<Nothing>> reset();

/**
* Does the same that {@link Bucket#replaceConfiguration(BucketConfiguration, TokensInheritanceStrategy)}
*/
Expand Down
Expand Up @@ -171,6 +171,12 @@ public CompletableFuture<VerboseResult<Nothing>> forceAddTokens(long tokensToAdd
return execute(verboseCommand).thenApply(RemoteVerboseResult::asLocal);
}

@Override
public CompletableFuture<VerboseResult<Nothing>> reset() {
VerboseCommand<Nothing> verboseCommand = new VerboseCommand<>(new ResetCommand());
return execute(verboseCommand).thenApply(RemoteVerboseResult::asLocal);
}

@Override
public CompletableFuture<VerboseResult<Nothing>> replaceConfiguration(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy) {
checkConfiguration(newConfiguration);
Expand Down Expand Up @@ -345,6 +351,12 @@ public CompletableFuture<Void> forceAddTokens(long tokensToAdd) {
return future.thenApply(nothing -> null);
}

@Override
public CompletableFuture<Void> reset() {
CompletableFuture<Nothing> future = execute(new ResetCommand());
return future.thenApply(nothing -> null);
}

@Override
public CompletableFuture<Long> getAvailableTokens() {
return execute(new GetAvailableTokensCommand());
Expand Down
Expand Up @@ -118,6 +118,12 @@ protected long consumeIgnoringRateLimitsImpl(long tokensToConsume) {
return execute(command);
}

@Override
public void reset() {
ResetCommand command = new ResetCommand();
execute(command);
}

@Override
public long getAvailableTokens() {
return execute(new GetAvailableTokensCommand());
Expand Down Expand Up @@ -165,6 +171,12 @@ protected VerboseResult<Nothing> forceAddTokensVerboseImpl(long tokensToAdd) {
return execute(command.asVerbose()).asLocal();
}

@Override
protected VerboseResult<Nothing> resetVerboseImpl() {
ResetCommand command = new ResetCommand();
return execute(command.asVerbose()).asLocal();
}

@Override
protected VerboseResult<Nothing> replaceConfigurationVerboseImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy) {
ReplaceConfigurationCommand replaceConfigCommand = new ReplaceConfigurationCommand(newConfiguration, tokensInheritanceStrategy);
Expand Down
Expand Up @@ -109,6 +109,10 @@ public void forceAddTokens(long tokensToAdd) {
state.forceAddTokens(tokensToAdd);
}

public void reset() {
state.reset();
}

public BucketState copyBucketState() {
return state.copy();
}
Expand Down

0 comments on commit 613cba5

Please sign in to comment.