com.github.lontime.shaded.org.redisson.reactive.CommandReactiveBatchService Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 2013-2021 Nikita Koksharov
*
* 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.
*/
package com.github.lontime.shaded.org.redisson.reactive;
import com.github.lontime.shaded.org.redisson.api.BatchOptions;
import com.github.lontime.shaded.org.redisson.api.BatchResult;
import com.github.lontime.shaded.org.redisson.api.RFuture;
import com.github.lontime.shaded.org.redisson.client.codec.Codec;
import com.github.lontime.shaded.org.redisson.client.protocol.RedisCommand;
import com.github.lontime.shaded.org.redisson.command.CommandBatchService;
import com.github.lontime.shaded.org.redisson.connection.ConnectionManager;
import com.github.lontime.shaded.org.redisson.connection.NodeSource;
import com.github.lontime.shaded.org.redisson.liveobject.core.RedissonObjectBuilder;
import reactor.core.publisher.Mono;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
/**
*
* @author Nikita Koksharov
*
*/
public class CommandReactiveBatchService extends CommandReactiveService {
private final CommandBatchService batchService;
public CommandReactiveBatchService(ConnectionManager connectionManager, CommandReactiveExecutor commandExecutor, BatchOptions options) {
super(connectionManager, commandExecutor.getObjectBuilder());
batchService = new CommandBatchService(commandExecutor, options, RedissonObjectBuilder.ReferenceType.REACTIVE);
}
@Override
public Mono reactive(Callable> supplier) {
Mono mono = super.reactive(new Callable>() {
volatile RFuture future;
@Override
public RFuture call() throws Exception {
if (future == null) {
synchronized (this) {
if (future == null) {
future = supplier.call();
}
}
}
return future;
}
});
mono.subscribe();
return mono;
}
@Override
protected CompletableFuture createPromise() {
return batchService.createPromise();
}
@Override
public RFuture async(boolean readOnlyMode, NodeSource nodeSource,
Codec codec, RedisCommand command, Object[] params, boolean ignoreRedirect, boolean noRetry) {
return batchService.async(readOnlyMode, nodeSource, codec, command, params, ignoreRedirect, noRetry);
}
public RFuture> executeAsync() {
return batchService.executeAsync();
}
public RFuture discardAsync() {
return batchService.discardAsync();
}
}