当前位置: 首页>>代码示例>>Java>>正文


Java Futures.transform方法代码示例

本文整理汇总了Java中com.google.common.util.concurrent.Futures.transform方法的典型用法代码示例。如果您正苦于以下问题:Java Futures.transform方法的具体用法?Java Futures.transform怎么用?Java Futures.transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.util.concurrent.Futures的用法示例。


在下文中一共展示了Futures.transform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findInfoByFrom

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<EntityRelationInfo>> findInfoByFrom(EntityId from, RelationTypeGroup typeGroup) {
    log.trace("Executing findInfoByFrom [{}][{}]", from, typeGroup);
    validate(from);
    validateTypeGroup(typeGroup);
    ListenableFuture<List<EntityRelation>> relations = relationDao.findAllByFrom(from, typeGroup);
    ListenableFuture<List<EntityRelationInfo>> relationsInfo = Futures.transform(relations,
            (AsyncFunction<List<EntityRelation>, List<EntityRelationInfo>>) relations1 -> {
        List<ListenableFuture<EntityRelationInfo>> futures = new ArrayList<>();
                relations1.stream().forEach(relation ->
                        futures.add(fetchRelationInfoAsync(relation,
                                relation2 -> relation2.getTo(),
                                (EntityRelationInfo relationInfo, String entityName) -> relationInfo.setToName(entityName)))
                );
                return Futures.successfulAsList(futures);
    });
    return relationsInfo;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:19,代码来源:BaseRelationService.java

示例2: findAllAsync

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
private ListenableFuture<List<TsKvEntry>> findAllAsync(EntityId entityId, TsKvQuery query) {
  if (query.getAggregation() == Aggregation.NONE) {
    return findAllAsyncWithLimit(entityId, query);
  } else {
    long stepTs = query.getStartTs();
    List<ListenableFuture<Optional<TsKvEntry>>> futures = new ArrayList<>();
    while (stepTs < query.getEndTs()) {
      long startTs = stepTs;
      long endTs = stepTs + query.getInterval();
      long ts = startTs + (endTs - startTs) / 2;
      futures.add(findAndAggregateAsync(entityId, query.getKey(), startTs, endTs, ts, query.getAggregation()));
      stepTs = endTs;
    }
    ListenableFuture<List<Optional<TsKvEntry>>> future = Futures.allAsList(futures);
    return Futures.transform(future, new Function<List<Optional<TsKvEntry>>, List<TsKvEntry>>() {
      @Nullable
      @Override
      public List<TsKvEntry> apply(@Nullable List<Optional<TsKvEntry>> results) {
        if (results == null || results.isEmpty()) {
          return null;
        }
        return results.stream().filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
      }
    }, service);
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:27,代码来源:JpaTimeseriesDao.java

示例3: findInfoByQuery

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<EntityRelationInfo>> findInfoByQuery(EntityRelationsQuery query) {
    log.trace("Executing findInfoByQuery [{}]", query);
    ListenableFuture<List<EntityRelation>> relations = findByQuery(query);
    EntitySearchDirection direction = query.getParameters().getDirection();
    ListenableFuture<List<EntityRelationInfo>> relationsInfo = Futures.transform(relations,
            (AsyncFunction<List<EntityRelation>, List<EntityRelationInfo>>) relations1 -> {
                List<ListenableFuture<EntityRelationInfo>> futures = new ArrayList<>();
                relations1.stream().forEach(relation ->
                        futures.add(fetchRelationInfoAsync(relation,
                                relation2 -> direction == EntitySearchDirection.FROM ? relation2.getTo() : relation2.getFrom(),
                                (EntityRelationInfo relationInfo, String entityName) -> {
                                    if (direction == EntitySearchDirection.FROM) {
                                        relationInfo.setToName(entityName);
                                    } else {
                                        relationInfo.setFromName(entityName);
                                    }
                                }))
                );
                return Futures.successfulAsList(futures);
            });
    return relationsInfo;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:24,代码来源:BaseRelationService.java

示例4: findAllAsyncWithLimit

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(EntityId entityId, TsKvQuery query) {
    long minPartition = toPartitionTs(query.getStartTs());
    long maxPartition = toPartitionTs(query.getEndTs());

    ResultSetFuture partitionsFuture = fetchPartitions(entityId, query.getKey(), minPartition, maxPartition);

    final SimpleListenableFuture<List<TsKvEntry>> resultFuture = new SimpleListenableFuture<>();
    final ListenableFuture<List<Long>> partitionsListFuture = Futures.transform(partitionsFuture, getPartitionsArrayFunction(), readResultsProcessingExecutor);

    Futures.addCallback(partitionsListFuture, new FutureCallback<List<Long>>() {
        @Override
        public void onSuccess(@Nullable List<Long> partitions) {
            TsKvQueryCursor cursor = new TsKvQueryCursor(entityId.getEntityType().name(), entityId.getId(), query, partitions);
            findAllAsyncSequentiallyWithLimit(cursor, resultFuture);
        }

        @Override
        public void onFailure(Throwable t) {
            log.error("[{}][{}] Failed to fetch partitions for interval {}-{}", entityId.getEntityType().name(), entityId.getId(), minPartition, maxPartition, t);
        }
    }, readResultsProcessingExecutor);

    return resultFuture;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:25,代码来源:CassandraBaseTimeseriesDao.java

示例5: findListByStatementAsync

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
protected ListenableFuture<List<D>> findListByStatementAsync(Statement statement) {
    if (statement != null) {
        statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
        ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
        return Futures.transform(resultSetFuture, new Function<ResultSet, List<D>>() {
            @Nullable
            @Override
            public List<D> apply(@Nullable ResultSet resultSet) {
                Result<E> result = getMapper().map(resultSet);
                if (result != null) {
                    List<E> entities = result.all();
                    return DaoUtil.convertDataList(entities);
                } else {
                    return Collections.emptyList();
                }
            }
        });
    }
    return Futures.immediateFuture(Collections.emptyList());
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:21,代码来源:CassandraAbstractModelDao.java

示例6: findInfoByTo

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<EntityRelationInfo>> findInfoByTo(EntityId to, RelationTypeGroup typeGroup) {
    log.trace("Executing findInfoByTo [{}][{}]", to, typeGroup);
    validate(to);
    validateTypeGroup(typeGroup);
    ListenableFuture<List<EntityRelation>> relations = relationDao.findAllByTo(to, typeGroup);
    ListenableFuture<List<EntityRelationInfo>> relationsInfo = Futures.transform(relations,
            (AsyncFunction<List<EntityRelation>, List<EntityRelationInfo>>) relations1 -> {
                List<ListenableFuture<EntityRelationInfo>> futures = new ArrayList<>();
                relations1.stream().forEach(relation ->
                    futures.add(fetchRelationInfoAsync(relation,
                            relation2 -> relation2.getFrom(),
                            (EntityRelationInfo relationInfo, String entityName) -> relationInfo.setFromName(entityName)))
                );
                return Futures.successfulAsList(futures);
            });
    return relationsInfo;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:19,代码来源:BaseRelationService.java

示例7: deleteEntityRelations

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<Boolean> deleteEntityRelations(EntityId entity) {
    log.trace("Executing deleteEntityRelations [{}]", entity);
    validate(entity);
    List<ListenableFuture<List<EntityRelation>>> inboundRelationsList = new ArrayList<>();
    for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) {
        inboundRelationsList.add(relationDao.findAllByTo(entity, typeGroup));
    }
    ListenableFuture<List<List<EntityRelation>>> inboundRelations = Futures.allAsList(inboundRelationsList);
    ListenableFuture<List<Boolean>> inboundDeletions = Futures.transform(inboundRelations, new AsyncFunction<List<List<EntityRelation>>, List<Boolean>>() {
        @Override
        public ListenableFuture<List<Boolean>> apply(List<List<EntityRelation>> relations) throws Exception {
            List<ListenableFuture<Boolean>> results = new ArrayList<>();
            for (List<EntityRelation> relationList : relations) {
                relationList.stream().forEach(relation -> results.add(relationDao.deleteRelation(relation)));
            }
            return Futures.allAsList(results);
        }
    });

    ListenableFuture<Boolean> inboundFuture = Futures.transform(inboundDeletions, getListToBooleanFunction());

    ListenableFuture<Boolean> outboundFuture = relationDao.deleteOutboundRelations(entity);

    return Futures.transform(Futures.allAsList(Arrays.asList(inboundFuture, outboundFuture)), getListToBooleanFunction());
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:27,代码来源:BaseRelationService.java

示例8: findAlarmInfoByIdAsync

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<AlarmInfo> findAlarmInfoByIdAsync(AlarmId alarmId) {
    log.trace("Executing findAlarmInfoByIdAsync [{}]", alarmId);
    validateId(alarmId, "Incorrect alarmId " + alarmId);
    return Futures.transform(alarmDao.findAlarmByIdAsync(alarmId.getId()),
            (AsyncFunction<Alarm, AlarmInfo>) alarm1 -> {
                AlarmInfo alarmInfo = new AlarmInfo(alarm1);
                return Futures.transform(
                        entityService.fetchEntityNameAsync(alarmInfo.getOriginator()), (Function<String, AlarmInfo>)
                                originatorName -> {
                                    alarmInfo.setOriginatorName(originatorName);
                                    return alarmInfo;
                                }
                );
            });
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:17,代码来源:BaseAlarmService.java

示例9: readAllData

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
private CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readAllData() {
    final Set<String> allShardNames = txContextFactory.getActorContext().getConfiguration().getAllShardNames();
    final Collection<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>> futures =
            new ArrayList<>(allShardNames.size());

    for (String shardName : allShardNames) {
        futures.add(singleShardRead(shardName, YangInstanceIdentifier.EMPTY));
    }

    final ListenableFuture<List<Optional<NormalizedNode<?, ?>>>> listFuture = Futures.allAsList(futures);
    final ListenableFuture<Optional<NormalizedNode<?, ?>>> aggregateFuture;

    aggregateFuture = Futures.transform(listFuture,
        (Function<List<Optional<NormalizedNode<?, ?>>>, Optional<NormalizedNode<?, ?>>>) input -> {
            try {
                return NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.EMPTY, input,
                        txContextFactory.getActorContext().getSchemaContext(),
                        txContextFactory.getActorContext().getDatastoreContext().getLogicalStoreType());
            } catch (DataValidationFailedException e) {
                throw new IllegalArgumentException("Failed to aggregate", e);
            }
        }, MoreExecutors.directExecutor());

    return MappingCheckedFuture.create(aggregateFuture, ReadFailedException.MAPPER);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:TransactionProxy.java

示例10: updateLocalServer

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
/**
 * Send a server configuration change to the remote API. The API will respond with
 * the latest version of the server document, and only at that point will the local
 * document be modified. This is done by calling {@link #handleReconfigure},
 * and subclasses can override that method if they want to fire a reconfigure event.
 *
 * This method returns a future that completes after the API responds to the update
 * AND the local server document has been replaced with the result.
 */
@Override
public ListenableFuture<Server> updateLocalServer(ServerDoc.Partial update) {
    return Futures.transform(
        serverService.update(apiConfiguration.serverId(), update),
        (Function<? super Server, ? extends Server>) result -> {
            handleLocalReconfigure(result);
            return result;
        },
        syncExecutor
    );
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:21,代码来源:MinecraftServiceImpl.java

示例11: checkBuildStatus

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
private void checkBuildStatus( final Iterable<BuildTypeData> monitoredBuilds ) {
    try {
        ListenableFuture<Void> future = Futures.immediateFuture( null );
        for ( final BuildTypeData buildType : monitoredBuilds )
            future = Futures.transform( future, (AsyncFunction<Void, Void>) o -> _apiController.requestLastBuildStatus( buildType ) );
        future.get( );
    } catch ( InterruptedException | ExecutionException ignored ) {
    }
}
 
开发者ID:u2032,项目名称:wall-t,代码行数:10,代码来源:ApiMonitoringService.java

示例12: findAssetsByQuery

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<Asset>> findAssetsByQuery(AssetSearchQuery query) {
  ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(query.toEntitySearchQuery());
  ListenableFuture<List<Asset>> assets = Futures.transform(relations,
      (AsyncFunction<List<EntityRelation>, List<Asset>>) relations1 -> {
        EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection();
        List<ListenableFuture<Asset>> futures = new ArrayList<>();
        for (EntityRelation relation : relations1) {
          EntityId entityId = direction == EntitySearchDirection.FROM ? relation.getTo() : relation.getFrom();
          if (entityId.getEntityType() == ThingType.ASSET) {
            futures.add(findAssetByIdAsync(new AssetId(entityId.getId())));
          }
        }
        return Futures.successfulAsList(futures);
      });

  assets = Futures.transform(assets, new Function<List<Asset>, List<Asset>>() {
    @Nullable
    @Override
    public List<Asset> apply(@Nullable List<Asset> assetList) {
      return assetList.stream().filter(asset -> query.getAssetTypes().contains(asset.getType()))
          .collect(Collectors.toList());
    }
  });

  return assets;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:28,代码来源:BaseAssetService.java

示例13: find

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<AttributeKvEntry>> find(EntityId entityId, String attributeType, Collection<String> attributeKeys) {
    List<ListenableFuture<Optional<AttributeKvEntry>>> entries = new ArrayList<>();
    attributeKeys.forEach(attributeKey -> entries.add(find(entityId, attributeType, attributeKey)));
    return Futures.transform(Futures.allAsList(entries), (Function<List<Optional<AttributeKvEntry>>, ? extends List<AttributeKvEntry>>) input -> {
        List<AttributeKvEntry> result = new ArrayList<>();
        input.stream().filter(opt -> opt.isPresent()).forEach(opt -> result.add(opt.get()));
        return result;
    }, readResultsProcessingExecutor);
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:11,代码来源:CassandraBaseAttributesDao.java

示例14: findByQuery

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<EntityRelation>> findByQuery(EntityRelationsQuery query) {
    log.trace("Executing findByQuery [{}]", query);
    RelationsSearchParameters params = query.getParameters();
    final List<EntityTypeFilter> filters = query.getFilters();
    if (filters == null || filters.isEmpty()) {
        log.debug("Filters are not set [{}]", query);
    }

    int maxLvl = params.getMaxLevel() > 0 ? params.getMaxLevel() : Integer.MAX_VALUE;

    try {
        ListenableFuture<Set<EntityRelation>> relationSet = findRelationsRecursively(params.getEntityId(), params.getDirection(), maxLvl, new ConcurrentHashMap<>());
        return Futures.transform(relationSet, (Function<Set<EntityRelation>, List<EntityRelation>>) input -> {
            List<EntityRelation> relations = new ArrayList<>();
            for (EntityRelation relation : input) {
                if (filters == null || filters.isEmpty()) {
                    relations.add(relation);
                } else {
                    for (EntityTypeFilter filter : filters) {
                        if (match(filter, relation, params.getDirection())) {
                            relations.add(relation);
                            break;
                        }
                    }
                }
            }
            return relations;
        });
    } catch (Exception e) {
        log.warn("Failed to query relations: [{}]", query, e);
        throw new RuntimeException(e);
    }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:35,代码来源:BaseRelationService.java

示例15: fetchRelationInfoAsync

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
private ListenableFuture<EntityRelationInfo> fetchRelationInfoAsync(EntityRelation relation,
                                                                    Function<EntityRelation, EntityId> entityIdGetter,
                                                                    BiConsumer<EntityRelationInfo, String> entityNameSetter) {
    ListenableFuture<String> entityName = entityService.fetchEntityNameAsync(entityIdGetter.apply(relation));
    ListenableFuture<EntityRelationInfo> entityRelationInfo =
            Futures.transform(entityName, (Function<String, EntityRelationInfo>) entityName1 -> {
                EntityRelationInfo entityRelationInfo1 = new EntityRelationInfo(relation);
                entityNameSetter.accept(entityRelationInfo1, entityName1);
                return entityRelationInfo1;
            });
    return entityRelationInfo;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:13,代码来源:BaseRelationService.java


注:本文中的com.google.common.util.concurrent.Futures.transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。