Java Code Examples for com.google.common.util.concurrent.Futures#scheduleAsync()

The following examples show how to use com.google.common.util.concurrent.Futures#scheduleAsync() . 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: Retrier.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private <T> ListenableFuture<T> onExecuteAsyncFailure(
    Exception t, AsyncCallable<T> call, Backoff backoff) {
  long waitMillis = backoff.nextDelayMillis();
  if (waitMillis >= 0 && isRetriable.apply(Status.fromThrowable(t))) {
    try {
      return Futures.scheduleAsync(
          () -> executeAsync(call, backoff), waitMillis, TimeUnit.MILLISECONDS, retryScheduler);
    } catch (RejectedExecutionException e) {
      // May be thrown by .scheduleAsync(...) if i.e. the executor is shutdown.
      return Futures.immediateFailedFuture(new IOException(e));
    }
  } else {
    return Futures.immediateFailedFuture(t);
  }
}
 
Example 2
Source File: Retrier.java    From bazel with Apache License 2.0 5 votes vote down vote up
private <T> ListenableFuture<T> onExecuteAsyncFailure(
    Exception t, AsyncCallable<T> call, Backoff backoff) {
  long waitMillis = backoff.nextDelayMillis();
  if (waitMillis >= 0 && isRetriable(t)) {
    try {
      return Futures.scheduleAsync(
          () -> executeAsync(call, backoff), waitMillis, TimeUnit.MILLISECONDS, retryService);
    } catch (RejectedExecutionException e) {
      // May be thrown by .scheduleAsync(...) if i.e. the executor is shutdown.
      return Futures.immediateFailedFuture(new IOException(e));
    }
  } else {
    return Futures.immediateFailedFuture(t);
  }
}
 
Example 3
Source File: StalePassiveConnectionServiceTest.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
private Answer<Object> delayedEchoResponse(int delay, TimeUnit timeUnit) {
    return (mock) -> Futures.scheduleAsync(() -> Futures.immediateFuture(null),
            delay, timeUnit, scheduledExecutorService);
}
 
Example 4
Source File: StalePassiveConnectionServiceTest.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
private Answer<Object> delayedEchoFailedResponse(int delay, TimeUnit timeUnit) {
    return (mock) -> Futures.scheduleAsync(() -> Futures.immediateFailedFuture(new RuntimeException("Echo failed")),
            delay, timeUnit, scheduledExecutorService);
}