List of usage examples for com.google.common.util.concurrent Futures immediateCancelledFuture
@GwtIncompatible("TODO") @CheckReturnValue public static <V> ListenableFuture<V> immediateCancelledFuture()
From source file:com.google.errorprone.bugpatterns.testdata.FutureReturnValueIgnoredPositiveCases.java
public void testFutureGenerics() { // BUG: Diagnostic contains: Future must be checked returnFutureType(Futures.immediateCancelledFuture()); }
From source file:dagger.producers.internal.DependencyMethodProducer.java
@Override public final ListenableFuture<T> get() { synchronized (futures) { if (cancelled) { return Futures.immediateCancelledFuture(); }/*w ww .j a v a2 s.c o m*/ final ListenableFuture<T> future = callDependencyMethod(); if (!future.isDone() && futures.add(future)) { future.addListener(new Runnable() { @Override public void run() { synchronized (futures) { futures.remove(future); } } }, directExecutor()); } return future; } }
From source file:com.facebook.buck.parser.ConvertingPipeline.java
@Override public ListenableFuture<ImmutableSet<T>> getAllNodesJob(final Cell cell, final Path buildFile) throws BuildTargetException { // TODO(csarbora): this hits the chained pipeline before hitting the cache ListenableFuture<List<T>> allNodesListJob = Futures.transformAsync(getItemsToConvert(cell, buildFile), allToConvert -> {/*from www. java2 s. co m*/ if (shuttingDown()) { return Futures.immediateCancelledFuture(); } ImmutableList.Builder<ListenableFuture<T>> allNodeJobs = ImmutableList.builder(); for (final F from : allToConvert) { if (isValid(from)) { final BuildTarget target = getBuildTarget(cell.getRoot(), buildFile, from); allNodeJobs.add(cache.getJobWithCacheLookup(cell, target, () -> { if (shuttingDown()) { return Futures.immediateCancelledFuture(); } return dispatchComputeNode(cell, target, from); })); } } return Futures.allAsList(allNodeJobs.build()); }, executorService); return Futures.transform(allNodesListJob, (Function<List<T>, ImmutableSet<T>>) ImmutableSet::copyOf, executorService); }
From source file:com.facebook.buck.parser.BuildFileRawNodeParsePipeline.java
@Override public ListenableFuture<BuildFileManifest> getAllNodesJob(Cell cell, Path buildFile) throws BuildTargetException { if (shuttingDown.get()) { return Futures.immediateCancelledFuture(); }//from w w w . j a va 2s. c o m return cache.getJobWithCacheLookup(cell, buildFile, () -> { if (shuttingDown.get()) { return Futures.immediateCancelledFuture(); } Path pathToCheck = cell.getRoot().relativize(buildFile.getParent()); if (cell.getFilesystem().isIgnored(pathToCheck)) { throw new HumanReadableException( "Content of '%s' cannot be built because it is defined in an ignored directory.", pathToCheck); } return projectBuildFileParserPool.getBuildFileManifest(eventBus, cell, watchman, buildFile, executorService); }, eventBus); }
From source file:com.facebook.buck.parser.RawNodeParsePipeline.java
@Override public ListenableFuture<ImmutableSet<Map<String, Object>>> getAllNodesJob(final Cell cell, final Path buildFile) throws BuildTargetException { if (shuttingDown()) { return Futures.immediateCancelledFuture(); }//from w w w. j a v a 2 s .c o m return cache.getJobWithCacheLookup(cell, buildFile, () -> { if (shuttingDown()) { return Futures.immediateCancelledFuture(); } return projectBuildFileParserPool.getAllRulesAndMetaRules(cell, buildFile, executorService); }); }
From source file:com.google.cloud.pubsub.v1.PollingSubscriberConnection.java
private ListenableFuture<PullResponse> pullMessages(final Duration backoff) { if (!isAlive()) { return Futures.immediateCancelledFuture(); }/*from w w w .j a v a2s.c om*/ ListenableFuture<PullResponse> pullResult = stub .pull(PullRequest.newBuilder().setSubscription(subscription.getName()) .setMaxMessages(maxDesiredPulledMessages).setReturnImmediately(false).build()); Futures.addCallback(pullResult, new FutureCallback<PullResponse>() { @Override public void onSuccess(PullResponse pullResponse) { if (pullResponse.getReceivedMessagesCount() == 0) { // No messages in response, possibly caught up in backlog, we backoff to avoid // slamming the server. pollingExecutor.schedule(new Runnable() { @Override public void run() { Duration newBackoff = backoff.multipliedBy(2); if (newBackoff.compareTo(MAX_BACKOFF) > 0) { newBackoff = MAX_BACKOFF; } pullMessages(newBackoff); } }, backoff.toMillis(), TimeUnit.MILLISECONDS); return; } messageDispatcher.processReceivedMessages(pullResponse.getReceivedMessagesList(), new Runnable() { @Override public void run() { pullMessages(INITIAL_BACKOFF); } }); } @Override public void onFailure(Throwable cause) { if (!isAlive()) { // we don't care about subscription failures when we're no longer running. logger.log(Level.FINE, "pull failure after service no longer running", cause); return; } if (StatusUtil.isRetryable(cause)) { logger.log(Level.WARNING, "Failed to pull messages (recoverable): ", cause); pollingExecutor.schedule(new Runnable() { @Override public void run() { Duration newBackoff = backoff.multipliedBy(2); if (newBackoff.compareTo(MAX_BACKOFF) > 0) { newBackoff = MAX_BACKOFF; } pullMessages(newBackoff); } }, backoff.toMillis(), TimeUnit.MILLISECONDS); } else { messageDispatcher.stop(); notifyFailed(cause); } } }, pollingExecutor); return pullResult; }
From source file:com.facebook.buck.parser.ConvertingPipeline.java
private ListenableFuture<T> dispatchComputeNode(Cell cell, BuildTarget buildTarget, F from) throws BuildTargetException { // TODO(csarbora): would be nice to have the first half of this function pulled up into base if (shuttingDown()) { return Futures.immediateCancelledFuture(); }/*from w w w.j a v a 2s.c o m*/ if (!isValid(from)) { throw new NoSuchBuildTargetException(buildTarget); } Path pathToCheck = buildTarget.getBasePath(); if (cell.getFilesystem().isIgnored(pathToCheck)) { throw new HumanReadableException( "Content of '%s' cannot be built because" + " it is defined in an ignored directory.", pathToCheck); } return Futures.immediateFuture(computeNode(cell, buildTarget, from)); }
From source file:org.opendaylight.sxp.controller.core.DatastoreAccess.java
/** * @param path InstanceIdentifier path specifying data * @param logicalDatastoreType Type of datastore where operation will be held * @param <T> Any type extending DataObject * @return ListenableFuture callback of operation *///ww w.j a va 2s . co m public synchronized <T extends DataObject> ListenableFuture<Void> delete(InstanceIdentifier<T> path, LogicalDatastoreType logicalDatastoreType) { if (!checkParams(path, logicalDatastoreType)) { return Futures.immediateCancelledFuture(); } if (LOG.isDebugEnabled()) { LOG.debug("Delete {} {}", logicalDatastoreType, path.getTargetType()); } synchronized (dataBroker) { WriteTransaction transaction = bindingTransactionChain.newWriteOnlyTransaction(); transaction.delete(logicalDatastoreType, path); return transaction.submit(); } }
From source file:org.opendaylight.sxp.controller.core.DatastoreAccess.java
/** * @param path InstanceIdentifier path specifying data * @param data Data that will be used in operation * @param logicalDatastoreType Type of datastore where operation will be held * @param <T> Any type extending DataObject * @return CheckedFuture callback of operation *///w w w . jav a 2 s .co m public synchronized <T extends DataObject> CheckedFuture<Void, TransactionCommitFailedException> merge( InstanceIdentifier<T> path, T data, LogicalDatastoreType logicalDatastoreType) { if (!checkParams(path, logicalDatastoreType)) { return Futures.makeChecked(Futures.immediateCancelledFuture(), input -> ACCESS_CLOSED_ON_RW); } Preconditions.checkNotNull(data); if (LOG.isDebugEnabled()) { LOG.debug("Merge {} {}", logicalDatastoreType, path.getTargetType()); } WriteTransaction transaction = bindingTransactionChain.newWriteOnlyTransaction(); transaction.merge(logicalDatastoreType, path, data); return transaction.submit(); }
From source file:io.v.v23.VFutures.java
/** * Returns a new {@link ListenableFuture} that runs on an {@link Executor} specified in the * given {@code context}. If the future completes but the given {@code context} has been * canceled, the returned future is canceled as well. *///from ww w . j a v a 2s. c om public static <T> ListenableFuture<T> withUserLandChecks(final VContext context, final ListenableFuture<T> future) { Executor executor = V.getExecutor(context); if (executor == null) { throw new RuntimeException("NULL executor in context: did you derive this context " + "from the context returned by V.init()?"); } return Futures.transform(future, new AsyncFunction<T, T>() { @Override public ListenableFuture<T> apply(T input) throws Exception { if (context.isCanceled()) { return Futures.immediateCancelledFuture(); } return Futures.immediateFuture(input); } }, executor); }