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:net.oneandone.troilus.SingleReadQuery.java
private static <T> ListenableFuture<ResultList<T>> toSingleEntryResultList( ListenableFuture<ResultList<T>> list) { Function<ResultList<T>, ResultList<T>> mapperFunction = new Function<ResultList<T>, ResultList<T>>() { @Override/* ww w. j a va 2 s . com*/ public ResultList<T> apply(ResultList<T> list) { return new SingleEntryResultList<>(list); } }; return Futures.transform(list, mapperFunction); }
From source file:co.cask.cdap.explore.client.AbstractExploreClient.java
@Override public ListenableFuture<Void> dropPartition(final Id.DatasetInstance datasetInstance, final PartitionKey key) { ListenableFuture<ExploreExecutionResult> futureResults = getResultsFuture(new HandleProducer() { @Override/*from w w w. j av a2 s . c o m*/ public QueryHandle getHandle() throws ExploreException, SQLException { return doDropPartition(datasetInstance, key); } }); // Exceptions will be thrown in case of an error in the futureHandle return Futures.transform(futureResults, Functions.<Void>constant(null)); }
From source file:org.opendaylight.openflowplugin.impl.services.SalFlowsBatchServiceImpl.java
@Override public Future<RpcResult<AddFlowsBatchOutput>> addFlowsBatch(final AddFlowsBatchInput input) { LOG.trace("Adding flows @ {} : {}", PathUtil.extractNodeId(input.getNode()), input.getBatchAddFlows().size()); final ArrayList<ListenableFuture<RpcResult<AddFlowOutput>>> resultsLot = new ArrayList<>(); for (BatchFlowInputGrouping batchFlow : input.getBatchAddFlows()) { final AddFlowInput addFlowInput = new AddFlowInputBuilder(batchFlow) .setFlowRef(createFlowRef(input.getNode(), batchFlow)).setNode(input.getNode()).build(); resultsLot.add(JdkFutureAdapters.listenInPoolThread(salFlowService.addFlow(addFlowInput))); }/*from w w w. java 2s. c o m*/ final ListenableFuture<RpcResult<List<BatchFailedFlowsOutput>>> commonResult = Futures.transform( Futures.successfulAsList(resultsLot), FlowUtil.<AddFlowOutput>createCumulatingFunction(input.getBatchAddFlows())); ListenableFuture<RpcResult<AddFlowsBatchOutput>> addFlowsBulkFuture = Futures.transform(commonResult, FlowUtil.FLOW_ADD_TRANSFORM); if (input.isBarrierAfter()) { addFlowsBulkFuture = BarrierUtil.chainBarrier(addFlowsBulkFuture, input.getNode(), transactionService, FlowUtil.FLOW_ADD_COMPOSING_TRANSFORM); } return addFlowsBulkFuture; }
From source file:com.facebook.buck.rules.UnskippedRulesTracker.java
private ListenableFuture<Void> releaseReferences(ImmutableSortedSet<BuildRule> rules) { ImmutableList.Builder<ListenableFuture<Void>> futures = ImmutableList.builder(); for (BuildRule rule : rules) { futures.add(releaseReference(rule)); }/*from w w w. j ava 2s . co m*/ return Futures.transform(Futures.allAsList(futures.build()), NULL_FUNCTION); }
From source file:org.thingsboard.server.dao.asset.AssetDaoImpl.java
@Override public ListenableFuture<List<TenantAssetTypeEntity>> findTenantAssetTypesAsync() { Select statement = select().distinct().column(ASSET_TYPE_PROPERTY).column(ASSET_TENANT_ID_PROPERTY) .from(ASSET_TYPES_BY_TENANT_VIEW_NAME); statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); ResultSetFuture resultSetFuture = getSession().executeAsync(statement); ListenableFuture<List<TenantAssetTypeEntity>> result = Futures.transform(resultSetFuture, new Function<ResultSet, List<TenantAssetTypeEntity>>() { @Nullable//from w w w. ja v a 2s. c om @Override public List<TenantAssetTypeEntity> apply(@Nullable ResultSet resultSet) { Result<TenantAssetTypeEntity> result = cluster.getMapper(TenantAssetTypeEntity.class) .map(resultSet); if (result != null) { return result.all(); } else { return Collections.emptyList(); } } }); return result; }
From source file:co.cask.cdap.common.zookeeper.coordination.ResourceCoordinatorClient.java
/** * Deletes the {@link ResourceRequirement} for the given resource. * * @param resourceName Name of the resource. * @return A {@link ListenableFuture} that will be completed when the requirement is successfully removed. * If the requirement doesn't exists, the deletion would still be treated as successful. *//*ww w . j a v a 2 s .c om*/ public ListenableFuture<String> deleteRequirement(String resourceName) { String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName; return Futures.transform(ZKOperations.ignoreError(zkClient.delete(zkPath), KeeperException.NoNodeException.class, resourceName), Functions.constant(resourceName)); }
From source file:org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowStatisticsServiceImpl.java
@Override public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch( final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor); }
From source file:io.v.v23.syncbase.nosql.DatabaseImpl.java
@Override public ListenableFuture<BlobWriter> writeBlob(VContext ctx, BlobRef ref) { ListenableFuture<BlobRef> refFuture = ref == null ? client.createBlob(ctx) : Futures.immediateFuture(ref); return Futures.transform(refFuture, new Function<BlobRef, BlobWriter>() { @Override// w w w . j a v a2 s.c om public BlobWriter apply(BlobRef ref) { return new BlobWriterImpl(client, ref); } }); }
From source file:com.microsoft.azure.keyvault.extensions.KeyVaultKey.java
@Override public ListenableFuture<Pair<byte[], String>> signAsync(byte[] digest, String algorithm) throws NoSuchAlgorithmException { if (implementation == null) { return null; }/*from w ww. j a va 2s. com*/ if (Strings.isNullOrWhiteSpace(algorithm)) { algorithm = getDefaultSignatureAlgorithm(); } // Never local ListenableFuture<KeyOperationResult> futureCall = client.signAsync(implementation.getKid(), new JsonWebKeySignatureAlgorithm(algorithm), digest, null); return Futures.transform(futureCall, new SignResultTransform(algorithm)); }
From source file:io.v.v23.InputChannels.java
private static <T> FutureCallback<T> newCallbackForCallback(final InputChannel<T> channel, final SettableFuture<Void> future, final InputChannelCallback<? super T> callback, final Executor executor) { return new FutureCallback<T>() { @Override//from w w w .j av a2 s . c o m public void onSuccess(T result) { ListenableFuture<Void> done = callback.onNext(result); if (done == null) { done = Futures.immediateFuture(null); } Futures.addCallback(Futures.transform(done, new AsyncFunction<Void, T>() { @Override public ListenableFuture<T> apply(Void input) throws Exception { return channel.recv(); } }), newCallbackForCallback(channel, future, callback, executor), executor); } @Override public void onFailure(Throwable t) { if (t instanceof EndOfFileException) { future.set(null); return; } future.setException(t); } }; }