All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.lettuce.core.masterreplica.SentinelTopologyRefreshConnections Maven / Gradle / Ivy

Go to download

Advanced and thread-safe Java Redis client for synchronous, asynchronous, and reactive usage. Supports Cluster, Sentinel, Pipelining, Auto-Reconnect, Codecs and much more.

The newest version!
package io.lettuce.core.masterreplica;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;

import io.lettuce.core.RedisException;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;

/**
 * @author Mark Paluch
 */
class SentinelTopologyRefreshConnections extends
        CompletableEventLatchSupport, SentinelTopologyRefreshConnections> {

    private final List exceptions = new CopyOnWriteArrayList<>();

    private final AtomicInteger success = new AtomicInteger();

    /**
     * Construct a new {@link CompletableEventLatchSupport} class expecting {@code expectedCount} notifications.
     *
     * @param expectedCount
     */
    public SentinelTopologyRefreshConnections(int expectedCount) {
        super(expectedCount);
    }

    @Override
    protected void onAccept(StatefulRedisPubSubConnection value) {
        success.incrementAndGet();
    }

    @Override
    protected void onError(Throwable value) {
        exceptions.add(value);
    }

    @Override
    protected void onEmit(Emission emission) {

        if (success.get() == 0) {

            RedisException exception = new RedisException("Cannot attach to Redis Sentinel for topology refresh");
            exceptions.forEach(exception::addSuppressed);
            emission.error(exception);
        } else {
            emission.success(this);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy