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);
}
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);
}
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;
}
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();
}
});
}
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"));
}
Aggregations