List of usage examples for com.google.common.util.concurrent Futures transform
public static <I, O> ListenableFuture<O> transform(ListenableFuture<I> input, Function<? super I, ? extends O> function)
From source file:org.opendaylight.faas.fabric.general.FabricManagementAPIProvider.java
@Override public Future<RpcResult<Void>> decomposeFabric(DecomposeFabricInput input) { final RpcResult<Void> result = RpcResultBuilder.<Void>success().build(); if (input == null) { return Futures.immediateFailedCheckedFuture(new IllegalArgumentException("fabricId can not be empty!")); }/*w ww.jav a 2 s. c o m*/ final FabricId fabricId = input.getFabricId(); if (fabricId == null) { return Futures.immediateFailedCheckedFuture(new IllegalArgumentException("fabricId can not be empty!")); } ReadWriteTransaction rt = dataBroker.newReadWriteTransaction(); final InstanceIdentifier<Node> fabricpath = Constants.DOM_FABRICS_PATH.child(Node.class, new NodeKey(fabricId)); CheckedFuture<Optional<Node>, ReadFailedException> readFuture = rt.read(LogicalDatastoreType.OPERATIONAL, fabricpath); return Futures.transform(readFuture, (AsyncFunction<Optional<Node>, RpcResult<Void>>) optional -> { if (optional.isPresent()) { Node fabric = optional.get(); FabricInstanceCache.INSTANCE.retrieveFabric(fabricId).notifyFabricDeleted(fabric); WriteTransaction wt = dataBroker.newWriteOnlyTransaction(); wt.delete(LogicalDatastoreType.OPERATIONAL, fabricpath); wt.delete(LogicalDatastoreType.CONFIGURATION, fabricpath); wt.delete(LogicalDatastoreType.OPERATIONAL, MdSalUtils.createTopoIId(fabricId.getValue())); MdSalUtils.wrapperSubmit(wt, executor); FabricInstanceCache.INSTANCE.removeFabric(fabricId); } return Futures.immediateFuture(result); }); }
From source file:org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.java
/** * @param tableOffset the new offset value * @return {@link ListenableFuture} to indicate that tables have been synced *///from www.j a v a 2 s . co m public ListenableFuture<Void> changeOpenFlowTableOffset(final short tableOffset) { try { verifyMaxTableId(tableOffset); } catch (IllegalArgumentException e) { LOG.error("Cannot update table offset. Max. table ID would be out of range.\n{}", e); // TODO - invalid offset value remains in conf DS // It's not possible to validate offset value by using constrains in model, // because number of tables in pipeline varies. return Futures.immediateFuture(null); } List<Short> tableIDs = getTableIDs(); this.tableOffset = tableOffset; return Futures.transform(removeUnusedTables(tableIDs), new Function<Void, Void>() { @Override public Void apply(Void tablesRemoved) { scheduleUpdate(); return null; } }); }
From source file:org.rhq.server.metrics.MetricsServer.java
public ListenableFuture<AggregateNumericMetric> getSummaryAggregateAsync(int scheduleId, long beginTime, long endTime) { long start = System.currentTimeMillis(); try {/*from w w w . ja va 2 s. c o m*/ if (log.isDebugEnabled()) { log.debug("Calculating resource summary aggregate (async) for [scheduleId: " + scheduleId + ", beginTime: " + beginTime + ", endTime: " + endTime + "]"); } DateTime begin = new DateTime(beginTime); StorageResultSetFuture queryFuture; if (dateTimeService.isInRawDataRange(begin)) { queryFuture = dao.findRawMetricsAsync(scheduleId, beginTime, endTime); return Futures.transform(queryFuture, new ComputeRawAggregate(beginTime)); } Bucket bucket = getBucket(begin); queryFuture = dao.findAggregateMetricsAsync(scheduleId, bucket, beginTime, endTime); return Futures.transform(queryFuture, new ComputeAggregate(beginTime, bucket)); } finally { long end = System.currentTimeMillis(); if (log.isDebugEnabled()) { log.debug("Finished calculating resource summary aggregate (async) in " + (end - start) + " ms"); } } }
From source file:org.thingsboard.server.dao.entityview.CassandraEntityViewDao.java
@Override public ListenableFuture<List<EntitySubtype>> findTenantEntityViewTypesAsync(UUID tenantId) { Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME); Select.Where query = select.where(); query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId)); query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.ENTITY_VIEW)); query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); ResultSetFuture resultSetFuture = executeAsyncRead(new TenantId(tenantId), query); return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() { @Nullable// w w w . j a v a2s . com @Override public List<EntitySubtype> apply(@Nullable ResultSet resultSet) { Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet); if (result != null) { List<EntitySubtype> entitySubtypes = new ArrayList<>(); result.all().forEach( (entitySubtypeEntity) -> entitySubtypes.add(entitySubtypeEntity.toEntitySubtype())); return entitySubtypes; } else { return Collections.emptyList(); } } }); }
From source file:org.thingsboard.server.dao.event.CassandraBaseEventDao.java
private ListenableFuture<Optional<Event>> saveAsync(TenantId tenantId, EventEntity entity, boolean ifNotExists) { if (entity.getId() == null) { entity.setId(UUIDs.timeBased()); }// w ww.ja va 2 s .co m Insert insert = QueryBuilder.insertInto(getColumnFamilyName()) .value(ModelConstants.ID_PROPERTY, entity.getId()) .value(ModelConstants.EVENT_TENANT_ID_PROPERTY, entity.getTenantId()) .value(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entity.getEntityType()) .value(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entity.getEntityId()) .value(ModelConstants.EVENT_TYPE_PROPERTY, entity.getEventType()) .value(ModelConstants.EVENT_UID_PROPERTY, entity.getEventUid()) .value(ModelConstants.EVENT_BODY_PROPERTY, entity.getBody()); if (ifNotExists) { insert = insert.ifNotExists(); } ResultSetFuture resultSetFuture = executeAsyncWrite(tenantId, insert); return Futures.transform(resultSetFuture, rs -> { if (rs.wasApplied()) { return Optional.of(DaoUtil.getData(entity)); } else { return Optional.empty(); } }); }
From source file:com.google.cloud.bigtable.grpc.BigtableGrpcClient.java
@Override public ListenableFuture<ImmutableList<SampleRowKeysResponse>> sampleRowKeysAsync(SampleRowKeysRequest request) { CollectingStreamObserver<SampleRowKeysResponse> responseBuffer = new CollectingStreamObserver<>(); Calls.asyncServerStreamingCall(bigtableChannel.newCall(BigtableServiceGrpc.CONFIG.sampleRowKeys), request, responseBuffer);/* w w w.ja v a2 s . co m*/ return Futures.transform(responseBuffer.getResponseCompleteFuture(), new Function<List<SampleRowKeysResponse>, ImmutableList<SampleRowKeysResponse>>() { @Override public ImmutableList<SampleRowKeysResponse> apply( List<SampleRowKeysResponse> sampleRowKeysResponses) { return ImmutableList.copyOf(sampleRowKeysResponses); } }); }
From source file:com.netflix.metacat.main.services.search.ElasticSearchMetacatRefresh.java
@SuppressWarnings("checkstyle:methodname") private ListenableFuture<Void> _processPartitions(final List<QualifiedName> qNames) { final List<QualifiedName> excludeQualifiedNames = config.getElasticSearchRefreshExcludeQualifiedNames(); final List<String> tables = elasticSearchUtil.getTableIdsByCatalogs(ElasticSearchDoc.Type.table.name(), qNames, excludeQualifiedNames); final List<ListenableFuture<ListenableFuture<Void>>> futures = tables.stream() .map(s -> service.submit(() -> { final QualifiedName tableName = QualifiedName.fromString(s, false); final List<ListenableFuture<Void>> indexFutures = Lists.newArrayList(); int offset = 0; int count; Sort sort;/*from ww w . j a v a 2 s. c o m*/ if ("s3".equals(tableName.getCatalogName()) || "aegisthus".equals(tableName.getCatalogName())) { sort = new Sort("id", SortOrder.ASC); } else { sort = new Sort("part_id", SortOrder.ASC); } final Pageable pageable = new Pageable(10000, offset); do { final List<PartitionDto> partitionDtos = partitionService.list(tableName, null, null, sort, pageable, true, true, true); count = partitionDtos.size(); if (!partitionDtos.isEmpty()) { final List<List<PartitionDto>> partitionedPartitionDtos = Lists.partition(partitionDtos, 1000); partitionedPartitionDtos.forEach(subPartitionsDtos -> indexFutures .add(indexPartitionDtos(tableName, subPartitionsDtos))); offset = offset + count; pageable.setOffset(offset); } } while (count == 10000); return Futures.transform(Futures.successfulAsList(indexFutures), Functions.constant((Void) null)); })).collect(Collectors.toList()); final ListenableFuture<Void> processPartitionsFuture = Futures .transformAsync(Futures.successfulAsList(futures), input -> { final List<ListenableFuture<Void>> inputFuturesWithoutNulls = input.stream().filter(NOT_NULL) .collect(Collectors.toList()); return Futures.transform(Futures.successfulAsList(inputFuturesWithoutNulls), Functions.constant(null)); }); return Futures.transformAsync(processPartitionsFuture, input -> { elasticSearchUtil.refresh(); final List<ListenableFuture<Void>> cleanUpFutures = tables.stream() .map(s -> service.submit( () -> partitionsCleanUp(QualifiedName.fromString(s, false), excludeQualifiedNames))) .collect(Collectors.toList()); return Futures.transform(Futures.successfulAsList(cleanUpFutures), Functions.constant(null)); }); }
From source file:io.v.v23.syncbase.DatabaseImpl.java
@Override public ListenableFuture<BlobWriter> writeBlob(VContext ctx, BlobRef ref) { ListenableFuture<BlobRef> refFuture = ref == null ? client.createBlob(ctx) : Futures.immediateFuture(ref); return VFutures.withUserLandChecks(ctx, Futures.transform(refFuture, new Function<BlobRef, BlobWriter>() { @Override/*from ww w .j av a 2 s. co m*/ public BlobWriter apply(BlobRef ref) { return new BlobWriterImpl(client, ref); } })); }
From source file:org.thingsboard.server.dao.asset.CassandraAssetDao.java
@Override public ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(UUID tenantId) { Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME); Select.Where query = select.where(); query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId)); query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.ASSET)); query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); ResultSetFuture resultSetFuture = executeAsyncRead(new TenantId(tenantId), query); return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() { @Nullable/*w ww. j ava 2 s. c o m*/ @Override public List<EntitySubtype> apply(@Nullable ResultSet resultSet) { Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet); if (result != null) { List<EntitySubtype> entitySubtypes = new ArrayList<>(); result.all().forEach( (entitySubtypeEntity) -> entitySubtypes.add(entitySubtypeEntity.toEntitySubtype())); return entitySubtypes; } else { return Collections.emptyList(); } } }); }
From source file:org.thingsboard.server.dao.device.CassandraDeviceDao.java
@Override public ListenableFuture<List<EntitySubtype>> findTenantDeviceTypesAsync(UUID tenantId) { Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME); Select.Where query = select.where(); query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId)); query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.DEVICE)); query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); ResultSetFuture resultSetFuture = executeAsyncRead(new TenantId(tenantId), query); return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() { @Nullable//from w w w. j a va 2 s . c o m @Override public List<EntitySubtype> apply(@Nullable ResultSet resultSet) { Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet); if (result != null) { List<EntitySubtype> entitySubtypes = new ArrayList<>(); result.all().forEach( (entitySubtypeEntity) -> entitySubtypes.add(entitySubtypeEntity.toEntitySubtype())); return entitySubtypes; } else { return Collections.emptyList(); } } }); }