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:org.opendaylight.openflowplugin.impl.statistics.StatisticsContextImpl.java

public StatisticsContextImpl(@CheckForNull final DeviceContext deviceContext) {
    this.deviceContext = Preconditions.checkNotNull(deviceContext);
    devState = Preconditions.checkNotNull(deviceContext.getDeviceState());
    emptyFuture = Futures.immediateFuture(new Boolean(false));
    statisticsGatheringService = new StatisticsGatheringService(this, deviceContext);
    statisticsGatheringOnTheFlyService = new StatisticsGatheringOnTheFlyService(this, deviceContext);

    final List<MultipartType> statListForCollecting = new ArrayList<>();
    if (devState.isTableStatisticsAvailable()) {
        statListForCollecting.add(MultipartType.OFPMPTABLE);
    }//w  w  w. j  a  v a 2s. c o  m
    if (devState.isFlowStatisticsAvailable()) {
        statListForCollecting.add(MultipartType.OFPMPFLOW);
    }
    if (devState.isGroupAvailable()) {
        statListForCollecting.add(MultipartType.OFPMPGROUPDESC);
        statListForCollecting.add(MultipartType.OFPMPGROUP);
    }
    if (devState.isMetersAvailable()) {
        statListForCollecting.add(MultipartType.OFPMPMETERCONFIG);
        statListForCollecting.add(MultipartType.OFPMPMETER);
    }
    if (devState.isPortStatisticsAvailable()) {
        statListForCollecting.add(MultipartType.OFPMPPORTSTATS);
    }
    if (devState.isQueueStatisticsAvailable()) {
        statListForCollecting.add(MultipartType.OFPMPQUEUE);
    }
    collectingStatType = ImmutableList.<MultipartType>copyOf(statListForCollecting);
    itemLifeCycleListener = new ItemLifecycleListenerImpl(deviceContext);
}

From source file:producerstest.SimpleProducerModule.java

@Produces
@Qual(10)//from  ww w . jav  a  2s.co m
static ListenableFuture<String> futureStrWithArgs(@SuppressWarnings("unused") int i,
        @SuppressWarnings("unused") Produced<Double> b, @SuppressWarnings("unused") Producer<Object> c,
        @SuppressWarnings("unused") Provider<Boolean> d) {
    return Futures.immediateFuture("future str with args");
}

From source file:com.facebook.presto.operator.PartitionedLookupSourceFactory.java

@Override
public synchronized ListenableFuture<LookupSource> createLookupSource() {
    if (lookupSourceSupplier != null) {
        return Futures.immediateFuture(lookupSourceSupplier.getLookupSource());
    }//from w w w.  ja  v a 2 s  . co m

    SettableFuture<LookupSource> lookupSourceFuture = SettableFuture.create();
    lookupSourceFutures.add(lookupSourceFuture);
    return lookupSourceFuture;
}

From source file:com.facebook.buck.distributed.MultiSourceContentsProvider.java

private ListenableFuture<Boolean> postInlineMaterializationHelper(boolean success,
        BuildJobStateFileHashEntry entry, Path targetAbsPath) {
    if (success) {
        LOG.info("Materialized source file using Inline Data: [%s]", targetAbsPath);
        return Futures.immediateFuture(true);
    }/*from   w w w.j  a  v  a 2s. c  om*/

    ListenableFuture<Boolean> localFsFuture;
    if (localFsProvider.isPresent()) {
        localFsFuture = localFsProvider.get().materializeFileContentsAsync(entry, targetAbsPath);
    } else {
        localFsFuture = Futures.immediateFuture(false);
    }

    return Futures.transformAsync(localFsFuture,
            (localFsSuccess) -> postLocalFsMaterializationHelper(localFsSuccess, entry, targetAbsPath),
            executorService);
}

From source file:com.google.gapid.server.Client.java

public ListenableFuture<ServerInfo> getSeverInfo() {
    LOG.log(FINE, "RPC->getServerInfo()");
    return Futures.transformAsync(client.getServerInfo(GetServerInfoRequest.newBuilder().build()),
            in -> Futures.immediateFuture(throwIfError(in.getInfo(), in.getError())));
}

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

@Override
protected ListenableFuture<Object> doInvokeFunction(UUID scriptId, String functionName, Object[] args) {
    try {//from   w  w  w  .  jav  a  2 s  .c  om
        Object result;
        if (useJsSandbox()) {
            result = sandbox.getSandboxedInvocable().invokeFunction(functionName, args);
        } else {
            result = ((Invocable) engine).invokeFunction(functionName, args);
        }
        return Futures.immediateFuture(result);
    } catch (Exception e) {
        onScriptExecutionError(scriptId);
        return Futures.immediateFailedFuture(e);
    }
}

From source file:org.opendaylight.service.impl.ServiceManager.java

public Future<RpcResult<Void>> testNotificationPublish() {
    NotificationProvider.getInstance().notify(new ReportMessageBuilder().setFailureReason("test111").build());
    return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
}

From source file:org.opendaylight.toaster.impl.KitchenProvider.java

@Override
public Future<RpcResult<Void>> makeBreakfast(MakeBreakfastInput input) {
    ListenableFuture<RpcResult<Void>> makeEggFuture = makeEgg(input);
    ListenableFuture<RpcResult<Void>> makeToastFuture = makeToast(input);
    ListenableFuture<List<RpcResult<Void>>> combinedFutures = Futures
            .allAsList(ImmutableList.of(makeEggFuture, makeToastFuture));
    return Futures.transform(combinedFutures, new AsyncFunction<List<RpcResult<Void>>, RpcResult<Void>>() {
        @Override//  www . j av a2  s .  c  o m
        public ListenableFuture<RpcResult<Void>> apply(List<RpcResult<Void>> input) throws Exception {
            boolean atLeastOneSucceed = false;
            ImmutableList.Builder<RpcError> errorList = ImmutableList.builder();
            for (RpcResult<Void> result : input) {
                if (result.isSuccessful()) {
                    atLeastOneSucceed = true;
                }
                if (result.getErrors() != null) {
                    errorList.addAll(result.getErrors());
                }
            }
            return Futures.immediateFuture(Rpcs.<Void>getRpcResult(atLeastOneSucceed, errorList.build()));
        }
    });
}

From source file:org.apache.qpid.server.security.group.GroupProviderImpl.java

@StateTransition(currentState = { State.UNINITIALIZED, State.QUIESCED,
        State.ERRORED }, desiredState = State.ACTIVE)
private ListenableFuture<Void> activate() {
    setState(State.ACTIVE);
    return Futures.immediateFuture(null);
}

From source file:org.apache.phoenix.query.PhoenixStatsCacheLoader.java

@Override
public ListenableFuture<GuidePostsInfo> reload(final GuidePostsKey key, GuidePostsInfo prevGuidepostInfo) {
    if (statsLoader.needsLoad()) {
        // schedule asynchronous task
        ListenableFutureTask<GuidePostsInfo> task = ListenableFutureTask.create(new Callable<GuidePostsInfo>() {
            public GuidePostsInfo call() {
                try {
                    return statsLoader.loadStats(key, prevGuidepostInfo);
                } catch (Exception e) {
                    logger.warn("Unable to load stats from table: " + key.toString(), e);
                    return prevGuidepostInfo;
                }/*from  w  ww .jav a2 s.c o m*/
            }
        });
        executor.execute(task);
        return task;
    } else {
        return Futures.immediateFuture(prevGuidepostInfo);
    }
}