Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*-
* ========================LICENSE_START=================================
* Bucket4j
* %%
* Copyright (C) 2015 - 2021 Vladimir Bukhtoyarov
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package io.github.bucket4j.redis.redisson.cas;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.redisson.api.RFuture;
import org.redisson.client.RedisException;
import org.redisson.client.codec.ByteArrayCodec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.convertor.BooleanNotNullReplayConvertor;
import org.redisson.command.CommandAsyncExecutor;
import io.github.bucket4j.distributed.ExpirationAfterWriteStrategy;
import io.github.bucket4j.distributed.proxy.generic.compare_and_swap.AbstractCompareAndSwapBasedProxyManager;
import io.github.bucket4j.distributed.proxy.generic.compare_and_swap.AsyncCompareAndSwapOperation;
import io.github.bucket4j.distributed.proxy.generic.compare_and_swap.CompareAndSwapOperation;
import io.github.bucket4j.distributed.remote.RemoteBucketState;
import io.github.bucket4j.distributed.serialization.Mapper;
import io.github.bucket4j.redis.AbstractRedisProxyManagerBuilder;
import io.github.bucket4j.redis.consts.LuaScripts;
import io.github.bucket4j.redis.redisson.Bucket4jRedisson;
import io.netty.buffer.ByteBuf;
public class RedissonBasedProxyManager extends AbstractCompareAndSwapBasedProxyManager {
public static final RedisCommand SET = new RedisCommand<>("SET", new BooleanNotNullReplayConvertor());
private final CommandAsyncExecutor commandExecutor;
private final ExpirationAfterWriteStrategy expirationStrategy;
private final Mapper keyMapper;
/**
* @deprecated use {@link Bucket4jRedisson#casBasedBuilder(CommandAsyncExecutor)}
*/
@Deprecated
public static RedissonBasedProxyManagerBuilder builderFor(CommandAsyncExecutor commandExecutor) {
return new RedissonBasedProxyManagerBuilder<>(Mapper.STRING, commandExecutor);
}
public static class RedissonBasedProxyManagerBuilder extends AbstractRedisProxyManagerBuilder> {
private final CommandAsyncExecutor commandExecutor;
private Mapper keyMapper;
private RedissonBasedProxyManagerBuilder(Mapper keyMapper, CommandAsyncExecutor commandExecutor) {
this.keyMapper = Objects.requireNonNull(keyMapper);
this.commandExecutor = Objects.requireNonNull(commandExecutor);
}
public RedissonBasedProxyManagerBuilder withKeyMapper(Mapper keyMapper) {
this.keyMapper = (Mapper) Objects.requireNonNull(keyMapper);
return (RedissonBasedProxyManagerBuilder) this;
}
public RedissonBasedProxyManager build() {
return new RedissonBasedProxyManager<>(this);
}
}
public RedissonBasedProxyManager(Bucket4jRedisson.RedissonBasedProxyManagerBuilder builder) {
super(builder.getClientSideConfig());
this.commandExecutor = builder.getCommandExecutor();
this.expirationStrategy = builder.getExpirationAfterWrite().orElse(ExpirationAfterWriteStrategy.none());
this.keyMapper = builder.getKeyMapper();
}
private RedissonBasedProxyManager(RedissonBasedProxyManagerBuilder builder) {
super(builder.getClientSideConfig());
this.commandExecutor = builder.commandExecutor;
this.expirationStrategy = builder.getNotNullExpirationStrategy();
this.keyMapper = builder.keyMapper;
}
@Override
public boolean isExpireAfterWriteSupported() {
return true;
}
@Override
protected CompareAndSwapOperation beginCompareAndSwapOperation(K key) {
String stringKey = keyMapper.toString(key);
List