List of usage examples for com.google.common.util.concurrent Futures immediateFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFuture(@Nullable V value)
From source file:co.cask.cdap.internal.pipeline.SynchronousPipeline.java
/** * Executes a pipeline in synchronous mode. * <p>//from w w w .ja va2s . c om * Waits for the results of previous to be available to move to next * stage of processing. * </p> * * @param o argument to run the pipeline. */ @SuppressWarnings("unchecked") @Override public ListenableFuture<T> execute(Object o) { Context ctx = new StageContext(o); try { for (Stage stage : getStages()) { stage.process(ctx); // Output of previous stage is input to next stage ctx = new StageContext(ctx.getDownStream()); } return Futures.immediateFuture((T) ctx.getUpStream()); } catch (Throwable th) { return Futures.immediateFailedFuture(th); } finally { Stage finalStage = getFinalStage(); if (finalStage != null) { try { finalStage.process(ctx); } catch (Throwable t) { LOG.warn("Exception thrown when executing final stage {}", finalStage, t); } } } }
From source file:com.facebook.buck.distributed.testutil.DummyArtifactCacheByBuildRule.java
@Override public ListenableFuture<BuildRule> uploadFromLocal(BuildRule rule) { if (localRules.contains(rule)) { remoteRules.add(rule);/*ww w . ja v a 2 s . c o m*/ } ListenableFuture<BuildRule> future = Futures.immediateFuture(rule); uploadFutures.add(future); return future; }
From source file:org.opendaylight.mdsal.dom.broker.TransactionChainWriteTransaction.java
@Override public boolean cancel() { txChain.closeWriteTransaction(Futures.immediateFuture(null)); return delegateTx.cancel(); }
From source file:io.crate.operation.join.FetchedRowsIterable.java
@Override public ListenableFuture<Void> fetchPage(PageInfo pageInfo) throws NoSuchElementException { this.pageInfo(pageInfo); return Futures.immediateFuture(null); }
From source file:com.facebook.buck.parser.cache.impl.FakeManifestService.java
/** Fetch the current value of the Manifest. An empty list is returned if no value is present. */ @Override/*from ww w .j a v a 2 s. co m*/ public ListenableFuture<Manifest> fetchManifest(String manifestKey) { Manifest manifest = new Manifest(); manifest.setKey(manifestKey); List<ByteBuffer> storedValues = fingerprints.get(manifestKey); if (storedValues == null) { storedValues = ImmutableList.of(); } manifest.setValues(storedValues); return Futures.immediateFuture(manifest); }
From source file:com.skcraft.plume.common.util.concurrent.DeferredImpl.java
@Override public Deferred<Void> then(Callback<I> task, ListeningExecutorService executor) { return new DeferredImpl<>(Futures.transform(future, (AsyncFunction<I, Void>) input -> { task.handle(input);//from w w w.ja v a 2 s . c o m return Futures.immediateFuture(null); }, executor), defaultExecutor); }
From source file:io.v.v23.V23TestUtil.java
/** * Asserts that the given future is executed on the provided thread. * <p>//ww w . j a va2 s . c o m * Note that this check is inherently racey: if the future has already completed, there is * no way to check on which thread it got executed. Therefore, this method should be executed * as close possible to the future's creation, to reduce the chance of the race happening. * Additionally, the future could be created with an executor that delays execution for a time * period that sufficient to all but prohibit races (e.g., 100ms). */ public static <T> void assertRunsOnThread(ListenableFuture<T> future, final Thread thread) { try { assertThat(future.isDone()).isFalse(); Futures.transform(future, new AsyncFunction<T, Void>() { @Override public ListenableFuture<Void> apply(T input) throws Exception { assertThat(Thread.currentThread()).isEqualTo(thread); return Futures.immediateFuture(null); } }).get(); } catch (Exception e) { Truth.assertWithMessage("error asserting executor").that(e.getMessage()).isEmpty(); } }
From source file:com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener.java
public ListenableFuture<Void> actionPerformedAsync(NodeActionEvent e) { try {// www . ja va 2 s . c o m actionPerformed(e); return Futures.immediateFuture(null); } catch (AzureCmdException ex) { return Futures.immediateFailedFuture(ex); } }
From source file:com.facebook.presto.execution.QueryQueue.java
QueryQueue(Executor queryExecutor, int maxQueuedQueries, int maxConcurrentQueries) { requireNonNull(queryExecutor, "queryExecutor is null"); checkArgument(maxQueuedQueries > 0, "maxQueuedQueries must be greater than zero"); checkArgument(maxConcurrentQueries > 0, "maxConcurrentQueries must be greater than zero"); this.queuePermits = new AtomicInteger(maxQueuedQueries + maxConcurrentQueries); this.asyncSemaphore = new AsyncSemaphore<>(maxConcurrentQueries, queryExecutor, queueEntry -> { QueuedExecution queuedExecution = queueEntry.dequeue(); if (queuedExecution != null) { queuedExecution.start();// ww w. j av a 2 s . c o m return queuedExecution.getCompletionFuture(); } return Futures.immediateFuture(null); }); }
From source file:com.google.gapid.models.ConstantSets.java
public ListenableFuture<Service.ConstantSet> loadConstants(Service.StateTreeNode node) { if (!node.hasConstants()) { return Futures.immediateFuture(null); }/*ww w . j a v a 2 s. c o m*/ return loadConstants(node.getConstants()); }