|
|
|
@ -15,11 +15,8 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.redisson.reactive;
|
|
|
|
|
|
|
|
|
|
import java.util.Queue;
|
|
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
|
|
import org.reactivestreams.Publisher;
|
|
|
|
|
import org.redisson.api.BatchOptions;
|
|
|
|
|
import org.redisson.api.BatchResult;
|
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
@ -32,7 +29,6 @@ import org.redisson.connection.ConnectionManager;
|
|
|
|
|
import org.redisson.connection.NodeSource;
|
|
|
|
|
import org.redisson.misc.RPromise;
|
|
|
|
|
|
|
|
|
|
import reactor.core.publisher.Flux;
|
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -43,22 +39,35 @@ import reactor.core.publisher.Mono;
|
|
|
|
|
public class CommandReactiveBatchService extends CommandReactiveService {
|
|
|
|
|
|
|
|
|
|
private final CommandBatchService batchService;
|
|
|
|
|
private final Queue<Publisher<?>> publishers = new ConcurrentLinkedQueue<Publisher<?>>();
|
|
|
|
|
|
|
|
|
|
public CommandReactiveBatchService(ConnectionManager connectionManager) {
|
|
|
|
|
public CommandReactiveBatchService(ConnectionManager connectionManager, BatchOptions options) {
|
|
|
|
|
super(connectionManager);
|
|
|
|
|
batchService = new CommandBatchService(connectionManager);
|
|
|
|
|
batchService = new CommandBatchService(connectionManager, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <R> Mono<R> reactive(Supplier<RFuture<R>> supplier) {
|
|
|
|
|
Mono<R> publisher = super.reactive(supplier);
|
|
|
|
|
publishers.add(publisher);
|
|
|
|
|
return publisher;
|
|
|
|
|
Mono<R> mono = super.reactive(new Supplier<RFuture<R>>() {
|
|
|
|
|
volatile RFuture<R> future;
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<R> get() {
|
|
|
|
|
if (future == null) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
if (future == null) {
|
|
|
|
|
future = supplier.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return future;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mono.subscribe();
|
|
|
|
|
return mono;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <R> Publisher<R> superReactive(Supplier<RFuture<R>> supplier) {
|
|
|
|
|
return super.reactive(supplier);
|
|
|
|
|
@Override
|
|
|
|
|
protected <R> RPromise<R> createPromise() {
|
|
|
|
|
return batchService.createPromise();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -68,10 +77,6 @@ public class CommandReactiveBatchService extends CommandReactiveService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RFuture<BatchResult<?>> executeAsync(BatchOptions options) {
|
|
|
|
|
for (Publisher<?> publisher : publishers) {
|
|
|
|
|
Flux.from(publisher).subscribe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return batchService.executeAsync(options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|