|
|
|
@ -24,10 +24,12 @@ import org.redisson.command.CommandBatchService;
|
|
|
|
|
import org.redisson.connection.ConnectionManager;
|
|
|
|
|
import org.redisson.connection.NodeSource;
|
|
|
|
|
import org.redisson.liveobject.core.RedissonObjectBuilder;
|
|
|
|
|
import org.redisson.misc.CompletableFutureWrapper;
|
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
@ -46,17 +48,14 @@ public class CommandReactiveBatchService extends CommandReactiveService {
|
|
|
|
|
@Override
|
|
|
|
|
public <R> Mono<R> reactive(Callable<RFuture<R>> supplier) {
|
|
|
|
|
Mono<R> mono = super.reactive(new Callable<RFuture<R>>() {
|
|
|
|
|
volatile RFuture<R> future;
|
|
|
|
|
final CompletableFuture<R> future = new CompletableFuture<>();
|
|
|
|
|
final AtomicBoolean lock = new AtomicBoolean();
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<R> call() throws Exception {
|
|
|
|
|
if (future == null) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
if (future == null) {
|
|
|
|
|
future = supplier.call();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (lock.compareAndSet(false, true)) {
|
|
|
|
|
transfer(supplier.call().toCompletableFuture(), future);
|
|
|
|
|
}
|
|
|
|
|
return future;
|
|
|
|
|
return new CompletableFutureWrapper<>(future);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mono.subscribe();
|
|
|
|
|