@Override public ResponseT call() { try { // NOTE: unlike gax's AttemptCallable, this ignores rpc timeouts externalFuture.setAttemptFuture(new NonCancellableFuture<ResponseT>()); if (externalFuture.isDone()) { return null; } ApiFuture<ResponseT> internalFuture = callable.futureCall(request, callContext); externalFuture.setAttemptFuture(internalFuture); } catch (Throwable e) { externalFuture.setAttemptFuture(ApiFutures.<ResponseT>immediateFailedFuture(e)); } return null; } }
if (externalFuture.isDone()) { return null;
@Override public boolean isDone() { return pollingFuture.isDone(); }
@Override public boolean isDone() { return pollingFuture.isDone(); }
/** * Submits an attempt for execution in the current thread, causing the current thread to sleep for * the specified by the {@link RetryingFuture#getAttemptSettings()} amount of time. As result, * this method completes execution only after the specified {@code retryingFuture} completes. * * @param retryingFuture the future previously returned by {@link #createFuture(Callable, * RetryingContext)} * @return returns completed {@code retryingFuture} */ @Override public ApiFuture<ResponseT> submit(RetryingFuture<ResponseT> retryingFuture) { while (!retryingFuture.isDone()) { try { sleep(retryingFuture.getAttemptSettings().getRandomizedRetryDelay()); ResponseT response = retryingFuture.getCallable().call(); retryingFuture.setAttemptFuture(ApiFutures.immediateFuture(response)); } catch (InterruptedException | InterruptedIOException | ClosedByInterruptException e) { Thread.currentThread().interrupt(); retryingFuture.setAttemptFuture(ApiFutures.<ResponseT>immediateFailedFuture(e)); } catch (Exception e) { retryingFuture.setAttemptFuture(ApiFutures.<ResponseT>immediateFailedFuture(e)); } } return retryingFuture; }
/** * Submits an attempt for execution in the current thread, causing the current thread to sleep for * the specified by the {@link RetryingFuture#getAttemptSettings()} amount of time. As result, * this method completes execution only after the specified {@code retryingFuture} completes. * * @param retryingFuture the future previously returned by {@link #createFuture(Callable, * RetryingContext)} * @return returns completed {@code retryingFuture} */ @Override public ApiFuture<ResponseT> submit(RetryingFuture<ResponseT> retryingFuture) { while (!retryingFuture.isDone()) { try { sleep(retryingFuture.getAttemptSettings().getRandomizedRetryDelay()); ResponseT response = retryingFuture.getCallable().call(); retryingFuture.setAttemptFuture(ApiFutures.immediateFuture(response)); } catch (InterruptedException | InterruptedIOException | ClosedByInterruptException e) { Thread.currentThread().interrupt(); retryingFuture.setAttemptFuture(ApiFutures.<ResponseT>immediateFailedFuture(e)); } catch (Exception e) { retryingFuture.setAttemptFuture(ApiFutures.<ResponseT>immediateFailedFuture(e)); } } return retryingFuture; }
@Override public ResponseT call() { try { // NOTE: unlike gax's AttemptCallable, this ignores rpc timeouts externalFuture.setAttemptFuture(new NonCancellableFuture<ResponseT>()); if (externalFuture.isDone()) { return null; } ApiFuture<ResponseT> internalFuture = callable.futureCall(request, callContext); externalFuture.setAttemptFuture(internalFuture); } catch (Throwable e) { externalFuture.setAttemptFuture(ApiFutures.<ResponseT>immediateFailedFuture(e)); } return null; } }
if (externalFuture.isDone()) { return null;
@Override public ResponseT call() { ApiCallContext callContext = originalCallContext; try { Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); if (!rpcTimeout.isZero()) { callContext = callContext.withTimeout(rpcTimeout); } externalFuture.setAttemptFuture(new NonCancellableFuture<ResponseT>()); if (externalFuture.isDone()) { return null; } callContext .getTracer() .attemptStarted(externalFuture.getAttemptSettings().getOverallAttemptCount()); ApiFuture<ResponseT> internalFuture = callable.futureCall(request, callContext); externalFuture.setAttemptFuture(internalFuture); } catch (Throwable e) { externalFuture.setAttemptFuture(ApiFutures.<ResponseT>immediateFailedFuture(e)); } return null; } }
@Override public ResponseT call() { ApiCallContext callContext = originalCallContext; try { Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); if (!rpcTimeout.isZero()) { callContext = callContext.withTimeout(rpcTimeout); } externalFuture.setAttemptFuture(new NonCancellableFuture<ResponseT>()); if (externalFuture.isDone()) { return null; } callContext .getTracer() .attemptStarted(externalFuture.getAttemptSettings().getOverallAttemptCount()); ApiFuture<ResponseT> internalFuture = callable.futureCall(request, callContext); externalFuture.setAttemptFuture(internalFuture); } catch (Throwable e) { externalFuture.setAttemptFuture(ApiFutures.<ResponseT>immediateFailedFuture(e)); } return null; } }
if (externalFuture.isDone()) { return null;
if (externalFuture.isDone()) { return null;
} while (exception != null && checks < maxRetries + 1); assertTrue(future.isDone()); assertFutureSuccess(future); assertEquals(15, future.getAttemptSettings().getAttemptCount());
assertTrue(future.isDone()); assertNotNull(cancellationException);
while (!future.isDone()) { ApiFuture<String> attemptResult = future.peekAttemptResult(); if (attemptResult != null) {
void assertFutureSuccess(RetryingFuture<String> future) throws ExecutionException, InterruptedException, TimeoutException { assertEquals("SUCCESS", future.get(3, TimeUnit.SECONDS)); assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertEquals("SUCCESS", future.peekAttemptResult().get(3, TimeUnit.SECONDS)); assertSame(future.peekAttemptResult(), future.peekAttemptResult()); assertTrue(future.peekAttemptResult().isDone()); assertFalse(future.peekAttemptResult().isCancelled()); assertEquals("SUCCESS", future.getAttemptResult().get(3, TimeUnit.SECONDS)); assertSame(future.getAttemptResult(), future.getAttemptResult()); assertTrue(future.getAttemptResult().isDone()); assertFalse(future.getAttemptResult().isCancelled()); String res = future.get(); ApiFuture<?> gottentAttempt = future.getAttemptResult(); ApiFuture<?> peekedAttempt = future.peekAttemptResult(); // testing completed immutability assertFalse(future.cancel(true)); assertFalse(future.cancel(false)); assertSame(gottentAttempt, future.getAttemptResult()); assertSame(peekedAttempt, future.peekAttemptResult()); assertSame(res, future.get()); assertTrue(future.isDone()); assertFalse(future.isCancelled()); }