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.skcraft.plume.common.util.concurrent.DeferredImpl.java

@Override
public <O> Deferred<O> filter(Filter<I, O> function, ListeningExecutorService executor) {
    return new DeferredImpl<O>(
            Futures.transform(future,/*from w  ww .ja  va 2  s  . co  m*/
                    (AsyncFunction<I, O>) input -> Futures.immediateFuture(function.apply(input)), executor),
            defaultExecutor);
}

From source file:com.google.pubsub.clients.experimental.CPSSubscriberTask.java

@Override
public ListenableFuture<RunResult> doRun() {
    synchronized (subscriber) {
        if (subscriber.isRunning()) {
            return Futures.immediateFuture(RunResult.empty());
        }//w w  w. j a  va  2  s .co  m
        try {
            subscriber.startAsync().awaitRunning();
        } catch (Exception e) {
            log.error("Fatal error from subscriber.", e);
            return Futures.immediateFailedFuture(e);
        }
        return Futures.immediateFuture(RunResult.empty());
    }
}

From source file:org.apache.apex.malhar.lib.state.managed.ManagedTimeStateImpl.java

@Override
public Future<Slice> getAsync(long bucketId, long time, Slice key) {
    long timeBucket = timeBucketAssigner.getTimeBucket(time);
    if (timeBucket == -1) {
        //time is expired so no point in looking further.
        return Futures.immediateFuture(BucketedState.EXPIRED);
    }/*from  w w  w . j  a  va  2s. c o  m*/
    return getValueFromBucketAsync(bucketId, timeBucket, key);
}

From source file:org.thingsboard.server.service.script.AbstractNashornJsInvokeService.java

@Override
protected ListenableFuture<UUID> doEval(UUID scriptId, String functionName, String jsScript) {
    try {//from  w  w  w  . j a  va  2 s.c  o m
        if (useJsSandbox()) {
            sandbox.eval(jsScript);
        } else {
            engine.eval(jsScript);
        }
        scriptIdToNameMap.put(scriptId, functionName);
    } catch (Exception e) {
        log.warn("Failed to compile JS script: {}", e.getMessage(), e);
        return Futures.immediateFailedFuture(e);
    }
    return Futures.immediateFuture(scriptId);
}

From source file:es.udc.pfc.gameroom.GameComponent.java

private final ListenableFuture<String> getUniqueRoomName() {
    final IQ unique = new IQ(IQ.Type.get);
    unique.setFrom(getJID());// w  ww.jav  a 2 s.com
    unique.setTo(JID.jid(getMUCServiceName()));
    unique.addExtension("unique", XMPPNamespaces.MUC_UNIQUE);

    return Futures.transform(sendIQ(unique), new AsyncFunction<IQ, String>() {
        @Override
        public ListenableFuture<String> apply(IQ input) throws Exception {
            final XMLElement unique = input.getExtension("unique", XMPPNamespaces.MUC_UNIQUE);
            if (unique == null)
                throw new Exception("No unique received");

            return Futures.immediateFuture(unique.getText());
        }
    });
}

From source file:io.airlift.drift.client.MockMethodInvoker.java

@Override
public synchronized ListenableFuture<?> delay(Duration duration) {
    delays.add(duration);/* w ww. ja v  a  2s.c  om*/
    ticker.increment(duration.toMillis(), MILLISECONDS);
    return Futures.immediateFuture(null);
}

From source file:org.apache.qpid.server.security.AllowAllAccessControlProviderImpl.java

@StateTransition(currentState = State.UNINITIALIZED, desiredState = State.QUIESCED)
@SuppressWarnings("unused")
private ListenableFuture<Void> startQuiesced() {
    setState(State.QUIESCED);/* w w  w.ja v a 2 s  .c  o  m*/
    return Futures.immediateFuture(null);
}

From source file:org.apache.rave.opensocial.service.impl.DefaultPersonService.java

@Override
public Future<RestfulCollection<Person>> getPeople(Set<UserId> userIds, GroupId groupId,
        CollectionOptions collectionOptions, Set<String> fields, SecurityToken token) throws ProtocolException {

    collectionOptions = manipulateCollectionOptions(collectionOptions, token);
    List<org.apache.rave.model.Person> people = getPeople(userIds, groupId, collectionOptions, token);
    return Futures.immediateFuture(new RestfulCollection<Person>(convertPeople(people, fields)));
}

From source file:com.facebook.buck.util.network.AbstractBatchingLogger.java

private ListenableFuture<Void> sendBatch() {
    ImmutableList<BatchEntry> toSend = batch.build();
    batch = ImmutableList.builder();/*  ww  w .  jav  a 2 s.  c  o m*/
    currentBatchSize = 0;
    if (toSend.isEmpty()) {
        return Futures.immediateFuture(null);
    } else {
        return logMultiple(toSend);
    }
}

From source file:org.thingsboard.server.dao.util.BufferedRateLimiter.java

@Override
public ListenableFuture<Void> acquireAsync() {
    totalRequested.incrementAndGet();/*from w w  w  .j  a  v  a 2  s  .  c om*/
    if (queue.isEmpty()) {
        if (permits.incrementAndGet() <= permitsLimit) {
            if (permits.get() > maxGrantedPermissions.get()) {
                maxGrantedPermissions.set(permits.get());
            }
            totalGranted.incrementAndGet();
            return Futures.immediateFuture(null);
        }
        permits.decrementAndGet();
    }

    return putInQueue();
}