Java Code Examples for org.redisson.api.RFuture#isSuccess()

The following examples show how to use org.redisson.api.RFuture#isSuccess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubTasksExecutor.java    From redisson with Apache License 2.0 5 votes vote down vote up
public boolean await() throws Exception {
    if (Thread.currentThread().isInterrupted()) {
        cancel(futures);
        return false;
    }
    
    long timeSpent = System.currentTimeMillis() - startTime;
    if (isTimeoutExpired(timeSpent)) {
        cancel(futures);
        throw new MapReduceTimeoutException();
    }
    try {
        if (timeout > 0 && !latch.await(timeout - timeSpent, TimeUnit.MILLISECONDS)) {
            cancel(futures);
            throw new MapReduceTimeoutException();
        }
        if (timeout == 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
        cancel(futures);
        return false;
    }
    for (RFuture<?> rFuture : futures) {
        if (!rFuture.isSuccess()) {
            throw (Exception) rFuture.cause();
        }
    }
    return true;
}
 
Example 2
Source File: CommandBatchService.java    From redisson with Apache License 2.0 5 votes vote down vote up
protected void handle(RPromise<Void> mainPromise, AtomicInteger slots, RFuture<?> future) {
    if (future.isSuccess()) {
        if (slots.decrementAndGet() == 0) {
            mainPromise.trySuccess(null);
        }
    } else {
        mainPromise.tryFailure(future.cause());
    }
}
 
Example 3
Source File: RedisExecutor.java    From redisson with Apache License 2.0 4 votes vote down vote up
private void scheduleRetryTimeout(RFuture<RedisConnection> connectionFuture, RPromise<R> attemptPromise) {
    TimerTask retryTimerTask = new TimerTask() {

        @Override
        public void run(Timeout t) throws Exception {
            if (attemptPromise.isDone()) {
                return;
            }

            if (connectionFuture.cancel(false)) {
                if (exception == null) {
                    exception = new RedisTimeoutException("Unable to acquire connection! Increase connection pool size and/or retryInterval settings "
                                + "Node source: " + source
                                + ", command: " + LogHelper.toString(command, params)
                                + " after " + attempt + " retry attempts");
                }
            } else {
                if (connectionFuture.isSuccess()) {
                    if (writeFuture == null || !writeFuture.isDone()) {
                        if (attempt == attempts) {
                            if (writeFuture != null && writeFuture.cancel(false)) {
                                if (exception == null) {
                                    long totalSize = 0;
                                    if (params != null) {
                                        for (Object param : params) {
                                            if (param instanceof ByteBuf) {
                                                totalSize += ((ByteBuf) param).readableBytes();
                                            }
                                        }
                                    }

                                    exception = new RedisTimeoutException("Command still hasn't been written into connection! Increase nettyThreads and/or retryInterval settings. Payload size in bytes: " + totalSize
                                            + ". Node source: " + source + ", connection: " + connectionFuture.getNow()
                                            + ", command: " + LogHelper.toString(command, params)
                                            + " after " + attempt + " retry attempts");
                                }
                                attemptPromise.tryFailure(exception);
                            }
                            return;
                        }
                        attempt++;

                        scheduleRetryTimeout(connectionFuture, attemptPromise);
                        return;
                    }

                    if (writeFuture.isSuccess()) {
                        return;
                    }
                }
            }

            if (mainPromise.isCancelled()) {
                if (attemptPromise.cancel(false)) {
                    free();
                }
                return;
            }

            if (attempt == attempts) {
                // filled out in connectionFuture or writeFuture handler
                attemptPromise.tryFailure(exception);
                return;
            }
            if (!attemptPromise.cancel(false)) {
                return;
            }

            attempt++;
            if (log.isDebugEnabled()) {
                log.debug("attempt {} for command {} and params {}",
                        attempt, command, LogHelper.toString(params));
            }
            
            mainPromiseListener = null;

            execute();
        }

    };

    timeout = connectionManager.newTimeout(retryTimerTask, retryInterval, TimeUnit.MILLISECONDS);
}