Example usage for com.google.common.util.concurrent Futures catching

List of usage examples for com.google.common.util.concurrent Futures catching

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Futures catching.

Prototype

@GwtIncompatible("AVAILABLE but requires exceptionType to be Throwable.class")
@CheckReturnValue
public static <V, X extends Throwable> ListenableFuture<V> catching(ListenableFuture<? extends V> input,
        Class<X> exceptionType, Function<? super X, ? extends V> fallback, Executor executor) 

Source Link

Document

Returns a Future whose result is taken from the given primary input or, if the primary input fails with the given exceptionType , from the result provided by the fallback .

Usage

From source file:com.salesforce.grpc.contrib.FutureChain.java

/**
 * @see Futures#catching(ListenableFuture, Class, Function, Executor)
 *///from   w  ww .  j  a v  a2 s . c  om
public <E extends Throwable> FutureChain<T> catching(Class<E> exceptionType,
        Function<? super E, ? extends T> fallback) {
    return new FutureChain<>(Futures.catching(future, exceptionType, fallback, executor), executor);
}

From source file:com.facebook.buck.core.build.engine.cache.manager.ManifestRuleKeyServiceImpl.java

@Override
public ListenableFuture<CacheResult> fetchManifest(final RuleKey manifestKey,
        final LazyPath downloadedManifest) {
    String key = toManifestServiceKey(manifestKey);
    final ListenableFuture<Manifest> future = manifestService.fetchManifest(key);
    final ListenableFuture<CacheResult> cacheResultFuture = Futures.transform(future,
            (manifest) -> writeManifestToFile(manifest, downloadedManifest), MoreExecutors.directExecutor());
    return Futures.catching(cacheResultFuture, IOException.class, (exception) -> {
        String msg = String.format("Failed to fetch manifest with error [%s].", exception);
        LOG.error(exception, msg);/*  w ww .  ja  va  2  s .  c  o  m*/
        return CacheResult.error(MANIFEST_SERVICE_SOURCE, ArtifactCacheMode.unknown, msg);
    }, MoreExecutors.directExecutor());
}