List of usage examples for com.google.common.util.concurrent SettableFuture setException
@Override public boolean setException(Throwable throwable)
From source file:com.google.devtools.build.lib.buildeventservice.client.BuildEventServiceGrpcClient.java
private StreamObserver<PublishBuildToolEventStreamRequest> createStream( final Function<PublishBuildToolEventStreamResponse, Void> ack, final SettableFuture<Status> streamFinished) throws InterruptedException { try {/* w w w. jav a 2 s.c o m*/ return besAsync.publishBuildToolEventStream(new StreamObserver<PublishBuildToolEventStreamResponse>() { @Override public void onNext(PublishBuildToolEventStreamResponse response) { ack.apply(response); } @Override public void onError(Throwable t) { streamReference.set(null); streamFinished.setException(t); } @Override public void onCompleted() { streamReference.set(null); streamFinished.set(Status.OK); } }); } catch (StatusRuntimeException e) { Throwable rootCause = Throwables.getRootCause(e); Throwables.throwIfInstanceOf(rootCause, InterruptedException.class); throw e; } }
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 www. ja va 2s . co 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:com.continuuity.loom.common.zookeeper.ZKClientExt.java
/** * Acts as {@link ZKClient#create(String, byte[], org.apache.zookeeper.CreateMode, boolean)} if node does not exist, * otherwise as {@link ZKClient#setData(String, byte[])}. *///w w w . j av a 2 s . c om public static ListenableFuture<SetResult> createOrSet(final ZKClient zkClient, final String path, @Nullable final byte[] data, final CreateMode createMode, final boolean createParent) { final SettableFuture<SetResult> resultFuture = SettableFuture.create(); final OperationFuture<String> createResult = zkClient.create(path, data, createMode, createParent); Futures.addCallback(createResult, new FutureCallback<String>() { private final FutureCallback<String> createCallback = this; @Override public void onSuccess(String result) { resultFuture.set(new SetResult(result, null)); } @Override public void onFailure(Throwable t) { if (causedBy(t, KeeperException.NodeExistsException.class)) { OperationFuture<Stat> setDataResult = zkClient.setData(path, data); Futures.addCallback(setDataResult, new FutureCallback<Stat>() { @Override public void onSuccess(Stat result) { resultFuture.set(new SetResult(null, result)); } @Override public void onFailure(Throwable t) { if (causedBy(t, KeeperException.NoNodeException.class)) { Futures.addCallback(zkClient.create(path, data, createMode, createParent), createCallback); return; } resultFuture.setException(t); } }); return; } resultFuture.setException(t); } }); return resultFuture; }
From source file:io.crate.autocomplete.InformationSchemaDataProvider.java
private ListenableFuture<List<String>> execute(String statement, Object[] args) { final SettableFuture<List<String>> result = SettableFuture.create(); transportAction.get().execute(new SQLRequest(statement, args), new ActionListener<SQLResponse>() { @Override/*ww w . ja v a 2s .c om*/ public void onResponse(SQLResponse response) { List<String> rows = new ArrayList<>(); for (Object[] objects : response.rows()) { rows.add((String) objects[0]); } result.set(rows); } @Override public void onFailure(Throwable e) { result.setException(e); } }); return result; }
From source file:com.twitter.heron.statemgr.zookeeper.curator.CuratorStateManager.java
protected ListenableFuture<Boolean> existNode(String path) { final SettableFuture<Boolean> result = SettableFuture.create(); try {/* w w w . j a va2 s . co 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:org.eclipse.scada.protocol.iec60870.client.Client.java
protected synchronized void handleOperationComplete(final SettableFuture<Void> result, final ChannelFuture future) { if (this.connectFuture != result) { // this should never happen return;//from ww w . j a va2 s . co m } this.connectFuture = null; try { future.get(); this.channel = future.channel(); fireConnected(); result.set(null); } catch (final InterruptedException | ExecutionException e) { fireDisconnected(e); result.setException(e); } }
From source file:com.magnet.yak.command.RegisterUserCmd.java
public ListenableFuture<RegisterUserCmdOutput> execAsync(final RegisterUserCmdInput input) { LOGGER.trace("apply : input={}", input); setup(input);//from w w w. j a va 2 s. com final SettableFuture<RegisterUserCmdOutput> future = SettableFuture.create(); final SettableFuture<Void> onAuth = SettableFuture.create(); final MMXMessageListener messageListener = new MMXMessageListenerImpl(input.getUsername(), mmxClient); final MMXConnectionListener connectionListener = new MMXConnectionListenerImpl(input.getUsername(), onAuth); Futures.addCallback(onAuth, new FutureCallback<Void>() { public void onFailure(Throwable t) { LOGGER.trace("onFailure : input={}", input, t); future.setException(t); } public void onSuccess(Void v) { LOGGER.trace("onSuccess : input={}", input); future.set(new RegisterUserCmdOutput(mmxClient, input.getUsername(), input.getPassword(), connectionListener, messageListener)); } }); ExecUtil.getService().submit(new Runnable() { public void run() { try { Log.setLoggable("test", 6); mmxClient.connect(input.getUsername(), input.getPassword().getBytes(), connectionListener, messageListener, false); } catch (MMXException e) { e.printStackTrace(); } } }); return future; }
From source file:org.opendaylight.netconf.topology.singleton.impl.tx.NetconfWriteOnlyTransaction.java
@Override public ListenableFuture<RpcResult<TransactionStatus>> commit() { LOG.trace("{}: Commit", id); final Future<Void> commit = delegate.submit(); final SettableFuture<RpcResult<TransactionStatus>> settFuture = SettableFuture.create(); commit.onComplete(new OnComplete<Void>() { @Override/*from w w w .j a v a 2s . c o m*/ public void onComplete(final Throwable throwable, final Void result) throws Throwable { if (throwable == null) { TransactionStatus status = TransactionStatus.SUBMITED; RpcResult<TransactionStatus> rpcResult = RpcResultBuilder.success(status).build(); settFuture.set(rpcResult); } else { settFuture.setException(throwable); } } }, actorSystem.dispatcher()); return settFuture; }
From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpBlobStore.java
@SuppressWarnings("FutureReturnValueIgnored") private ListenableFuture<Boolean> get(String key, final OutputStream out, boolean casDownload) { final AtomicBoolean dataWritten = new AtomicBoolean(); OutputStream wrappedOut = new OutputStream() { // OutputStream.close() does nothing, which is what we want to ensure that the // OutputStream can't be closed somewhere in the Netty pipeline, so that we can support // retries. The OutputStream is closed in the finally block below. @Override//from www . jav a2s.c o m public void write(byte[] b, int offset, int length) throws IOException { dataWritten.set(true); out.write(b, offset, length); } @Override public void write(int b) throws IOException { dataWritten.set(true); out.write(b); } @Override public void flush() throws IOException { out.flush(); } }; DownloadCommand download = new DownloadCommand(uri, casDownload, key, wrappedOut); SettableFuture<Boolean> outerF = SettableFuture.create(); acquireDownloadChannel().addListener((Future<Channel> chP) -> { if (!chP.isSuccess()) { outerF.setException(chP.cause()); return; } Channel ch = chP.getNow(); ch.writeAndFlush(download).addListener((f) -> { try { if (f.isSuccess()) { outerF.set(true); } else { Throwable cause = f.cause(); // cause can be of type HttpException, because Netty uses // Unsafe.throwException to // re-throw a checked exception that hasn't been declared in the method // signature. if (cause instanceof HttpException) { HttpResponse response = ((HttpException) cause).response(); if (!dataWritten.get() && authTokenExpired(response)) { // The error is due to an auth token having expired. Let's try // again. refreshCredentials(); getAfterCredentialRefresh(download, outerF); return; } else if (cacheMiss(response.status())) { outerF.set(false); return; } } outerF.setException(cause); } } finally { releaseDownloadChannel(ch); } }); }); return outerF; }
From source file:com.microsoft.services.odata.ODataMediaEntityFetcher.java
public ListenableFuture<byte[]> getContent() { final SettableFuture<byte[]> result = SettableFuture.create(); Request request = getResolver().createRequest(); request.setVerb(HttpVerb.GET);/*from w ww .j av a 2 s .c o m*/ ODataURL url = request.getUrl(); url.appendPathComponent("$value"); ListenableFuture<ODataResponse> future = oDataExecute(request); Futures.addCallback(future, new FutureCallback<ODataResponse>() { @Override public void onSuccess(ODataResponse response) { result.set(response.getPayload()); } @Override public void onFailure(Throwable t) { result.setException(t); } }); return result; }