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<Value> get(Path.Any path) { LOG.log(FINE, "RPC->get({0})", path); return Futures.transformAsync(client.get(GetRequest.newBuilder().setPath(path).build()), in -> Futures.immediateFuture(throwIfError(in.getValue(), in.getError()))); }
From source file:com.facebook.buck.parser.ConvertingPipeline.java
@Override public ListenableFuture<T> getNodeJob(final Cell cell, final BuildTarget buildTarget) throws BuildTargetException { return cache.getJobWithCacheLookup(cell, buildTarget, () -> Futures.transformAsync(getItemToConvert(cell, buildTarget), from -> dispatchComputeNode(cell, buildTarget, from))); }
From source file:com.orangerhymelabs.helenus.cassandra.table.ViewService.java
public ListenableFuture<View> update(View view) { ListenableFuture<Boolean> tableFuture = tables.exists(view.databaseName(), view.tableName()); return Futures.transformAsync(tableFuture, new AsyncFunction<Boolean, View>() { @Override/*w ww .ja v a 2 s . c om*/ public ListenableFuture<View> apply(Boolean exists) throws Exception { if (exists) { try { ValidationEngine.validateAndThrow(view); return views.update(view); } catch (ValidationException e) { return Futures.immediateFailedFuture(e); } } else { return Futures.immediateFailedFuture( new ItemNotFoundException("Database not found: " + view.databaseName())); } } }); }
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.server.dao.dashboard.CassandraDashboardInfoDao.java
@Override public ListenableFuture<List<DashboardInfo>> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TimePageLink pageLink) { log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink);/* w ww .ja v a 2 s . co m*/ ListenableFuture<List<EntityRelation>> relations = relationDao.findRelations(new TenantId(tenantId), new CustomerId(customerId), EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD, EntityType.DASHBOARD, pageLink); return Futures.transformAsync(relations, input -> { List<ListenableFuture<DashboardInfo>> dashboardFutures = new ArrayList<>(input.size()); for (EntityRelation relation : input) { dashboardFutures.add(findByIdAsync(new TenantId(tenantId), relation.getTo().getId())); } return Futures.successfulAsList(dashboardFutures); }); }
From source file:com.google.gapid.server.Client.java
public ListenableFuture<Path.Any> follow(Path.Any path) { LOG.log(FINE, "RPC->follow({0})", path); return Futures.transformAsync(client.follow(FollowRequest.newBuilder().setPath(path).setPath(path).build()), in -> Futures.immediateFuture(throwIfError(in.getPath(), in.getError()))); }
From source file:com.google.gapid.models.CommandStream.java
@Override protected ListenableFuture<Node> doLoad(Path.Any path) { return Futures.transformAsync(client.get(path), tree -> Futures.transform(client.get(Paths.toAny(tree.getCommandTree().getRoot())), val -> new RootNode(tree.getCommandTree().getRoot().getTree(), val.getCommandTreeNode()))); }
From source file:org.thingsboard.server.dao.sql.alarm.JpaAlarmDao.java
@Override public ListenableFuture<List<AlarmInfo>> findAlarms(TenantId tenantId, AlarmQuery query) { log.trace("Try to find alarms by entity [{}], status [{}] and pageLink [{}]", query.getAffectedEntityId(), query.getStatus(), query.getPageLink()); EntityId affectedEntity = query.getAffectedEntityId(); String searchStatusName;//from www . j a va 2 s . 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.ApiState.java
public ListenableFuture<Node> load(Node node) { return node.load( () -> Futures.transformAsync(client.get(Paths.any(node.getPath(Path.StateTreeNode.newBuilder()))), value -> Futures.transform(constants.loadConstants(value.getStateTreeNode()), ignore -> new NodeData(value.getStateTreeNode())))); }
From source file:com.google.gapid.models.Devices.java
public void loadDevices() { Rpc.listen(Futures.transformAsync(client.getDevices(), paths -> { List<ListenableFuture<Service.Value>> results = Lists.newArrayList(); for (Path.Device path : paths) { results.add(client.get(Paths.device(path))); }//from w w w. j av a 2 s . com return Futures.allAsList(results); }), rpcController, new UiErrorCallback<List<Service.Value>, List<Device.Instance>, Void>(shell, LOG) { @Override protected ResultOrError<List<Device.Instance>, Void> onRpcThread(Result<List<Service.Value>> result) throws RpcException, ExecutionException { try { return success(result.get().stream().map(Service.Value::getDevice).collect(toList())); } catch (RpcException | ExecutionException e) { LOG.log(SEVERE, "LoadData error", e); return error(null); } } @Override protected void onUiThreadSuccess(List<Device.Instance> result) { updateDevices(result); } @Override protected void onUiThreadError(Void error) { updateDevices(null); } }); }