类com.google.common.util.concurrent.AsyncCallable源码实例Demo

下面列出了怎么用com.google.common.util.concurrent.AsyncCallable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: bazel-buildfarm   文件: Retrier.java
/**
 * Executes an {@link AsyncCallable}, retrying execution in case of failure with the given
 * backoff.
 */
public <T> ListenableFuture<T> executeAsync(AsyncCallable<T> call, Backoff backoff) {
  try {
    return Futures.catchingAsync(
        call.call(),
        Exception.class,
        t -> onExecuteAsyncFailure(t, call, backoff),
        MoreExecutors.directExecutor());
  } catch (Exception e) {
    return onExecuteAsyncFailure(e, call, backoff);
  }
}
 
源代码2 项目: bazel-buildfarm   文件: Retrier.java
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);
  }
}
 
源代码3 项目: bazel   文件: Retrier.java
/**
 * Executes an {@link AsyncCallable}, retrying execution in case of failure with the given
 * backoff.
 */
public <T> ListenableFuture<T> executeAsync(AsyncCallable<T> call, Backoff backoff) {
  try {
    return Futures.catchingAsync(
        call.call(),
        Exception.class,
        t -> onExecuteAsyncFailure(t, call, backoff),
        MoreExecutors.directExecutor());
  } catch (Exception e) {
    return onExecuteAsyncFailure(e, call, backoff);
  }
}
 
源代码4 项目: bazel   文件: Retrier.java
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);
  }
}
 
源代码5 项目: tutorials   文件: JavaAsync.java
/**
 * Finds factorial of a number using Guava's Futures.submitAsync()
 * @param number
 * @return
 */
@Loggable
public static ListenableFuture<Long> factorialUsingGuavaFutures(int number) {
    ListeningExecutorService service = MoreExecutors.listeningDecorator(threadpool);
    AsyncCallable<Long> asyncCallable = Callables.asAsyncCallable(new Callable<Long>() {
        public Long call() {
            return factorial(number);
        }
    }, service);
    return Futures.submitAsync(asyncCallable, service);
}
 
源代码6 项目: bazel-buildfarm   文件: Retrier.java
/** Executes an {@link AsyncCallable}, retrying execution in case of failure. */
public <T> ListenableFuture<T> executeAsync(AsyncCallable<T> call) {
  return executeAsync(call, newBackoff());
}
 
源代码7 项目: bazel   文件: Retrier.java
/** Executes an {@link AsyncCallable}, retrying execution in case of failure. */
public <T> ListenableFuture<T> executeAsync(AsyncCallable<T> call) {
  return executeAsync(call, newBackoff());
}
 
 同包方法