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.openflowplugin.impl.services.SalFlowsBatchServiceImpl.java
@Override public Future<RpcResult<RemoveFlowsBatchOutput>> removeFlowsBatch(final RemoveFlowsBatchInput input) { LOG.trace("Removing flows @ {} : {}", PathUtil.extractNodeId(input.getNode()), input.getBatchRemoveFlows().size()); final ArrayList<ListenableFuture<RpcResult<RemoveFlowOutput>>> resultsLot = new ArrayList<>(); for (BatchFlowInputGrouping batchFlow : input.getBatchRemoveFlows()) { final RemoveFlowInput removeFlowInput = new RemoveFlowInputBuilder(batchFlow) .setFlowRef(createFlowRef(input.getNode(), batchFlow)).setNode(input.getNode()).build(); resultsLot.add(JdkFutureAdapters.listenInPoolThread(salFlowService.removeFlow(removeFlowInput))); }/*from w w w . j a v a2 s. c om*/ final ListenableFuture<RpcResult<List<BatchFailedFlowsOutput>>> commonResult = Futures.transform( Futures.successfulAsList(resultsLot), FlowUtil.<RemoveFlowOutput>createCumulatingFunction(input.getBatchRemoveFlows())); ListenableFuture<RpcResult<RemoveFlowsBatchOutput>> removeFlowsBulkFuture = Futures.transform(commonResult, FlowUtil.FLOW_REMOVE_TRANSFORM); if (input.isBarrierAfter()) { removeFlowsBulkFuture = BarrierUtil.chainBarrier(removeFlowsBulkFuture, input.getNode(), transactionService, FlowUtil.FLOW_REMOVE_COMPOSING_TRANSFORM); } return removeFlowsBulkFuture; }
From source file:utils.teamcity.wallt.controller.api.ApiMonitoringService.java
private void checkBuildStatus(final Iterable<BuildTypeData> monitoredBuilds) { try {/*from www.j a v a 2 s.com*/ 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) { } }
From source file:org.grouplens.lenskit.eval.script.ConfigMethodInvoker.java
Object transform(Object obj, Function<Object, ?> function) { if (obj instanceof Future) { return Futures.transform(listenInPoolThread((Future) obj), function); } else {/* www. j ava2 s . c om*/ return function.apply(obj); } }
From source file:io.v.v23.syncbase.DatabaseImpl.java
@Override public ListenableFuture<Map<String, Permissions>> getPermissions(VContext ctx) { return VFutures.withUserLandChecks(ctx, Futures.transform(client.getPermissions(ctx), new Function<ObjectClient.GetPermissionsOut, Map<String, Permissions>>() { @Override/*from w ww . j a va2 s . c o m*/ public Map<String, Permissions> apply(ObjectClient.GetPermissionsOut perms) { return ImmutableMap.of(perms.version, perms.perms); } })); }
From source file:io.v.v23.syncbase.nosql.DatabaseImpl.java
public ListenableFuture<BatchDatabase> beginBatch(VContext ctx, BatchOptions opts) { return Futures.transform(client.beginBatch(ctx, getSchemaVersion(), opts), new Function<String, BatchDatabase>() { @Override//from w w w. j a v a 2 s. c o m public BatchDatabase apply(String batchSuffix) { return new DatabaseImpl(parentFullName, name, batchSuffix, schema); } }); }
From source file:org.opendaylight.controller.sal.connect.netconf.sal.tx.NetconfDeviceReadOnlyTx.java
private CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readOperationalData( final YangInstanceIdentifier path) { final ListenableFuture<RpcResult<CompositeNode>> future = rpc.invokeRpc(NETCONF_GET_QNAME, NetconfMessageTransformUtil.wrap(NETCONF_GET_QNAME, toFilterStructure(path))); final ListenableFuture<Optional<NormalizedNode<?, ?>>> transformedFuture = Futures.transform(future, new Function<RpcResult<CompositeNode>, Optional<NormalizedNode<?, ?>>>() { @Override//ww w . j a va 2s.co m public Optional<NormalizedNode<?, ?>> apply(final RpcResult<CompositeNode> result) { checkReadSuccess(result, path); final CompositeNode data = result.getResult().getFirstCompositeByName(NETCONF_DATA_QNAME); final CompositeNode node = (CompositeNode) NetconfMessageTransformUtil.findNode(data, path); return data == null ? Optional.<NormalizedNode<?, ?>>absent() : transform(path, node); } }); return MappingCheckedFuture.create(transformedFuture, ReadFailedException.MAPPER); }
From source file:co.cask.cdap.data.stream.AbstractStreamCoordinator.java
@Override public ListenableFuture<Long> changeTTL(final StreamConfig streamConfig, final long newTTL) { return Futures.transform( propertyStore.get().update(streamConfig.getName(), new PropertyUpdater<StreamProperty>() { @Override/* w ww. j a va 2 s . c om*/ public ListenableFuture<StreamProperty> apply(@Nullable final StreamProperty property) { final SettableFuture<StreamProperty> resultFuture = SettableFuture.create(); updateExecutor.execute(new Runnable() { @Override public void run() { try { int currentGeneration = (property == null) ? StreamUtils.getGeneration(streamConfig) : property.getGeneration(); StreamConfig newConfig = new StreamConfig(streamConfig.getName(), streamConfig.getPartitionDuration(), streamConfig.getIndexInterval(), newTTL, streamConfig.getLocation()); saveConfig(newConfig); resultFuture.set(new StreamProperty(currentGeneration, newTTL)); } catch (IOException e) { resultFuture.setException(e); } } }); return resultFuture; } }), new Function<StreamProperty, Long>() { @Override public Long apply(StreamProperty property) { return property.getTTL(); } }); }
From source file:org.opendaylight.openflowplugin.impl.role.RoleManagerImpl.java
@Override public void onDeviceContextLevelUp(@CheckForNull final DeviceContext deviceContext) { LOG.debug("RoleManager called for device:{}", deviceContext.getPrimaryConnectionContext().getNodeId()); if (deviceContext.getDeviceState().getFeatures().getVersion() < OFConstants.OFP_VERSION_1_3) { // Roles are not supported before OF1.3, so move forward. deviceInitializationPhaseHandler.onDeviceContextLevelUp(deviceContext); return;/* w ww .jav a 2 s . c o m*/ } final RoleContext roleContext = new RoleContextImpl(deviceContext, entityOwnershipService, makeEntity(deviceContext.getDeviceState().getNodeId())); // if the device context gets closed (mostly on connection close), we would need to cleanup deviceContext.addDeviceContextClosedHandler(this); Verify.verify(contexts.putIfAbsent(roleContext.getEntity(), roleContext) == null, "RoleCtx for master Node {} is still not close.", deviceContext.getDeviceState().getNodeId()); final ListenableFuture<OfpRole> roleChangeFuture = roleContext.initialization(); final ListenableFuture<Void> initDeviceFuture = Futures.transform(roleChangeFuture, new AsyncFunction<OfpRole, Void>() { @Override public ListenableFuture<Void> apply(final OfpRole input) throws Exception { final ListenableFuture<Void> nextFuture; if (OfpRole.BECOMEMASTER.equals(input)) { LOG.debug("Node {} was initialized", deviceContext.getDeviceState().getNodeId()); nextFuture = DeviceInitializationUtils.initializeNodeInformation(deviceContext, switchFeaturesMandatory); } else { LOG.debug("Node {} we are not Master so we are going to finish.", deviceContext.getDeviceState().getNodeId()); nextFuture = Futures.immediateFuture(null); } return nextFuture; } }); Futures.addCallback(initDeviceFuture, new FutureCallback<Void>() { @Override public void onSuccess(final Void result) { LOG.debug("Initialization Node {} is done.", deviceContext.getDeviceState().getNodeId()); getRoleContextLevelUp(deviceContext); } @Override public void onFailure(final Throwable t) { LOG.warn("Unexpected error for Node {} initialization", deviceContext.getDeviceState().getNodeId(), t); deviceContext.close(); } }); }
From source file:co.cask.cdap.explore.client.AbstractExploreClient.java
@Override public ListenableFuture<Void> disableExploreStream(final Id.Stream stream) { ListenableFuture<ExploreExecutionResult> futureResults = getResultsFuture(new HandleProducer() { @Override/* w w w .j av a2s . c om*/ public QueryHandle getHandle() throws ExploreException, SQLException { return doDisableExploreStream(stream); } }); // Exceptions will be thrown in case of an error in the futureHandle return Futures.transform(futureResults, Functions.<Void>constant(null)); }
From source file:org.thingsboard.server.dao.plugin.BasePluginService.java
@Override public ListenableFuture<PluginMetaData> findPluginByIdAsync(PluginId pluginId) { validateId(pluginId, "Incorrect plugin id for search plugin request."); ListenableFuture<PluginMetaDataEntity> pluginEntity = pluginDao.findByIdAsync(pluginId.getId()); return Futures.transform(pluginEntity, (com.google.common.base.Function<? super PluginMetaDataEntity, ? extends PluginMetaData>) input -> getData( input));/*from w w w . ja va 2 s . co m*/ }