@Override public boolean await(RFuture<?> future, long timeout, TimeUnit timeoutUnit) throws InterruptedException { final CountDownLatch l = new CountDownLatch(1); future.addListener(new FutureListener<Object>() { @Override public void operationComplete(Future<Object> future) throws Exception { l.countDown(); } }); return l.await(timeout, timeoutUnit); }
private <T> void syncExecute(RemotePromise<T> promise) { RFuture<Boolean> addFuture = promise.getAddFuture(); addFuture.syncUninterruptibly(); Boolean res = addFuture.getNow(); if (!res) { throw new RejectedExecutionException("Task rejected. ExecutorService is in shutdown state"); } }
private void cancel(List<RFuture<?>> futures) { for (RFuture<?> future : futures) { future.cancel(true); } }
@Override public <V> V get(RFuture<V> future) { if (!future.isDone()) { final CountDownLatch l = new CountDownLatch(1); future.addListener(new FutureListener<V>() { @Override public void operationComplete(Future<V> future) throws Exception { l.countDown(); } }); boolean interrupted = false; while (!future.isDone()) { try { l.await(); } catch (InterruptedException e) { interrupted = true; break; } } if (interrupted) { Thread.currentThread().interrupt(); } } // commented out due to blocking issues up to 200 ms per minute for each thread // future.awaitUninterruptibly(); if (future.isSuccess()) { return future.getNow(); } throw convertException(future); }
@Override public void run(Timeout timeout) throws Exception { CommandData<?, ?> commandData = connection.getCurrentCommand(); if ((commandData == null || !commandData.isBlockingCommand()) && (future.cancel(false) || !future.isSuccess())) { ctx.channel().close(); log.debug("channel: {} closed due to PING response timeout set in {} ms", ctx.channel(), config.getPingConnectionInterval()); } else { sendPing(ctx); } } }, config.getPingConnectionInterval(), TimeUnit.MILLISECONDS);
futureAdd.await(); if (!futureAdd.isSuccess()) { if (responseFuture != null) { responseFuture.cancel(false); ackFuture.cancel(false); throw futureAdd.cause(); if (!futureAdd.get()) { if (responseFuture != null) { responseFuture.cancel(false); ackFuture.cancel(false); ackFuture.await(); RemoteServiceAck ack = ackFuture.getNow(); if (ack == null) { RFuture<RemoteServiceAck> ackFutureAttempt = tryPollAckAgainAsync(optionsCopy, ackName, requestId); ackFutureAttempt.await(); ack = ackFutureAttempt.getNow(); if (ack == null) { throw new RemoteServiceAckTimeoutException("No ACK response after "
RFuture<RedisConnection> connectionFuture = connectToNode(cfg, addr, null, addr.getHost()); try { RedisConnection connection = connectionFuture.syncUninterruptibly().getNow(); masterFuture.awaitUninterruptibly(); if (!masterFuture.isSuccess()) { lastException = masterFuture.cause(); continue; for (RFuture<Void> future : masterFuture.getNow()) { future.awaitUninterruptibly(); if (!future.isSuccess()) { lastException = future.cause();
public <R> R await(RFuture<R> future) { final CountDownLatch l = new CountDownLatch(1); future.addListener(new FutureListener<R>() { @Override public void operationComplete(Future<R> future) throws Exception { l.countDown(); } }); try { if (!l.await(redisClient.getCommandTimeout(), TimeUnit.MILLISECONDS)) { RPromise<R> promise = (RPromise<R>)future; RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout for " + redisClient.getAddr()); promise.tryFailure(ex); throw ex; } if (!future.isSuccess()) { if (future.cause() instanceof RedisException) { throw (RedisException) future.cause(); } throw new RedisException("Unexpected exception while processing command", future.cause()); } return future.getNow(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return null; } }
for (RedisClientEntry entry : clients) { RFuture<RedisConnection> f = entry.getClient().connectAsync(); f.addListener(new FutureListener<RedisConnection>() { @Override public void operationComplete(Future<RedisConnection> future) throws Exception { for (Entry<RedisConnection, RFuture<String>> entry : result.entrySet()) { RFuture<String> f = entry.getValue(); f.awaitUninterruptibly(); if (!"PONG".equals(f.getNow())) { res = false;
@Override public void unlock() { List<RFuture<Void>> futures = new ArrayList<RFuture<Void>>(locks.size()); for (RLock lock : locks) { futures.add(lock.unlockAsync()); } for (RFuture<Void> future : futures) { future.syncUninterruptibly(); } }
RFuture<RedisConnection> connFuture, final boolean noResult, final long responseTimeout, final int attempts, ExecutionMode executionMode, final AtomicInteger slots) { if (connFuture.isCancelled()) { connectionManager.getShutdownLatch().release(); return; if (!connFuture.isSuccess()) { connectionManager.getShutdownLatch().release(); details.setException(convertException(connFuture)); final RedisConnection connection = connFuture.getNow(); boolean isAtomic = executionMode != ExecutionMode.IN_MEMORY; boolean isQueued = executionMode == ExecutionMode.REDIS_READ_ATOMIC || executionMode == ExecutionMode.REDIS_WRITE_ATOMIC;
private void retrieveAddresses() { ConnectionManager connectionManager = ((Redisson)redisson).getConnectionManager(); for (MasterSlaveEntry entry : connectionManager.getEntrySet()) { RFuture<RedisConnection> readFuture = entry.connectionReadOp(null); if (readFuture.awaitUninterruptibly((long)connectionManager.getConfig().getConnectTimeout()) && readFuture.isSuccess()) { RedisConnection connection = readFuture.getNow(); entry.releaseRead(connection); remoteAddress = (InetSocketAddress) connection.getChannel().remoteAddress(); localAddress = (InetSocketAddress) connection.getChannel().localAddress(); return; } RFuture<RedisConnection> writeFuture = entry.connectionWriteOp(null); if (writeFuture.awaitUninterruptibly((long)connectionManager.getConfig().getConnectTimeout()) && writeFuture.isSuccess()) { RedisConnection connection = writeFuture.getNow(); entry.releaseWrite(connection); remoteAddress = (InetSocketAddress) connection.getChannel().remoteAddress(); localAddress = (InetSocketAddress) connection.getChannel().localAddress(); return; } } }
@Override public ClusterInfo clusterGetClusterInfo() { RFuture<Map<String, String>> f = executorService.readAsync((String)null, StringCodec.INSTANCE, RedisCommands.CLUSTER_INFO); syncFuture(f); Properties props = new Properties(); for (Entry<String, String> entry : f.getNow().entrySet()) { props.setProperty(entry.getKey(), entry.getValue()); } return new ClusterInfo(props); }
@Override public void syncSubscription(RFuture<?> future) { MasterSlaveServersConfig config = connectionManager.getConfig(); try { int timeout = config.getTimeout() + config.getRetryInterval() * config.getRetryAttempts(); if (!future.await(timeout)) { ((RPromise<?>)future).tryFailure(new RedisTimeoutException("Subscribe timeout: (" + timeout + "ms). Increase 'subscriptionsPerConnection' and/or 'subscriptionConnectionPoolSize' parameters.")); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } future.syncUninterruptibly(); }
connectionFuture.awaitUninterruptibly(); RedisConnection connection = connectionFuture.getNow(); if (connection == null) { continue;
@Override public void operationComplete(Future<R> future) throws Exception { if (!connectionFuture.isSuccess()) { return; } RedisConnection connection = connectionFuture.getNow(); connectionManager.getShutdownLatch().release(); if (isReadOnly) { connectionManager.releaseRead(source, connection); } else { connectionManager.releaseWrite(source, connection); } if (log.isDebugEnabled()) { log.debug("connection released for command {} and params {} from slot {} using connection {}", details.getCommand(), LogHelper.toString(details.getParams()), details.getSource(), connection); } } });
f.handle((result, throwable) -> { if (!f.isSuccess()) { if (!f.isCancelled()) { LOGGER.warn("Async Redis query failed", throwable);
protected void unlockInner(Collection<RLock> locks) { List<RFuture<Void>> futures = new ArrayList<RFuture<Void>>(locks.size()); for (RLock lock : locks) { futures.add(lock.unlockAsync()); } for (RFuture<Void> unlockFuture : futures) { unlockFuture.awaitUninterruptibly(); } }