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.android.camera.one.v2.commands.CameraCommandExecutor.java

/**
 * Executes the given command, returning a Future to indicate its status and
 * allow (interruptible) cancellation.//  w  ww . j av  a 2 s.co m
 */
public Future<?> execute(CameraCommand command) {
    if (mClosed) {
        return Futures.immediateFuture(null);
    }
    synchronized (mLock) {
        if (mExecutor == null) {
            // Create a new executor, if necessary.
            mExecutor = mExecutorProvider.get();
        }
        checkNotNull(mExecutor);
        return mExecutor.submit(new CommandRunnable(command));
    }
}

From source file:io.v.v23.syncbase.nosql.DatabaseImpl.java

@Override
public ListenableFuture<QueryResults> exec(VContext ctx, String query) {
    final ClientRecvStream<List<VdlAny>, Void> stream = client.exec(ctx, getSchemaVersion(), query);
    return Futures.transform(stream.recv(), new AsyncFunction<List<VdlAny>, QueryResults>() {
        @Override//  w w  w .  ja v  a 2  s  . c  o m
        public ListenableFuture<QueryResults> apply(List<VdlAny> columnNames) throws Exception {
            return Futures.immediateFuture((QueryResults) new QueryResultsImpl(columnNames, stream));
        }
    });
}

From source file:org.opendaylight.alto.basic.endpointcostservice.impl.base.BaseECSImplementation.java

public ListenableFuture<RpcResult<QueryOutput>> getECS(QueryInput input) {
    if (checkInput(input) && postCheck(input)) {
        buildEndpointCostServiceOutput(input);
    }/*  w w  w .  j ava  2 s  .  c  o m*/
    return Futures.immediateFuture(ecsOutput);
}

From source file:org.opendaylight.controller.clustering.it.provider.impl.FlappingSingletonService.java

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<Void> closeServiceInstance() {
    LOG.debug("Closing flapping-singleton-service, flapCount: {}", flapCount);

    flapCount.incrementAndGet();/*  w  w w. j av a 2 s  .  c o  m*/
    if (active.get()) {
        // TODO direct registration/close seem to trigger a bug in singleton state transitions,
        // remove  whole executor shenanigans after it's fixed.
        // Needs to be delayed slightly otherwise it's triggered as well.
        EXECUTOR.schedule(() -> {
            LOG.debug("Running re-registration");
            try {
                registration = singletonServiceProvider.registerClusterSingletonService(this);
            } catch (RuntimeException e) {
                LOG.warn("There was a problem re-registering flapping singleton service.", e);
                setInactive();

                final long count = flapCount.get();
                flapCount.compareAndSet(count, -count - 1);
            }

        }, 200, TimeUnit.MILLISECONDS);
    }

    return Futures.immediateFuture(null);
}

From source file:com.proofpoint.event.monitor.test.SerialScheduledExecutorService.java

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> callables) throws InterruptedException {
    ImmutableList.Builder<Future<T>> resultBuilder = ImmutableList.builder();
    for (Callable<T> callable : callables) {
        try {//from www  .  j a v a  2 s . co  m
            resultBuilder.add(Futures.immediateFuture(callable.call()));
        } catch (Exception e) {
            resultBuilder.add(Futures.<T>immediateFailedFuture(e));
        }
    }
    return resultBuilder.build();
}

From source file:org.opendaylight.natapp.impl.NatPacketHandler.java

public Future<RpcResult<java.lang.Void>> natType(NatTypeInput input) {
    type = input.getNatType();//from ww  w .j a  v  a2s.  c o m
    return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
}

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

public ListenableFuture<Path.Any> set(Path.Any path, Service.Value value) {
    LOG.log(FINE, "RPC->set({0}, {1})", new Object[] { path, value });
    return Futures.transformAsync(client.set(SetRequest.newBuilder().setPath(path).setValue(value).build()),
            in -> Futures.immediateFuture(throwIfError(in.getPath(), in.getError())));
}

From source file:org.thingsboard.rule.engine.action.TbClearAlarmNode.java

private ListenableFuture<AlarmResult> clearAlarm(TbContext ctx, TbMsg msg, Alarm alarm) {
    ListenableFuture<JsonNode> asyncDetails = buildAlarmDetails(ctx, msg, alarm.getDetails());
    return Futures.transformAsync(asyncDetails, details -> {
        ListenableFuture<Boolean> clearFuture = ctx.getAlarmService().clearAlarm(ctx.getTenantId(),
                alarm.getId(), details, System.currentTimeMillis());
        return Futures.transformAsync(clearFuture, cleared -> {
            if (cleared && details != null) {
                alarm.setDetails(details);
            }//from  ww  w . j  a v  a2 s. c o  m
            alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK);
            return Futures.immediateFuture(new AlarmResult(false, false, true, alarm));
        });
    }, ctx.getDbCallbackExecutor());
}

From source file:org.apache.hadoop.yarn.util.FSDownload.java

/**
 * Creates the cache loader for the status loading cache. This should be used
 * to create an instance of the status cache that is passed into the
 * FSDownload constructor.//from www.  j a va 2 s.c  o m
 */
public static CacheLoader<Path, Future<FileStatus>> createStatusCacheLoader(final Configuration conf) {
    return new CacheLoader<Path, Future<FileStatus>>() {
        public Future<FileStatus> load(Path path) {
            try {
                FileSystem fs = path.getFileSystem(conf);
                return Futures.immediateFuture(fs.getFileStatus(path));
            } catch (Throwable th) {
                // report failures so it can be memoized
                return Futures.immediateFailedFuture(th);
            }
        }
    };
}

From source file:io.prestosql.operator.index.IndexLookupSourceFactory.java

@Override
public ListenableFuture<LookupSourceProvider> createLookupSourceProvider() {
    checkState(taskContext != null, "taskContext not set");

    IndexLoader indexLoader = indexLoaderSupplier.get();
    indexLoader.setContext(taskContext);
    return Futures.immediateFuture(new StaticLookupSourceProvider(new IndexLookupSource(indexLoader)));
}