Search in sources :

Example 6 with RedissonShutdownException

use of org.redisson.RedissonShutdownException in project redisson by redisson.

the class RedisExecutor method execute.

public void execute() {
    if (mainPromise.isCancelled()) {
        free();
        return;
    }
    if (!connectionManager.getShutdownLatch().acquire()) {
        free();
        mainPromise.completeExceptionally(new RedissonShutdownException("Redisson is shutdown"));
        return;
    }
    codec = getCodec(codec);
    CompletableFuture<RedisConnection> connectionFuture = getConnection().toCompletableFuture();
    CompletableFuture<R> attemptPromise = new CompletableFuture<>();
    mainPromiseListener = (r, e) -> {
        if (mainPromise.isCancelled() && connectionFuture.cancel(false)) {
            log.debug("Connection obtaining canceled for {}", command);
            timeout.cancel();
            if (attemptPromise.cancel(false)) {
                free();
            }
        }
    };
    if (attempt == 0) {
        mainPromise.whenComplete((r, e) -> {
            if (this.mainPromiseListener != null) {
                this.mainPromiseListener.accept(r, e);
            }
        });
    }
    scheduleRetryTimeout(connectionFuture, attemptPromise);
    connectionFuture.whenComplete((connection, e) -> {
        if (connectionFuture.isCancelled()) {
            connectionManager.getShutdownLatch().release();
            return;
        }
        if (connectionFuture.isDone() && connectionFuture.isCompletedExceptionally()) {
            connectionManager.getShutdownLatch().release();
            exception = convertException(connectionFuture);
            return;
        }
        sendCommand(attemptPromise, connection);
        writeFuture.addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                checkWriteFuture(writeFuture, attemptPromise, connection);
            }
        });
    });
    attemptPromise.whenComplete((r, e) -> {
        releaseConnection(attemptPromise, connectionFuture);
        checkAttemptPromise(attemptPromise, connectionFuture);
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) CompletableFuture(java.util.concurrent.CompletableFuture) RedissonShutdownException(org.redisson.RedissonShutdownException) ChannelFutureListener(io.netty.channel.ChannelFutureListener) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) RedissonShutdownException(org.redisson.RedissonShutdownException)

Aggregations

RedissonShutdownException (org.redisson.RedissonShutdownException)6 ChannelFuture (io.netty.channel.ChannelFuture)5 ChannelFutureListener (io.netty.channel.ChannelFutureListener)5 Timeout (io.netty.util.Timeout)4 TimerTask (io.netty.util.TimerTask)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Channel (io.netty.channel.Channel)2 FutureListener (io.netty.util.concurrent.FutureListener)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CancellationException (java.util.concurrent.CancellationException)2 CompletionException (java.util.concurrent.CompletionException)2 TimeUnit (java.util.concurrent.TimeUnit)2 RFuture (org.redisson.api.RFuture)2 RedisAskException (org.redisson.client.RedisAskException)2 RedisException (org.redisson.client.RedisException)2 RedisLoadingException (org.redisson.client.RedisLoadingException)2 RedisMovedException (org.redisson.client.RedisMovedException)2 RedisTimeoutException (org.redisson.client.RedisTimeoutException)2 Codec (org.redisson.client.codec.Codec)2