List of usage examples for com.google.common.util.concurrent MoreExecutors directExecutor
public static Executor directExecutor()
From source file:org.onosproject.store.service.AsyncConsistentMap.java
/** * Registers the specified listener to be notified whenever the map is updated. * * @param listener listener to notify about map events * @return future that will be completed when the operation finishes *///from ww w .j ava 2s . com default CompletableFuture<Void> addListener(MapEventListener<K, V> listener) { return addListener(listener, MoreExecutors.directExecutor()); }
From source file:com.facebook.buck.rules.modern.builders.RemoteExecutionStrategy.java
private ListenableFuture<Optional<BuildResult>> executeNowThatInputsAreReady(ProjectFilesystem filesystem, BuildStrategyContext strategyContext, BuildTarget buildTarget, Callable<Throwable> tryStart, Digest actionDigest, Iterable<? extends Path> actionOutputs, String ruleName) { AtomicReference<Throwable> cancelled = new AtomicReference<>(null); ListenableFuture<ExecutionResult> executionResult = executionLimiter.schedule(service, () -> { cancelled.set(tryStart.call());//from w ww . j av a2 s . com boolean isCancelled = cancelled.get() != null; if (isCancelled) { RemoteExecutionActionEvent.sendTerminalEvent(eventBus, State.ACTION_CANCELLED, buildTarget, Optional.of(actionDigest)); return Futures.immediateFuture(null); } Scope executingScope = RemoteExecutionActionEvent.sendEvent(eventBus, State.EXECUTING, buildTarget, Optional.of(actionDigest)); return Futures.transform(executionClients.getRemoteExecutionService().execute(actionDigest, ruleName), result -> { executingScope.close(); return result; }, MoreExecutors.directExecutor()); }); return sendFailedEventOnException(Futures.transformAsync(executionResult, result -> { if (cancelled.get() != null) { return Futures.immediateFuture(Optional.of(strategyContext.createCancelledResult(cancelled.get()))); } return handleResultLimiter.schedule(service, () -> handleExecutionResult(filesystem, strategyContext, buildTarget, result, actionDigest, actionOutputs)); }, service), buildTarget, actionDigest); }
From source file:com.google.cloud.bigtable.grpc.v2.BigtableDataGrpcClient.java
private CancellationToken createCancellationToken( final ClientCall<ReadRowsRequest, ReadRowsResponse> readRowsCall) { // If the scanner is closed before we're done streaming, we want to cancel the RPC. CancellationToken cancellationToken = new CancellationToken(); cancellationToken.addListener(new Runnable() { @Override/* www . j av a 2 s . c o m*/ public void run() { readRowsCall.cancel(); } }, MoreExecutors.directExecutor()); return cancellationToken; }
From source file:io.atomix.core.map.AtomicMap.java
/** * Registers the specified listener to be notified whenever the map is updated. * * @param listener listener to notify about map events *//* w ww. java 2 s . c om*/ default void addListener(AtomicMapEventListener<K, V> listener) { addListener(listener, MoreExecutors.directExecutor()); }
From source file:com.orangerhymelabs.helenus.cassandra.document.DocumentService.java
private ListenableFuture<AbstractDocumentRepository> acquireRepositoryFor(String database, String table) { Identifier cacheKey = new Identifier(database, table); AbstractDocumentRepository repo = repoCache.get(cacheKey); if (repo != null) { return Futures.immediateFuture(repo); }/* w w w . java2 s. c om*/ ListenableFuture<Table> futureTable = tables.read(database, table); return Futures.transformAsync(futureTable, new AsyncFunction<Table, AbstractDocumentRepository>() { @Override public ListenableFuture<AbstractDocumentRepository> apply(Table input) throws Exception { AbstractDocumentRepository repo = factory.newInstance(input); repoCache.put(cacheKey, repo); return Futures.immediateFuture(repo); } }, MoreExecutors.directExecutor()); }
From source file:com.facebook.buck.distributed.build_slave.MinionModeRunner.java
private void registerUploadCompletionHandler(BuildResult buildResult) { String fullyQualifiedName = buildResult.getRule().getFullyQualifiedName(); Futures.addCallback(buildResult.getUploadCompleteFuture().orElse(Futures.immediateFuture(null)), new FutureCallback<Void>() { @Override/*w w w. j a v a2s . c o m*/ public void onSuccess(@Nullable Void result) { buildTracker.recordUploadedTarget(fullyQualifiedName); } @Override public void onFailure(Throwable t) { // TODO(alisdair,ruibm,msienkiewicz): We used to have async upload confirmations from // cache which made this codepath (almost) never get triggered - we would crash the // build if it happened. We need to now look at error rate and decide on a retry/crash // policy. Until then, log and progress as if upload was successful. registerFailedUploadHandler(t, buildResult.getRule(), fullyQualifiedName); buildTracker.recordUploadedTarget(fullyQualifiedName); } }, MoreExecutors.directExecutor()); }
From source file:com.facebook.buck.core.build.engine.cache.manager.ManifestRuleKeyManager.java
public ListenableFuture<ManifestFetchResult> performManifestBasedCacheFetch( RuleKeyAndInputs originalRuleKeyAndInputs) { Preconditions.checkArgument(useManifestCaching()); // Explicitly drop the input list from the caller, as holding this in the closure below until // the future eventually runs can potentially consume a lot of memory. RuleKey manifestRuleKey = originalRuleKeyAndInputs.getRuleKey(); originalRuleKeyAndInputs = null;/*from w w w.j av a 2s . com*/ // Fetch the manifest from the cache. return Futures.transformAsync(fetchManifest(manifestRuleKey), (@Nonnull CacheResult manifestCacheResult) -> { ManifestFetchResult.Builder manifestFetchResult = ManifestFetchResult.builder(); manifestFetchResult.setManifestCacheResult(manifestCacheResult); if (!manifestCacheResult.getType().isSuccess()) { return Futures.immediateFuture(manifestFetchResult.build()); } // Re-calculate the rule key and the input list. While we do already have the input list // above in `originalRuleKeyAndInputs`, we intentionally don't pass it in and use it here // to avoid holding on to significant memory until this future runs. RuleKeyAndInputs keyAndInputs = manifestBasedKeySupplier.get() .orElseThrow(IllegalStateException::new); // Load the manifest from disk. ManifestLoadResult loadResult = loadManifest(keyAndInputs.getRuleKey()); if (!loadResult.getManifest().isPresent()) { manifestFetchResult.setManifestLoadError(loadResult.getError().get()); return Futures.immediateFuture(manifestFetchResult.build()); } Manifest manifest = loadResult.getManifest().get(); Preconditions.checkState(manifest.getKey().equals(keyAndInputs.getRuleKey()), "%s: found incorrectly keyed manifest: %s != %s", rule.getBuildTarget(), keyAndInputs.getRuleKey(), manifest.getKey()); manifestFetchResult.setManifestStats(manifest.getStats()); // Lookup the dep file rule key matching the current state of our inputs. Optional<RuleKey> depFileRuleKey = manifest.lookup(fileHashCache, pathResolver, keyAndInputs.getInputs()); if (!depFileRuleKey.isPresent()) { return Futures.immediateFuture(manifestFetchResult.build()); } manifestFetchResult.setDepFileRuleKey(depFileRuleKey.get()); // Fetch the rule outputs from cache using the found dep file rule key. return Futures.transform( buildCacheArtifactFetcher .tryToFetchArtifactFromBuildCacheAndOverlayOnTopOfProjectFilesystem( depFileRuleKey.get(), artifactCache, rule.getProjectFilesystem()), (@Nonnull CacheResult ruleCacheResult) -> { manifestFetchResult.setRuleCacheResult(ruleCacheResult); return manifestFetchResult.build(); }, MoreExecutors.directExecutor()); }, MoreExecutors.directExecutor()); }
From source file:io.atomix.cluster.messaging.impl.NettyMessagingService.java
@Override public CompletableFuture<Void> sendAsync(Address address, String type, byte[] payload) { InternalRequest message = new InternalRequest(preamble, messageIdGenerator.incrementAndGet(), localAddress, type, payload);//from w ww . ja v a 2 s . co m return executeOnPooledConnection(address, type, c -> c.sendAsync(message), MoreExecutors.directExecutor()); }
From source file:io.atomix.cluster.messaging.impl.NettyMessagingService.java
@Override public CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload) { return sendAndReceive(address, type, payload, null, MoreExecutors.directExecutor()); }
From source file:com.facebook.buck.rules.modern.builders.RemoteExecutionStrategy.java
private ListenableFuture<Optional<BuildResult>> sendFailedEventOnException( ListenableFuture<Optional<BuildResult>> futureToBeWrapped, BuildTarget buildTarget, Digest actionDigest) {//ww w . ja v a2 s .c o m futureToBeWrapped.addListener(() -> { Optional<Throwable> exception = Optional.empty(); try { futureToBeWrapped.get(); } catch (InterruptedException e) { exception = Optional.of(e); } catch (ExecutionException e) { exception = Optional.of(e.getCause()); } if (exception.isPresent()) { RemoteExecutionActionEvent.sendTerminalEvent(eventBus, exception.get() instanceof InterruptedException ? State.ACTION_CANCELLED : State.ACTION_FAILED, buildTarget, Optional.of(actionDigest)); } }, MoreExecutors.directExecutor()); return futureToBeWrapped; }