Search in sources :

Example 1 with RedisRedirectException

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;
}
Also used : RedissonPromise(org.redisson.misc.RedissonPromise) RedisRedirectException(org.redisson.client.RedisRedirectException) NodeSource(org.redisson.connection.NodeSource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry) BiConsumer(java.util.function.BiConsumer)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiConsumer (java.util.function.BiConsumer)1 RedisRedirectException (org.redisson.client.RedisRedirectException)1 MasterSlaveEntry (org.redisson.connection.MasterSlaveEntry)1 NodeSource (org.redisson.connection.NodeSource)1 RedissonPromise (org.redisson.misc.RedissonPromise)1