Search in sources :

Example 1 with WriteRedisConnectionException

use of org.redisson.client.WriteRedisConnectionException in project redisson by redisson.

the class CommandBatchService method checkWriteFuture.

private void checkWriteFuture(final RPromise<Void> attemptPromise, AsyncDetails details, final RedisConnection connection, ChannelFuture future, boolean noResult) {
    if (attemptPromise.isDone() || future.isCancelled()) {
        return;
    }
    if (!future.isSuccess()) {
        details.setException(new WriteRedisConnectionException("Can't write command batch to channel: " + future.channel(), future.cause()));
    } else {
        details.getTimeout().cancel();
        TimerTask timeoutTask = new TimerTask() {

            @Override
            public void run(Timeout timeout) throws Exception {
                attemptPromise.tryFailure(new RedisTimeoutException("Redis server response timeout during command batch execution. Channel: " + connection.getChannel()));
            }
        };
        Timeout timeout = connectionManager.newTimeout(timeoutTask, connectionManager.getConfig().getTimeout(), TimeUnit.MILLISECONDS);
        details.setTimeout(timeout);
    }
}
Also used : WriteRedisConnectionException(org.redisson.client.WriteRedisConnectionException) TimerTask(io.netty.util.TimerTask) RedisTimeoutException(org.redisson.client.RedisTimeoutException) Timeout(io.netty.util.Timeout)

Example 2 with WriteRedisConnectionException

use of org.redisson.client.WriteRedisConnectionException in project redisson by redisson.

the class CommandAsyncService method checkWriteFuture.

private <V, R> void checkWriteFuture(final AsyncDetails<V, R> details, final RedisConnection connection) {
    ChannelFuture future = details.getWriteFuture();
    if (details.getAttemptPromise().isDone() || future.isCancelled()) {
        return;
    }
    if (!future.isSuccess()) {
        details.setException(new WriteRedisConnectionException("Can't write command: " + details.getCommand() + ", params: " + LogHelper.toString(details.getParams()) + " to channel: " + future.channel(), future.cause()));
        return;
    }
    details.getTimeout().cancel();
    long timeoutTime = connectionManager.getConfig().getTimeout();
    if (RedisCommands.BLOCKING_COMMANDS.contains(details.getCommand().getName())) {
        Long popTimeout = Long.valueOf(details.getParams()[details.getParams().length - 1].toString());
        handleBlockingOperations(details, connection, popTimeout);
        if (popTimeout == 0) {
            return;
        }
        timeoutTime += popTimeout * 1000;
        // add 1 second due to issue https://github.com/antirez/redis/issues/874
        timeoutTime += 1000;
    }
    final long timeoutAmount = timeoutTime;
    TimerTask timeoutTask = new TimerTask() {

        @Override
        public void run(Timeout timeout) throws Exception {
            details.getAttemptPromise().tryFailure(new RedisTimeoutException("Redis server response timeout (" + timeoutAmount + " ms) occured for command: " + details.getCommand() + " with params: " + LogHelper.toString(details.getParams()) + " channel: " + connection.getChannel()));
        }
    };
    Timeout timeout = connectionManager.newTimeout(timeoutTask, timeoutTime, TimeUnit.MILLISECONDS);
    details.setTimeout(timeout);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) WriteRedisConnectionException(org.redisson.client.WriteRedisConnectionException) TimerTask(io.netty.util.TimerTask) RedisTimeoutException(org.redisson.client.RedisTimeoutException) Timeout(io.netty.util.Timeout)

Example 3 with WriteRedisConnectionException

use of org.redisson.client.WriteRedisConnectionException in project redisson by redisson.

the class CommandsQueue method channelInactive.

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    Queue<QueueCommandHolder> queue = ctx.channel().attr(COMMANDS_QUEUE).get();
    Iterator<QueueCommandHolder> iterator = queue.iterator();
    while (iterator.hasNext()) {
        QueueCommandHolder command = iterator.next();
        if (command.getCommand().isBlockingCommand()) {
            continue;
        }
        iterator.remove();
        command.getChannelPromise().tryFailure(new WriteRedisConnectionException("Channel has been closed! Can't write command: " + LogHelper.toString(command.getCommand()) + " to channel: " + ctx.channel()));
    }
    super.channelInactive(ctx);
}
Also used : WriteRedisConnectionException(org.redisson.client.WriteRedisConnectionException) QueueCommandHolder(org.redisson.client.protocol.QueueCommandHolder)

Example 4 with WriteRedisConnectionException

use of org.redisson.client.WriteRedisConnectionException in project redisson by redisson.

the class CommandsQueuePubSub method channelInactive.

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    while (true) {
        QueueCommandHolder command = queue.poll();
        if (command == null) {
            break;
        }
        command.getChannelPromise().tryFailure(new WriteRedisConnectionException("Channel has been closed! Can't write command: " + LogHelper.toString(command.getCommand()) + " to channel: " + ctx.channel()));
    }
    super.channelInactive(ctx);
}
Also used : WriteRedisConnectionException(org.redisson.client.WriteRedisConnectionException) QueueCommandHolder(org.redisson.client.protocol.QueueCommandHolder)

Aggregations

WriteRedisConnectionException (org.redisson.client.WriteRedisConnectionException)4 Timeout (io.netty.util.Timeout)2 TimerTask (io.netty.util.TimerTask)2 RedisTimeoutException (org.redisson.client.RedisTimeoutException)2 QueueCommandHolder (org.redisson.client.protocol.QueueCommandHolder)2 ChannelFuture (io.netty.channel.ChannelFuture)1