Search in sources :

Example 1 with Endpoint

use of io.lettuce.core.protocol.Endpoint in project lettuce-core by lettuce-io.

the class RedisClient method doConnectSentinelAsync.

private <K, V> ConnectionFuture<StatefulRedisSentinelConnection<K, V>> doConnectSentinelAsync(RedisCodec<K, V> codec, RedisURI redisURI, Duration timeout, String clientName) {
    ConnectionBuilder connectionBuilder;
    if (redisURI.isSsl()) {
        SslConnectionBuilder sslConnectionBuilder = SslConnectionBuilder.sslConnectionBuilder();
        sslConnectionBuilder.ssl(redisURI);
        connectionBuilder = sslConnectionBuilder;
    } else {
        connectionBuilder = ConnectionBuilder.connectionBuilder();
    }
    connectionBuilder.clientOptions(ClientOptions.copyOf(getOptions()));
    connectionBuilder.clientResources(getResources());
    DefaultEndpoint endpoint = new DefaultEndpoint(getOptions(), getResources());
    RedisChannelWriter writer = endpoint;
    if (CommandExpiryWriter.isSupported(getOptions())) {
        writer = new CommandExpiryWriter(writer, getOptions(), getResources());
    }
    if (CommandListenerWriter.isSupported(getCommandListeners())) {
        writer = new CommandListenerWriter(writer, getCommandListeners());
    }
    StatefulRedisSentinelConnectionImpl<K, V> connection = newStatefulRedisSentinelConnection(writer, codec, timeout);
    ConnectionState state = connection.getConnectionState();
    state.apply(redisURI);
    if (LettuceStrings.isEmpty(state.getClientName())) {
        state.setClientName(clientName);
    }
    connectionBuilder.connectionInitializer(createHandshake(state));
    logger.debug("Connecting to Redis Sentinel, address: " + redisURI);
    connectionBuilder.endpoint(endpoint).commandHandler(() -> new CommandHandler(getOptions(), getResources(), endpoint)).connection(connection);
    connectionBuilder(getSocketAddressSupplier(redisURI), connectionBuilder, connection.getConnectionEvents(), redisURI);
    ConnectionFuture<?> sync = initializeChannelAsync(connectionBuilder);
    return sync.thenApply(ignore -> (StatefulRedisSentinelConnection<K, V>) connection).whenComplete((ignore, e) -> {
        if (e != null) {
            logger.warn("Cannot connect Redis Sentinel at " + redisURI + ": " + e);
            connection.closeAsync();
        }
    });
}
Also used : ClientResources(io.lettuce.core.resource.ClientResources) SocketAddress(java.net.SocketAddress) StringCodec(io.lettuce.core.codec.StringCodec) CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) PushHandler(io.lettuce.core.protocol.PushHandler) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) Futures(io.lettuce.core.internal.Futures) LettuceAssert(io.lettuce.core.internal.LettuceAssert) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Duration(java.time.Duration) PubSubEndpoint(io.lettuce.core.pubsub.PubSubEndpoint) StatefulRedisSentinelConnectionImpl(io.lettuce.core.sentinel.StatefulRedisSentinelConnectionImpl) ExceptionFactory(io.lettuce.core.internal.ExceptionFactory) CommandHandler(io.lettuce.core.protocol.CommandHandler) Endpoint(io.lettuce.core.protocol.Endpoint) StatefulRedisPubSubConnection(io.lettuce.core.pubsub.StatefulRedisPubSubConnection) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) CompletionException(java.util.concurrent.CompletionException) Mono(reactor.core.publisher.Mono) InetSocketAddress(java.net.InetSocketAddress) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) MasterReplica(io.lettuce.core.masterreplica.MasterReplica) RedisCodec(io.lettuce.core.codec.RedisCodec) StatefulRedisSentinelConnection(io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection) StatefulRedisPubSubConnectionImpl(io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) LettuceStrings(io.lettuce.core.internal.LettuceStrings) InternalLogger(io.netty.util.internal.logging.InternalLogger) Queue(java.util.Queue) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) CommandHandler(io.lettuce.core.protocol.CommandHandler) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) StatefulRedisSentinelConnection(io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection)

Aggregations

StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1 RedisCodec (io.lettuce.core.codec.RedisCodec)1 StringCodec (io.lettuce.core.codec.StringCodec)1 ExceptionFactory (io.lettuce.core.internal.ExceptionFactory)1 Futures (io.lettuce.core.internal.Futures)1 LettuceAssert (io.lettuce.core.internal.LettuceAssert)1 LettuceStrings (io.lettuce.core.internal.LettuceStrings)1 MasterReplica (io.lettuce.core.masterreplica.MasterReplica)1 CommandExpiryWriter (io.lettuce.core.protocol.CommandExpiryWriter)1 CommandHandler (io.lettuce.core.protocol.CommandHandler)1 DefaultEndpoint (io.lettuce.core.protocol.DefaultEndpoint)1 Endpoint (io.lettuce.core.protocol.Endpoint)1 PushHandler (io.lettuce.core.protocol.PushHandler)1 PubSubCommandHandler (io.lettuce.core.pubsub.PubSubCommandHandler)1 PubSubEndpoint (io.lettuce.core.pubsub.PubSubEndpoint)1 StatefulRedisPubSubConnection (io.lettuce.core.pubsub.StatefulRedisPubSubConnection)1 StatefulRedisPubSubConnectionImpl (io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl)1 ClientResources (io.lettuce.core.resource.ClientResources)1 StatefulRedisSentinelConnectionImpl (io.lettuce.core.sentinel.StatefulRedisSentinelConnectionImpl)1 StatefulRedisSentinelConnection (io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection)1