當前位置: 首頁>>代碼示例>>Java>>正文


Java AsyncFunction類代碼示例

本文整理匯總了Java中com.google.common.util.concurrent.AsyncFunction的典型用法代碼示例。如果您正苦於以下問題:Java AsyncFunction類的具體用法?Java AsyncFunction怎麽用?Java AsyncFunction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AsyncFunction類屬於com.google.common.util.concurrent包,在下文中一共展示了AsyncFunction類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findDevicesByQuery

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
@Override
public ListenableFuture<List<DeviceType>> findDevicesByQuery(DeviceTypeSearchQuery query) {
    ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(query.toEntitySearchQuery());
    ListenableFuture<List<DeviceType>> devices = Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<DeviceType>>) relations1 -> {
        EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection();
        List<ListenableFuture<DeviceType>> futures = new ArrayList<>();
        for (EntityRelation relation : relations1) {
            EntityId entityId = direction == EntitySearchDirection.FROM ? relation.getTo() : relation.getFrom();
            if (entityId.getEntityType() == ThingType.DEVICE) {
                futures.add(findDeviceByIdAsync(new DeviceTypeId(entityId.getId())));
            }
        }
        return Futures.successfulAsList(futures);
    });

    devices = Futures.transform(devices, new Function<List<DeviceType>, List<DeviceType>>() {
        @Nullable
        @Override
        public List<DeviceType> apply(@Nullable List<DeviceType> deviceList) {
            return deviceList.stream().collect(Collectors.toList());
        }
    });

    return devices;
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:26,代碼來源:DeviceTypeServiceImpl.java

示例2: deleteEntityRelations

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的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

示例3: findInfoByFrom

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的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

示例4: findInfoByTo

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的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

示例5: findInfoByQuery

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的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

示例6: findDevicesByQuery

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
@Override
public ListenableFuture<List<Device>> findDevicesByQuery(DeviceSearchQuery query) {
    ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(query.toEntitySearchQuery());
    ListenableFuture<List<Device>> devices = Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<Device>>) relations1 -> {
        EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection();
        List<ListenableFuture<Device>> futures = new ArrayList<>();
        for (EntityRelation relation : relations1) {
            EntityId entityId = direction == EntitySearchDirection.FROM ? relation.getTo() : relation.getFrom();
            if (entityId.getEntityType() == ThingType.DEVICE) {
                futures.add(findDeviceByIdAsync(new DeviceId(entityId.getId())));
            }
        }
        return Futures.successfulAsList(futures);
    });

    devices = Futures.transform(devices, new Function<List<Device>, List<Device>>() {
        @Nullable
        @Override
        public List<Device> apply(@Nullable List<Device> deviceList) {
            return deviceList.stream().filter(device -> query.getDeviceTypes().contains(device.getType())).collect(Collectors.toList());
        }
    });

    return devices;
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:26,代碼來源:DeviceServiceImpl.java

示例7: findAlarmInfoByIdAsync

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的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

示例8: findAlarms

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
@Override
public ListenableFuture<List<AlarmInfo>> findAlarms(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;
    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(affectedEntity, relationType, RelationTypeGroup.ALARM, ThingType.ALARM, query.getPageLink());
    return Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<AlarmInfo>>) input -> {
        List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size());
        for (EntityRelation relation : input) {
            alarmFutures.add(Futures.transform(
                    findAlarmByIdAsync(relation.getTo().getId()),
                    (Function<Alarm, AlarmInfo>) AlarmInfo::new));
        }
        return Futures.successfulAsList(alarmFutures);
    });
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:25,代碼來源:CassandraAlarmDao.java

示例9: getFetchChunksAsyncFunction

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
private AsyncFunction<List<Long>, List<ResultSet>> getFetchChunksAsyncFunction(EntityId entityId, String key, Aggregation aggregation, long startTs, long endTs) {
    return partitions -> {
        try {
            PreparedStatement proto = getFetchStmt(aggregation);
            List<ResultSetFuture> futures = new ArrayList<>(partitions.size());
            for (Long partition : partitions) {
                log.trace("Fetching data for partition [{}] for entityType {} and entityId {}", partition, entityId.getEntityType(), entityId.getId());
                BoundStatement stmt = proto.bind();
                stmt.setString(0, entityId.getEntityType().name());
                stmt.setUUID(1, entityId.getId());
                stmt.setString(2, key);
                stmt.setLong(3, partition);
                stmt.setLong(4, startTs);
                stmt.setLong(5, endTs);
                log.debug("Generated query [{}] for entityType {} and entityId {}", stmt, entityId.getEntityType(), entityId.getId());
                futures.add(executeAsyncRead(stmt));
            }
            return Futures.allAsList(futures);
        } catch (Throwable e) {
            log.error("Failed to fetch data", e);
            throw e;
        }
    };
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:25,代碼來源:CassandraBaseTimeseriesDao.java

示例10: findAlarms

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
@Override
public ListenableFuture<List<AlarmInfo>> findAlarms(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;
  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(affectedEntity, relationType,
      RelationTypeGroup.ALARM, ThingType.ALARM, query.getPageLink());
  return Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<AlarmInfo>>) input -> {
    List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size());
    for (EntityRelation relation : input) {
      alarmFutures.add(Futures.transform(findAlarmByIdAsync(relation.getTo().getId()),
          (Function<Alarm, AlarmInfo>) AlarmInfo::new));
    }
    return Futures.successfulAsList(alarmFutures);
  });
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:26,代碼來源:JpaAlarmDao.java

