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

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

Introduction

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

Prototype

@CheckReturnValue
public static <V> ListenableFuture<V> immediateFuture(@Nullable V value) 

Source Link

Document

Creates a ListenableFuture which has its value set immediately upon construction.

Usage

From source file:com.google.devtools.kythe.platform.shared.FileDataCache.java

@Override
public Future<byte[]> startLookup(String path, String digest) {
    byte[] content = fileContents.get(digest);
    return content != null ? Futures.immediateFuture(content)
            : Futures.<byte[]>immediateFailedFuture(
                    new RuntimeException("Cache does not contain file for digest: " + digest));
}

From source file:google.registry.testing.ForwardingURLFetchService.java

@Override
public Future<HTTPResponse> fetchAsync(HTTPRequest request) {
    try {/* w  w w.  j  a v  a 2  s  .co m*/
        return Futures.immediateFuture(fetch(request));
    } catch (Exception e) {
        return Futures.immediateFailedFuture(e);
    }
}

From source file:net.javacrumbs.futureconverter.common.test.guava.GuavaOriginalFutureTestHelper.java

@Override
public ListenableFuture<String> createFinishedFuture() {
    return Futures.immediateFuture(AbstractConverterTest.VALUE);
}

From source file:org.thingsboard.rule.engine.util.EntitiesTenantIdAsyncLoader.java

private static <T extends HasTenantId> ListenableFuture<TenantId> getTenantAsync(ListenableFuture<T> future) {
    return Futures.transformAsync(future, in -> {
        return in != null ? Futures.immediateFuture(in.getTenantId()) : Futures.immediateFuture(null);
    });/*from  www .ja va  2 s .  c  o m*/
}

From source file:com.android.camera.one.v2.commands.ResettingRunnableCameraCommand.java

public ResettingRunnableCameraCommand(CameraCommandExecutor executor, CameraCommand command) {
    mExecutor = executor;/*  w  w  w .  ja v  a2s.  c om*/
    mCommand = command;
    mLock = new Object();
    mInProgressCommand = Futures.immediateFuture(new Object());
}

From source file:com.spotify.asyncdatastoreclient.example.ExampleAsync.java

private static ListenableFuture<MutationResult> addDataInTransaction(final Datastore datastore) {
    final ListenableFuture<TransactionResult> txn = datastore.transactionAsync();

    final KeyQuery get = QueryBuilder.query("employee", 2345678L);

    return Futures.transform(datastore.executeAsync(get, txn), (QueryResult result) -> {
        if (result.getEntity() == null) {
            datastore.rollbackAsync(txn); // fire and forget
            return Futures.immediateFuture(MutationResult.build());
        }//from   w  w w  . j a va2 s.com

        final Insert insert = QueryBuilder.insert("employee", 2345678L).value("fullname", "Fred Blinge")
                .value("inserted", new Date()).value("age", 40);
        return datastore.executeAsync(insert);
    });
}

From source file:net.oneandone.troilus.SimpleResultList.java

public static ResultListPublisher<Record> newResultListPublisher(long elements, int fetchDelayMillis) {
    return new ResultListPublisher<Record>(
            Futures.immediateFuture(new SimpleResultList(elements, fetchDelayMillis)));
}

From source file:com.facebook.swift.service.async.DelayedMapAsyncHandler.java

@Override
public ListenableFuture<List<String>> getMultipleValues(long timeout, TimeUnit unit, List<String> keys)
        throws TException {
    return Futures.immediateFuture(innerHandler.getMultipleValues(timeout, unit, keys));
}

From source file:com.facebook.buck.core.build.distributed.synchronization.impl.NoOpRemoteBuildRuleCompletionWaiter.java

@Override
public ListenableFuture<Boolean> waitForMostBuildRulesToFinishRemotely() {
    return Futures.immediateFuture(true);
}

From source file:com.sk89q.guavabackport.cache.CacheLoader.java

@GwtIncompatible("Futures")
public ListenableFuture<V> reload(final K key, final V oldValue) throws Exception {
    Preconditions.checkNotNull((Object) key);
    Preconditions.checkNotNull((Object) oldValue);
    return (ListenableFuture<V>) Futures.immediateFuture(this.load(key));
}