use of org.redisson.client.RedisRedirectException in project redisson by redisson.
the class CommandAsyncService method allAsync.
private <T, R> RFuture<R> allAsync(boolean readOnlyMode, Codec codec, RedisCommand<T> command, SlotCallback<T, R> callback, Object... params) {
RPromise<R> mainPromise = new RedissonPromise<R>();
Collection<MasterSlaveEntry> nodes = connectionManager.getEntrySet();
AtomicInteger counter = new AtomicInteger(nodes.size());
BiConsumer<T, Throwable> listener = new BiConsumer<T, Throwable>() {
@Override
public void accept(T result, Throwable u) {
if (u != null && !(u instanceof RedisRedirectException)) {
mainPromise.tryFailure(u);
return;
}
if (u instanceof RedisRedirectException) {
result = command.getConvertor().convert(result);
}
if (callback != null) {
callback.onSlotResult(result);
}
if (counter.decrementAndGet() == 0) {
if (callback != null) {
mainPromise.trySuccess(callback.onFinish());
} else {
mainPromise.trySuccess(null);
}
}
}
};
for (MasterSlaveEntry entry : nodes) {
RFuture<T> promise = async(readOnlyMode, new NodeSource(entry), codec, command, params, true, false);
promise.whenComplete(listener);
}
return mainPromise;
}
Aggregations