List of usage examples for com.google.common.util.concurrent Futures transformAsync
public static <I, O> ListenableFuture<O> transformAsync(ListenableFuture<I> input, AsyncFunction<? super I, ? extends O> function)
From source file:com.google.gapid.server.Client.java
public ListenableFuture<Message> getSchema() { LOG.log(FINE, "RPC->getSchema()"); return Futures.transformAsync(client.getSchema(GetSchemaRequest.newBuilder().build()), in -> Futures.immediateFuture(decode(throwIfError(in.getObject(), in.getError())))); }
From source file:com.facebook.buck.rules.UnskippedRulesTracker.java
public ListenableFuture<Void> markRuleAsUsed(final BuildRule rule, final BuckEventBus eventBus) { // Add a reference to the used rule so that it is never marked as skipped. ListenableFuture<Void> future = acquireReference(rule); if (rule instanceof HasRuntimeDeps) { // Add references to rule's runtime deps since they cannot be skipped now. future = MoreFutures.chainExceptions(future, acquireReferences(ruleFinder.filterBuildRuleInputs(((HasRuntimeDeps) rule).getRuntimeDeps()))); }/*from w w w . ja v a 2 s. co m*/ // Release references from rule's dependencies since this rule will not need them anymore. future = Futures.transformAsync(future, input -> Futures.transformAsync(ruleDepsCache.get(rule), releaseReferences, executor)); future.addListener(() -> sendEventIfStateChanged(eventBus), MoreExecutors.directExecutor()); return future; }
From source file:com.google.gapid.image.FetchedImage.java
public static ListenableFuture<ImageData> loadLevel(ListenableFuture<FetchedImage> futureImage, final int level) { return Futures.transformAsync(futureImage, image -> Futures.transform(image.getLevel(Math.min(level, image.getLevelCount())), (l) -> l.getData().getImageData())); }
From source file:com.google.gapid.models.CommandStream.java
public ListenableFuture<Node> load(Node node) { return node.load(shell, () -> Futures .transformAsync(client.get(Paths.toAny(node.getPath(Path.CommandTreeNode.newBuilder()))), v1 -> { Service.CommandTreeNode data = v1.getCommandTreeNode(); if (data.getGroup().isEmpty() && data.hasCommands()) { return Futures.transform(loadCommand(lastCommand(data.getCommands())), cmd -> new NodeData(data, cmd)); }/*w w w . ja v a 2 s. co m*/ return Futures.immediateFuture(new NodeData(data, null)); })); }
From source file:com.facebook.buck.core.build.engine.cache.manager.BuildCacheArtifactFetcher.java
public ListenableFuture<CacheResult> tryToFetchArtifactFromBuildCacheAndOverlayOnTopOfProjectFilesystem( RuleKey ruleKey, ArtifactCache artifactCache, ProjectFilesystem filesystem) { if (!rule.isCacheable()) { return Futures.immediateFuture(CacheResult.ignored()); }/*from w w w . j a va 2 s . c o m*/ // Create a temp file whose extension must be ".zip" for Filesystems.newFileSystem() to infer // that we are creating a zip-based FileSystem. LazyPath lazyZipPath = new LazyPath() { @Override protected Path create() throws IOException { return Files.createTempFile( "buck_artifact_" + MostFiles.sanitize(rule.getBuildTarget().getShortName()), ".zip"); } }; // TODO(mbolin): Change ArtifactCache.fetch() so that it returns a File instead of takes one. // Then we could download directly from the remote cache into the on-disk cache and unzip it // from there. return Futures.transformAsync(fetch(artifactCache, ruleKey, lazyZipPath), cacheResult -> { try (Scope ignored = buildRuleScope()) { // Verify that the rule key we used to fetch the artifact is one of the rule keys // reported in it's metadata. if (cacheResult.getType().isSuccess()) { ImmutableSet<RuleKey> ruleKeys = RichStream.from(cacheResult.getMetadata().entrySet()) .filter(e -> BuildInfo.RULE_KEY_NAMES.contains(e.getKey())).map(Map.Entry::getValue) .map(RuleKey::new).toImmutableSet(); if (!ruleKeys.contains(ruleKey)) { LOG.warn("%s: rule keys in artifact don't match rule key used to fetch it: %s not in %s", rule.getBuildTarget(), ruleKey, ruleKeys); } } return Futures.immediateFuture( extractArtifactFromCacheResult(ruleKey, lazyZipPath, filesystem, cacheResult)); } }); }
From source file:com.google.gapid.server.Client.java
public ListenableFuture<List<Stringtable.Info>> getAvailableStringTables() { LOG.log(FINE, "RPC->getAvailableStringTables()"); return Futures.transformAsync( client.getAvailableStringTables(GetAvailableStringTablesRequest.newBuilder().build()), in -> Futures.immediateFuture(throwIfError(in.getTables(), in.getError()).getListList())); }
From source file:org.thingsboard.server.dao.alarm.CassandraAlarmDao.java
@Override public ListenableFuture<List<AlarmInfo>> findAlarms(TenantId tenantId, AlarmQuery query) { log.trace("Try to find alarms by entity [{}], searchStatus [{}], status [{}] and pageLink [{}]", query.getAffectedEntityId(), query.getSearchStatus(), query.getStatus(), query.getPageLink()); EntityId affectedEntity = query.getAffectedEntityId(); String searchStatusName;/*w w w . j a va 2s . c o m*/ if (query.getSearchStatus() == null && query.getStatus() == null) { searchStatusName = AlarmSearchStatus.ANY.name(); } else if (query.getSearchStatus() != null) { searchStatusName = query.getSearchStatus().name(); } else { searchStatusName = query.getStatus().name(); } String relationType = BaseAlarmService.ALARM_RELATION_PREFIX + searchStatusName; ListenableFuture<List<EntityRelation>> relations = relationDao.findRelations(tenantId, affectedEntity, relationType, RelationTypeGroup.ALARM, EntityType.ALARM, query.getPageLink()); return Futures.transformAsync(relations, input -> { List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size()); for (EntityRelation relation : input) { alarmFutures.add( Futures.transform(findAlarmByIdAsync(tenantId, relation.getTo().getId()), AlarmInfo::new)); } return Futures.successfulAsList(alarmFutures); }); }
From source file:com.google.gapid.models.CommandStream.java
public ListenableFuture<API.Command> loadCommand(Path.Command path) { return Futures.transformAsync(client.get(Paths.toAny(path)), value -> Futures .transform(constants.loadConstants(value.getCommand()), ignore -> value.getCommand())); }
From source file:com.google.gapid.server.Client.java
public ListenableFuture<Stringtable.StringTable> getStringTable(Stringtable.Info info) { LOG.log(FINE, "RPC->getStringTable({0})", info); return Futures.transformAsync( client.getStringTable(GetStringTableRequest.newBuilder().setTable(info).build()), in -> Futures.immediateFuture(throwIfError(in.getTable(), in.getError()))); }
From source file:com.google.gapid.server.Client.java
public ListenableFuture<Path.Capture> importCapture(byte[] data) { LOG.log(FINE, "RPC->importCapture(<{0} bytes>)", data.length); return Futures.transformAsync( client.importCapture(ImportCaptureRequest.newBuilder().setData(ByteString.copyFrom(data)).build()), in -> Futures.immediateFuture(throwIfError(in.getCapture(), in.getError()))); }