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

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

Introduction

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

Prototype

@Deprecated
@CheckReturnValue
public static <V> ListenableFuture<V> withFallback(ListenableFuture<? extends V> input,
        FutureFallback<? extends V> fallback) 

Source Link

Document

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

Usage

From source file:com.spotify.helios.testing.HeliosSoloDeployment.java

private <T> T getOrNull(final ListenableFuture<T> future) throws ExecutionException, InterruptedException {
    return Futures.withFallback(future, new FutureFallback<T>() {
        @Override/*w w w  . j av a 2s.c o  m*/
        public ListenableFuture<T> create(@NotNull final Throwable t) throws Exception {
            return Futures.immediateFuture(null);
        }
    }).get();
}

From source file:org.rhq.enterprise.server.cloud.StorageNodeManagerBean.java

private ListenableFuture<StorageNodeLoadComposite> wrapFuture(ListenableFuture<StorageNodeLoadComposite> future,
        final StorageNodeLoadComposite value, final String msg) {
    return Futures.withFallback(future, new FutureFallback<StorageNodeLoadComposite>() {
        @Override/* w  w w  .  j  a  va2  s . c o  m*/
        public ListenableFuture<StorageNodeLoadComposite> create(Throwable t) throws Exception {
            if (log.isDebugEnabled()) {
                log.debug(msg, t);
            } else {
                log.info(msg + ": " + t.getMessage());
            }
            return Futures.immediateFuture(value);
        }
    });
}

From source file:com.spotify.helios.system.SystemTestBase.java

protected <T> T getOrNull(final ListenableFuture<T> future) throws ExecutionException, InterruptedException {
    return Futures.withFallback(future, new FutureFallback<T>() {
        @Override//ww  w.ja v a  2s .c om
        public ListenableFuture<T> create(@NotNull final Throwable t) throws Exception {
            return Futures.immediateFuture(null);
        }
    }).get();
}