@Override public void handleFailure(Throwable t) { if (throwableType == null || throwableType.isAssignableFrom(t.getClass())) { try { slf.setRunningThread(Thread.currentThread()); ListenableFuture<RT> mapFuture = mapper.apply((TT)t); slf.updateDelegateFuture(mapFuture); mapFuture.addCallback(slf); slf.setRunningThread(null); // may be processing async now } catch (Throwable newT) { slf.setFailure(newT); } } else { slf.setFailure(t); } } }, executor, optimizeExecution);
@Override public void handleFailure(Throwable t) { if (throwableType == null || throwableType.isAssignableFrom(t.getClass())) { try { slf.setRunningThread(Thread.currentThread()); ListenableFuture<RT> mapFuture = mapper.apply((TT)t); slf.updateDelegateFuture(mapFuture); mapFuture.addCallback(slf); slf.setRunningThread(null); // may be processing async now } catch (Throwable newT) { slf.setFailure(newT); } } else { slf.setFailure(t); } } }, executor, optimizeExecution);
@Override public void handleResult(List<ListenableFuture<?>> failedFutures) { if (failedFutures.isEmpty()) { resultFuture.setResult(result); } else { // propagate error ListenableFuture<?> f = failedFutures.get(0); if (f.isCancelled()) { resultFuture.cancelRegardlessOfDelegateFutureState(false); } else { try { f.get(); } catch (ExecutionException e) { resultFuture.setFailure(e.getCause()); } catch (InterruptedException e) { // should not be possible throw new RuntimeException(e); } } } }
resultFuture.setResult(result); } else { resultFuture.setFailure(new TimeoutException()); } catch (ExecutionException e) { resultFuture.setFailure(e.getCause()); return; resultFuture.setFailure(t); } finally {
resultFuture.setResult(result); } else { resultFuture.setFailure(new TimeoutException()); } catch (ExecutionException e) { resultFuture.setFailure(e.getCause()); return; resultFuture.setFailure(t); } finally {
@Override public void handleResult(T result) { try { if (startTime > 0 && Clock.lastKnownForwardProgressingMillis() - startTime > timeoutMillis) { if (timeoutProvideLastValue) { resultFuture.setResult(result); } else { resultFuture.setFailure(new TimeoutException()); } } else if (loopTest.test(result)) { ListenableFuture<T> lf = scheduler.submitScheduled(cancelCheckingTask, scheduleDelayMillis); resultFuture.updateDelegateFuture(lf); // TODO - if future is always already complete, this may StackOverflow lf.addCallback(this); // add this to check again once execution completes } else { // once we have our result, this will end our loop resultFuture.setResult(result); } } catch (Throwable t) { // failure likely from the predicate test, handle exception // so the behavior is closer to if the exception was thrown from a task submitted to the pool ExceptionUtils.handleException(t); resultFuture.setFailure(t); } } });
@Override public void handleResult(T result) { try { if (startTime > 0 && Clock.lastKnownForwardProgressingMillis() - startTime > timeoutMillis) { if (timeoutProvideLastValue) { resultFuture.setResult(result); } else { resultFuture.setFailure(new TimeoutException()); } } else if (loopTest.test(result)) { ListenableFuture<T> lf = scheduler.submitScheduled(cancelCheckingTask, scheduleDelayMillis); resultFuture.updateDelegateFuture(lf); // TODO - if future is always already complete, this may StackOverflow lf.addCallback(this); // add this to check again once execution completes } else { // once we have our result, this will end our loop resultFuture.setResult(result); } } catch (Throwable t) { // failure likely from the predicate test, handle exception // so the behavior is closer to if the exception was thrown from a task submitted to the pool ExceptionUtils.handleException(t); resultFuture.setFailure(t); } } });
@Override public void handleResult(List<ListenableFuture<?>> failedFutures) { if (failedFutures.isEmpty()) { resultFuture.setResult(result); } else { // propagate error ListenableFuture<?> f = failedFutures.get(0); if (f.isCancelled()) { resultFuture.cancelRegardlessOfDelegateFutureState(false); } else { try { f.get(); } catch (ExecutionException e) { resultFuture.setFailure(e.getCause()); } catch (InterruptedException e) { // should not be possible throw new RuntimeException(e); } } } }
@Override public void handleResult(ST result) { try { slf.setRunningThread(Thread.currentThread()); ListenableFuture<? extends RT> mapFuture = mapper.apply(result); slf.updateDelegateFuture(mapFuture); mapFuture.addCallback(slf); slf.setRunningThread(null); // may be processing async now } catch (Throwable t) { // failure calculating transformation, let handler get a chance to see the uncaught exception // This makes the behavior closer to if the exception was thrown from a task submitted to the pool ExceptionUtils.handleException(t); slf.setFailure(t); } } }, executor, optimizeExecution);
@Override public void handleResult(ST result) { try { slf.setRunningThread(Thread.currentThread()); ListenableFuture<? extends RT> mapFuture = mapper.apply(result); slf.updateDelegateFuture(mapFuture); mapFuture.addCallback(slf); slf.setRunningThread(null); // may be processing async now } catch (Throwable t) { // failure calculating transformation, let handler get a chance to see the uncaught exception // This makes the behavior closer to if the exception was thrown from a task submitted to the pool ExceptionUtils.handleException(t); slf.setFailure(t); } } }, executor, optimizeExecution);
@Override public void handleFailure(Throwable t) { resultFuture.setFailure(t); } });
@Override public void handleFailure(Throwable t) { resultFuture.setFailure(t); } });