Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
fix: bump hazelcast version to 4.1.1 fixes rateLimit repository
Browse files Browse the repository at this point in the history
As 3.10 gateway provides hazelcast version 4.1.1,
APIM has to use same hazelcast version, to ensure hazelcast repository plugin compatibility (there has been breaking changes since hazelcast 3.12).

This fixes hazelcast ratelimit implementation.
  • Loading branch information
Marc authored and marcambier committed Oct 27, 2021
1 parent 4433e61 commit 8e68014
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Expand Up @@ -16,14 +16,16 @@
package io.gravitee.repository.hazelcast.ratelimit;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.map.IMap;
import io.gravitee.repository.hazelcast.ratelimit.configuration.HazelcastRateLimitConfiguration;
import io.gravitee.repository.ratelimit.api.RateLimitRepository;
import io.gravitee.repository.ratelimit.model.RateLimit;
import io.reactivex.*;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.Single;
import io.reactivex.SingleSource;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.function.Supplier;
Expand Down Expand Up @@ -53,7 +55,7 @@ public void afterPropertiesSet() {
public Single<RateLimit> incrementAndGet(String key, long weight, Supplier<RateLimit> supplier) {
final long now = System.currentTimeMillis();

Lock lock = hazelcastInstance.getLock("lock-rl-" + key);
Lock lock = hazelcastInstance.getCPSubsystem().getLock("lock-rl-" + key);

return Completable
.create(
Expand All @@ -67,7 +69,7 @@ public Single<RateLimit> incrementAndGet(String key, long weight, Supplier<RateL
Single.defer(
() ->
Maybe
.fromFuture(counters.getAsync(key))
.fromFuture(counters.getAsync(key).toCompletableFuture())
.switchIfEmpty((SingleSource<RateLimit>) observer -> observer.onSuccess(supplier.get()))
.flatMap(
(Function<RateLimit, SingleSource<RateLimit>>) rateLimit -> {
Expand All @@ -81,12 +83,14 @@ public Single<RateLimit> incrementAndGet(String key, long weight, Supplier<RateL

return Completable
.fromFuture(
counters.setAsync(
rateLimit.getKey(),
rateLimit,
now - rateLimit.getResetTime(),
TimeUnit.MILLISECONDS
)
counters
.setAsync(
rateLimit.getKey(),
rateLimit,
now - rateLimit.getResetTime(),
TimeUnit.MILLISECONDS
)
.toCompletableFuture()
)
.andThen(Single.defer(() -> Single.just(finalRateLimit)))
.doFinally(lock::unlock);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -83,7 +83,7 @@
<gson.version>2.7</gson.version>
<guava.version>30.1.1-jre</guava.version>
<hamcrest.version>1.3</hamcrest.version>
<hazelcast.version>3.12.9</hazelcast.version>
<hazelcast.version>4.1.1</hazelcast.version>
<imageio.version>3.7.0</imageio.version>
<jackson-mapper-asl.version>1.9.13</jackson-mapper-asl.version>
<java-jwt.version>3.10.2</java-jwt.version>
Expand Down

0 comments on commit 8e68014

Please sign in to comment.