private <T> io.netty.util.concurrent.Future<T> poll(List<RExecutorFuture<?>> futures, long timeout, TimeUnit timeUnit) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<io.netty.util.concurrent.Future<T>> result = new AtomicReference<io.netty.util.concurrent.Future<T>>(); FutureListener<T> listener = new FutureListener<T>() { @Override public void operationComplete(io.netty.util.concurrent.Future<T> future) throws Exception { latch.countDown(); result.compareAndSet(null, future); } }; for (Future<?> future : futures) { RFuture<T> f = (RFuture<T>) future; f.addListener(listener); } if (timeout == -1) { latch.await(); } else { latch.await(timeout, timeUnit); } for (Future<?> future : futures) { RFuture<T> f = (RFuture<T>) future; f.removeListener(listener); } return result.get(); }
private <T> io.netty.util.concurrent.Future<T> poll(List<RExecutorFuture<?>> futures, long timeout, TimeUnit timeUnit) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<io.netty.util.concurrent.Future<T>> result = new AtomicReference<io.netty.util.concurrent.Future<T>>(); FutureListener<T> listener = new FutureListener<T>() { @Override public void operationComplete(io.netty.util.concurrent.Future<T> future) throws Exception { latch.countDown(); result.compareAndSet(null, future); } }; for (Future<?> future : futures) { RFuture<T> f = (RFuture<T>) future; f.addListener(listener); } if (timeout == -1) { latch.await(); } else { latch.await(timeout, timeUnit); } for (Future<?> future : futures) { RFuture<T> f = (RFuture<T>) future; f.removeListener(listener); } return result.get(); }
@Override public void operationComplete(Future<R> future) throws Exception { if (scheduledFuture != null) { scheduledFuture.cancel(); } synchronized (listener) { connectionManager.getShutdownPromise().removeListener(listener); } // handling cancel operation for blocking commands if (future.isCancelled() && !details.getAttemptPromise().isDone()) { log.debug("Canceled blocking operation {} used {}", details.getCommand(), connection); connection.forceFastReconnectAsync().addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { details.getAttemptPromise().cancel(true); } }); return; } if (future.cause() instanceof RedissonShutdownException) { details.getAttemptPromise().tryFailure(future.cause()); } } });
@Override public void operationComplete(Future<R> future) throws Exception { if (scheduledFuture != null) { scheduledFuture.cancel(); } synchronized (listener) { connectionManager.getShutdownPromise().removeListener(listener); } // handling cancel operation for blocking commands if (future.isCancelled() && !details.getAttemptPromise().isDone()) { log.debug("Canceled blocking operation {} used {}", details.getCommand(), connection); connection.forceFastReconnectAsync().addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { details.getAttemptPromise().cancel(true); } }); return; } if (future.cause() instanceof RedissonShutdownException) { details.getAttemptPromise().tryFailure(future.cause()); } } });
private <T> io.netty.util.concurrent.Future<T> poll(List<RExecutorFuture<?>> futures, long timeout, TimeUnit timeUnit) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<io.netty.util.concurrent.Future<T>> result = new AtomicReference<io.netty.util.concurrent.Future<T>>(); FutureListener<T> listener = new FutureListener<T>() { @Override public void operationComplete(io.netty.util.concurrent.Future<T> future) throws Exception { latch.countDown(); result.compareAndSet(null, future); } }; for (Future<?> future : futures) { RFuture<T> f = (RFuture<T>) future; f.addListener(listener); } if (timeout == -1) { latch.await(); } else { latch.await(timeout, timeUnit); } for (Future<?> future : futures) { RFuture<T> f = (RFuture<T>) future; f.removeListener(listener); } return result.get(); }
@Override public void operationComplete(Future<R> future) throws Exception { if (scheduledFuture != null) { scheduledFuture.cancel(); } synchronized (listener) { connectionManager.getShutdownPromise().removeListener(listener); } // handling cancel operation for blocking commands if (future.isCancelled() && !details.getAttemptPromise().isDone()) { log.debug("Canceled blocking operation {} used {}", details.getCommand(), connection); connection.forceFastReconnectAsync().addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { details.getAttemptPromise().cancel(true); } }); return; } if (future.cause() instanceof RedissonShutdownException) { details.getAttemptPromise().tryFailure(future.cause()); } } });