Search in sources :

Example 6 with CommandHandler

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

the class ChannelGroupListener method channelInactive.

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    CommandHandler commandHandler = getCommandHandler(ctx);
    String epid = commandHandler.getEndpoint().getId();
    eventBus.publish(new DisconnectedEvent(getRedisUri(ctx.channel()), epid, commandHandler.getChannelId(), local(ctx), remote(ctx)));
    channels.remove(ctx.channel());
    super.channelInactive(ctx);
}
Also used : DisconnectedEvent(io.lettuce.core.event.connection.DisconnectedEvent) CommandHandler(io.lettuce.core.protocol.CommandHandler)

Example 7 with CommandHandler

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

the class ConnectionEventTrigger method channelActive.

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    Channel channel = ctx.channel();
    connectionEvents.fireEventRedisConnected(connection, channel.remoteAddress());
    CommandHandler commandHandler = getCommandHandler(ctx);
    String epid = commandHandler.getEndpoint().getId();
    eventBus.publish(new ConnectionActivatedEvent(getRedisUri(channel), epid, commandHandler.getChannelId(), local(ctx), remote(ctx)));
    super.channelActive(ctx);
}
Also used : Channel(io.netty.channel.Channel) CommandHandler(io.lettuce.core.protocol.CommandHandler) ConnectionActivatedEvent(io.lettuce.core.event.connection.ConnectionActivatedEvent)

Example 8 with CommandHandler

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

the class RedisClient method connectStandaloneAsync.

private <K, V> ConnectionFuture<StatefulRedisConnection<K, V>> connectStandaloneAsync(RedisCodec<K, V> codec, RedisURI redisURI, Duration timeout) {
    assertNotNull(codec);
    checkValidRedisURI(redisURI);
    logger.debug("Trying to get a Redis connection for: {}", redisURI);
    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());
    }
    StatefulRedisConnectionImpl<K, V> connection = newStatefulRedisConnection(writer, endpoint, codec, timeout);
    ConnectionFuture<StatefulRedisConnection<K, V>> future = connectStatefulAsync(connection, endpoint, redisURI, () -> new CommandHandler(getOptions(), getResources(), endpoint));
    future.whenComplete((channelHandler, throwable) -> {
        if (throwable != null) {
            connection.closeAsync();
        }
    });
    return future;
}
Also used : CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) DefaultEndpoint(io.lettuce.core.protocol.DefaultEndpoint) CommandHandler(io.lettuce.core.protocol.CommandHandler) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection)

Example 9 with CommandHandler

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

the class RedisClusterClient method connectToNodeAsync.

/**
 * Create a connection to a redis socket address.
 *
 * @param codec Use this codec to encode/decode keys and values, must not be {@code null}
 * @param nodeId the nodeId
 * @param clusterWriter global cluster writer
 * @param socketAddressSupplier supplier for the socket address
 * @param <K> Key type
 * @param <V> Value type
 * @return A new connection
 */
<K, V> ConnectionFuture<StatefulRedisConnection<K, V>> connectToNodeAsync(RedisCodec<K, V> codec, String nodeId, RedisChannelWriter clusterWriter, Mono<SocketAddress> socketAddressSupplier) {
    assertNotNull(codec);
    assertNotEmpty(initialUris);
    LettuceAssert.notNull(socketAddressSupplier, "SocketAddressSupplier must not be null");
    ClusterNodeEndpoint endpoint = new ClusterNodeEndpoint(getClusterClientOptions(), getResources(), clusterWriter);
    RedisChannelWriter writer = endpoint;
    if (CommandExpiryWriter.isSupported(getClusterClientOptions())) {
        writer = new CommandExpiryWriter(writer, getClusterClientOptions(), getResources());
    }
    if (CommandListenerWriter.isSupported(getCommandListeners())) {
        writer = new CommandListenerWriter(writer, getCommandListeners());
    }
    StatefulRedisConnectionImpl<K, V> connection = newStatefulRedisConnection(writer, endpoint, codec, getFirstUri().getTimeout());
    ConnectionFuture<StatefulRedisConnection<K, V>> connectionFuture = connectStatefulAsync(connection, endpoint, getFirstUri(), socketAddressSupplier, () -> new CommandHandler(getClusterClientOptions(), getResources(), endpoint));
    return connectionFuture.whenComplete((conn, throwable) -> {
        if (throwable != null) {
            connection.closeAsync();
        }
    });
}
Also used : CommandExpiryWriter(io.lettuce.core.protocol.CommandExpiryWriter) CommandHandler(io.lettuce.core.protocol.CommandHandler) PubSubCommandHandler(io.lettuce.core.pubsub.PubSubCommandHandler) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection)

Example 10 with CommandHandler

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

the class ReactiveBackpressurePropagationUnitTests method before.

@BeforeEach
void before() {
    when(clientResources.commandLatencyRecorder()).thenReturn(latencyCollector);
    when(clientResources.tracing()).thenReturn(Tracing.disabled());
    when(statefulConnection.dispatch(any(RedisCommand.class))).thenAnswer(invocation -> {
        RedisCommand command = (RedisCommand) invocation.getArguments()[0];
        embeddedChannel.writeOutbound(command);
        return command;
    });
    commandHandler = new CommandHandler(ClientOptions.create(), clientResources, endpoint);
    embeddedChannel = new EmbeddedChannel(commandHandler);
    embeddedChannel.connect(new LocalAddress("remote"));
}
Also used : LocalAddress(io.netty.channel.local.LocalAddress) RedisCommand(io.lettuce.core.protocol.RedisCommand) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) CommandHandler(io.lettuce.core.protocol.CommandHandler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CommandHandler (io.lettuce.core.protocol.CommandHandler)10 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)5 CommandExpiryWriter (io.lettuce.core.protocol.CommandExpiryWriter)5 PubSubCommandHandler (io.lettuce.core.pubsub.PubSubCommandHandler)5 DefaultEndpoint (io.lettuce.core.protocol.DefaultEndpoint)4 RedisCodec (io.lettuce.core.codec.RedisCodec)3 StringCodec (io.lettuce.core.codec.StringCodec)3 Futures (io.lettuce.core.internal.Futures)3 LettuceAssert (io.lettuce.core.internal.LettuceAssert)3 PushHandler (io.lettuce.core.protocol.PushHandler)3 PubSubEndpoint (io.lettuce.core.pubsub.PubSubEndpoint)3 StatefulRedisPubSubConnection (io.lettuce.core.pubsub.StatefulRedisPubSubConnection)3 StatefulRedisPubSubConnectionImpl (io.lettuce.core.pubsub.StatefulRedisPubSubConnectionImpl)3 ClientResources (io.lettuce.core.resource.ClientResources)3 InternalLogger (io.netty.util.internal.logging.InternalLogger)3 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)3 SocketAddress (java.net.SocketAddress)3 Duration (java.time.Duration)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3