示例11: deleteEntityRelationsAsync

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
@Override
public ListenableFuture<Boolean> deleteEntityRelationsAsync(EntityId entity) {
    log.trace("Executing deleteEntityRelationsAsync [{}]", 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.deleteRelationAsync(relation)));
            }
            return Futures.allAsList(results);
        }
    });

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

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

    return Futures.transform(Futures.allAsList(Arrays.asList(inboundFuture, outboundFuture)), getListToBooleanFunction());
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:27,代碼來源:BaseRelationService.java

示例12: findDevicesByQuery

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
@Override
public ListenableFuture<List<Device>> findDevicesByQuery(DeviceSearchQuery query) {
    ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(query.toEntitySearchQuery());
    ListenableFuture<List<Device>> devices = Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<Device>>) relations1 -> {
        EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection();
        List<ListenableFuture<Device>> futures = new ArrayList<>();
        for (EntityRelation relation : relations1) {
            EntityId entityId = direction == EntitySearchDirection.FROM ? relation.getTo() : relation.getFrom();
            if (entityId.getEntityType() == EntityType.DEVICE) {
                futures.add(findDeviceByIdAsync(new DeviceId(entityId.getId())));
            }
        }
        return Futures.successfulAsList(futures);
    });

    devices = Futures.transform(devices, new Function<List<Device>, List<Device>>() {
        @Nullable
        @Override
        public List<Device> apply(@Nullable List<Device> deviceList) {
            return deviceList == null ? Collections.emptyList() : deviceList.stream().filter(device -> query.getDeviceTypes().contains(device.getType())).collect(Collectors.toList());
        }
    });

    return devices;
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:26,代碼來源:DeviceServiceImpl.java

示例13: findAlarms

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
@Override
public ListenableFuture<List<AlarmInfo>> findAlarms(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;
    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(affectedEntity, relationType, RelationTypeGroup.ALARM, EntityType.ALARM, query.getPageLink());
    return Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<AlarmInfo>>) input -> {
        List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size());
        for (EntityRelation relation : input) {
            alarmFutures.add(Futures.transform(
                    findAlarmByIdAsync(relation.getTo().getId()),
                    (Function<Alarm, AlarmInfo>) AlarmInfo::new));
        }
        return Futures.successfulAsList(alarmFutures);
    });
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:25,代碼來源:CassandraAlarmDao.java

示例14: getFetchChunksAsyncFunction

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
private AsyncFunction<List<Long>, List<ResultSet>> getFetchChunksAsyncFunction(EntityId entityId, String key, Aggregation aggregation, long startTs, long endTs) {
    return partitions -> {
        try {
            PreparedStatement proto = getFetchStmt(aggregation);
            List<ResultSetFuture> futures = new ArrayList<>(partitions.size());
            for (Long partition : partitions) {
                log.trace("Fetching data for partition [{}] for entityType {} and entityId {}", partition, entityId.getEntityType(), entityId.getId());
                BoundStatement stmt = proto.bind();
                stmt.setString(0, entityId.getEntityType().name());
                stmt.setUUID(1, entityId.getId());
                stmt.setString(2, key);
                stmt.setLong(3, partition);
                stmt.setLong(4, startTs);
                stmt.setLong(5, endTs);
                log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId());
                futures.add(executeAsyncRead(stmt));
            }
            return Futures.allAsList(futures);
        } catch (Throwable e) {
            log.error("Failed to fetch data", e);
            throw e;
        }
    };
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:25,代碼來源:CassandraBaseTimeseriesDao.java

示例15: findAlarms

import com.google.common.util.concurrent.AsyncFunction; //導入依賴的package包/類
@Override
public ListenableFuture<List<AlarmInfo>> findAlarms(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;
    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(affectedEntity, relationType, RelationTypeGroup.ALARM, EntityType.ALARM, query.getPageLink());
    return Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<AlarmInfo>>) input -> {
        List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size());
        for (EntityRelation relation : input) {
            alarmFutures.add(Futures.transform(
                    findAlarmByIdAsync(relation.getTo().getId()),
                    (Function<Alarm, AlarmInfo>) AlarmInfo::new));
        }
        return Futures.successfulAsList(alarmFutures);
    });
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:25,代碼來源:JpaAlarmDao.java


注:本文中的com.google.common.util.concurrent.AsyncFunction類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。