List of usage examples for com.google.common.util.concurrent SettableFuture set
@Override public boolean set(@Nullable V value)
From source file:org.opendaylight.netconf.topology.impl.NetconfNodeOperationalDataAggregator.java
@Override public ListenableFuture<Void> combineDeleteAttempts(final List<ListenableFuture<Void>> stateFutures) { final SettableFuture<Void> future = SettableFuture.create(); final ListenableFuture<List<Void>> allAsList = Futures.allAsList(stateFutures); Futures.addCallback(allAsList, new FutureCallback<List<Void>>() { @Override//from ww w.j av a 2 s . c o m public void onSuccess(final List<Void> result) { future.set(null); } @Override public void onFailure(final Throwable t) { LOG.error("One of the combined delete attempts failed {}", t); future.setException(t); } }); return future; }
From source file:org.apache.helix.provisioning.yarn.RMCallbackHandler.java
@Override public void onContainersCompleted(List<ContainerStatus> completedContainers) { LOG.info("Got response from RM for container ask, completedCnt=" + completedContainers.size()); for (ContainerStatus containerStatus : completedContainers) { GenericApplicationMaster.LOG.info("Got container status for containerID=" + containerStatus.getContainerId() + ", state=" + containerStatus.getState() + ", exitStatus=" + containerStatus.getExitStatus() + ", diagnostics=" + containerStatus.getDiagnostics()); // non complete containers should not be here assert (containerStatus.getState() == ContainerState.COMPLETE); synchronized (_genericApplicationMaster.allocatedContainerSet) { _genericApplicationMaster.allocatedContainerSet.remove(containerStatus.getContainerId()); SettableFuture<ContainerStopResponse> stopResponseFuture = _genericApplicationMaster.containerStopMap .remove(containerStatus.getContainerId()); if (stopResponseFuture != null) { ContainerStopResponse value = new ContainerStopResponse(); stopResponseFuture.set(value); } else { SettableFuture<ContainerReleaseResponse> releaseResponseFuture = _genericApplicationMaster.containerReleaseMap .remove(containerStatus.getContainerId()); if (releaseResponseFuture != null) { ContainerReleaseResponse value = new ContainerReleaseResponse(); releaseResponseFuture.set(value); }/*from w w w. j a v a 2 s.co m*/ } } // increment counters for completed/failed containers int exitStatus = containerStatus.getExitStatus(); if (0 != exitStatus) { // container failed if (ContainerExitStatus.ABORTED != exitStatus) { } else { // container was killed by framework, possibly preempted // we should re-try as the container was lost for some reason // we do not need to release the container as it would be done // by the RM } } else { // nothing to do // container completed successfully GenericApplicationMaster.LOG.info( "Container completed successfully." + ", containerId=" + containerStatus.getContainerId()); } } }
From source file:com.twitter.heron.statemgr.zookeeper.curator.CuratorStateManager.java
protected ListenableFuture<Boolean> existNode(String path) { final SettableFuture<Boolean> result = SettableFuture.create(); try {/*from w w w.j ava 2s . c o m*/ LOG.info("Checking existence of path: " + path); result.set(client.checkExists().forPath(path) != null); // Suppress it since forPath() throws Exception // SUPPRESS CHECKSTYLE IllegalCatch } catch (Exception e) { result.setException(new RuntimeException("Could not check Exist", e)); } return result; }
From source file:com.microsoftopentechnologies.intellij.serviceexplorer.NodeActionListenerAsync.java
public ListenableFuture<Void> actionPerformedAsync(final NodeActionEvent actionEvent) { final SettableFuture<Void> future = SettableFuture.create(); ProgressManager.getInstance()//w ww .j ava 2s. c o m .run(new Task.Backgroundable(actionEvent.getAction().getNode().getProject(), progressMessage) { @Override public void run(@NotNull ProgressIndicator progressIndicator) { try { runInBackground(actionEvent); future.set(null); } catch (AzureCmdException e) { future.setException(e); } } }); return future; }
From source file:org.apache.qpid.server.model.AbstractConfiguredObjectTypeFactory.java
@Override public ListenableFuture<X> createAsync(final ConfiguredObjectFactory factory, final Map<String, Object> attributes, final ConfiguredObject<?> parent) { final SettableFuture<X> returnVal = SettableFuture.create(); final X instance = createInstance(attributes, parent); final ListenableFuture<Void> createFuture = instance.createAsync(); AbstractConfiguredObject.addFutureCallback(createFuture, new FutureCallback<Void>() { @Override//from w ww. j a va 2 s. co m public void onSuccess(final Void result) { returnVal.set(instance); } @Override public void onFailure(final Throwable t) { returnVal.setException(t); } }, MoreExecutors.directExecutor()); return returnVal; }
From source file:com.tinspx.util.net.Requests.java
/** * Wraps {@code delegate} in a {@code RequestContext} that will convert * successful responses that satisfy {@code failPredicate} to an error. Note * that converting the response to a failure only affects the status of the * response {@code ListenableFuture}, and has <i>no</i> effect on the * {@link RequestCallback} callback methods. *//*from w ww . j a v a 2 s.co m*/ public static RequestContext toFailure(final @NonNull AsyncFunction<? super Request, Response> delegate, final @NonNull Predicate<? super Response> failPredicate) { return new RequestContext() { @Override public ListenableFuture<Response> apply(Request request) throws Exception { ListenableFuture<Response> delegateFuture = delegate.apply(request); final SettableFuture<Response> future = SettableFuture.create(); Futures.addCallback(delegateFuture, new FutureCallback<Response>() { @Override public void onSuccess(Response result) { try { if (failPredicate.apply(result)) { result.onError(Errors.message("predicate failure: %s", failPredicate)); future.setException(new RequestException(result)); } else { future.set(result); } } catch (Throwable t) { //have to ensure the returned future always completes //even if the predicate or onError throws future.setException(new RequestException(result, t)); //guava Futures should log this throw Throwables.propagate(t); } } @Override public void onFailure(Throwable t) { future.setException(t); } }); FutureUtils.linkFailure(future, delegateFuture, false); return future; } }; }
From source file:org.opendaylight.aaa.cert.impl.AaaCertRpcServiceImpl.java
@Override public Future<RpcResult<GetODLCertificateOutput>> getODLCertificate() { final SettableFuture<RpcResult<GetODLCertificateOutput>> futureResult = SettableFuture.create(); final String cert = aaaCertProvider.getODLKeyStoreCertificate(false); if (cert != null && !cert.isEmpty()) { final GetODLCertificateOutput odlCertOutput = new GetODLCertificateOutputBuilder().setOdlCert(cert) .build();//from www .ja v a 2s .com futureResult.set(RpcResultBuilder.<GetODLCertificateOutput>success(odlCertOutput).build()); } else { futureResult.set(RpcResultBuilder.<GetODLCertificateOutput>failed().build()); } return futureResult; }
From source file:com.continuuity.loom.common.zookeeper.LeaderElection.java
private void doDeleteNode(final SettableFuture<String> completion) { if (zkNodePath == null) { completion.set(null); }/*from ww w . j a v a 2 s . c om*/ try { Futures.addCallback(zkClient.delete(zkNodePath), new FutureCallback<String>() { @Override public void onSuccess(String result) { LOG.debug("Node deleted: {}", result); completion.set(result); } @Override public void onFailure(Throwable t) { LOG.warn("Fail to delete node: {}", zkNodePath); if (!(t instanceof KeeperException.NoNodeException)) { LOG.debug("Retry delete node: {}", zkNodePath); doDeleteNode(completion); } else { completion.setException(t); } } }, executor); } catch (Throwable t) { // If any exception happens when calling delete, treats it as completed with failure. completion.setException(t); } }
From source file:org.onosproject.incubator.store.virtual.impl.SimpleVirtualFlowRuleStore.java
@Override public void batchOperationComplete(NetworkId networkId, FlowRuleBatchEvent event) { final Long batchId = event.subject().batchId(); SettableFuture<CompletedBatchOperation> future = pendingFutures.getIfPresent(batchId); if (future != null) { future.set(event.result()); pendingFutures.invalidate(batchId); }/*from w ww .j a v a 2 s . c o m*/ notifyDelegate(networkId, event); }
From source file:org.opendaylight.controller.cluster.schema.provider.impl.RemoteSchemaProvider.java
@Override public CheckedFuture<YangTextSchemaSource, SchemaSourceException> getSource(SourceIdentifier sourceIdentifier) { LOG.trace("Getting yang schema source for {}", sourceIdentifier.getName()); Future<YangTextSchemaSourceSerializationProxy> result = remoteRepo .getYangTextSchemaSource(sourceIdentifier); final SettableFuture<YangTextSchemaSource> res = SettableFuture.create(); result.onComplete(new OnComplete<YangTextSchemaSourceSerializationProxy>() { @Override/* ww w . ja v a2 s .c o m*/ public void onComplete(Throwable throwable, YangTextSchemaSourceSerializationProxy yangTextSchemaSourceSerializationProxy) { if (yangTextSchemaSourceSerializationProxy != null) { res.set(yangTextSchemaSourceSerializationProxy.getRepresentation()); } if (throwable != null) { res.setException(throwable); } } }, executionContext); return Futures.makeChecked(res, MAPPER); }