Search in sources :

Example 1 with RedisCommandTimeoutException

use of io.lettuce.core.RedisCommandTimeoutException in project lettuce-core by lettuce-io.

the class RedisHandshakeHandler method channelRegistered.

@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    Runnable timeoutGuard = () -> {
        timedOut = true;
        if (handshakeFuture.isDone()) {
            return;
        }
        fail(ctx, new RedisCommandTimeoutException("Connection initialization timed out after " + ExceptionFactory.formatTimeout(initializeTimeout)));
    };
    Timeout timeoutHandle = clientResources.timer().newTimeout(t -> {
        if (clientResources.eventExecutorGroup().isShuttingDown()) {
            timeoutGuard.run();
            return;
        }
        clientResources.eventExecutorGroup().submit(timeoutGuard);
    }, initializeTimeout.toNanos(), TimeUnit.NANOSECONDS);
    handshakeFuture.thenAccept(ignore -> {
        timeoutHandle.cancel();
    });
    super.channelRegistered(ctx);
}
Also used : Timeout(io.netty.util.Timeout) RedisCommandTimeoutException(io.lettuce.core.RedisCommandTimeoutException)

Aggregations

RedisCommandTimeoutException (io.lettuce.core.RedisCommandTimeoutException)1 Timeout (io.netty.util.Timeout)1