List of usage examples for com.google.common.util.concurrent SettableFuture setException
@Override public boolean setException(Throwable throwable)
From source file:io.crate.executor.transport.task.elasticsearch.ESDeleteByQueryTask.java
public ESDeleteByQueryTask(UUID jobId, ESDeleteByQueryNode node, TransportDeleteByQueryAction transport, JobContextService jobContextService) { super(jobId, node.executionPhaseId(), node.whereClauses().size(), jobContextService); List<DeleteByQueryRequest> requests = new ArrayList<>(node.whereClauses().size()); List<ActionListener> listeners = new ArrayList<>(node.whereClauses().size()); for (int i = 0; i < node.whereClauses().size(); i++) { DeleteByQueryRequest request = new DeleteByQueryRequest(); SettableFuture<TaskResult> result = SettableFuture.create(); String[] indices = node.indices().get(i); WhereClause whereClause = node.whereClauses().get(i); String routing = node.routings().get(i); try {//from w w w. ja va2 s. com request.source(QUERY_BUILDER.convert(whereClause)); request.indices(indices); if (whereClause.clusteredBy().isPresent()) { request.routing(routing); } } catch (IOException e) { result.setException(e); } results.add(result); requests.add(request); listeners.add(new Listener(result)); } createContext("delete by query", requests, listeners, transport, null); }
From source file:co.cask.cdap.internal.app.runtime.workflow.AbstractProgramWorkflowRunner.java
/** * Adds a listener to the {@link ProgramController} and blocks for completion. * * @param controller the {@link ProgramController} for the program * @param context the {@link RuntimeContext} * @return {@link RuntimeContext} of the completed program * @throws Exception if the execution failed *//*from ww w . j a va2s . c o m*/ protected RuntimeContext executeProgram(final ProgramController controller, final RuntimeContext context) throws Exception { // Execute the program. final SettableFuture<RuntimeContext> completion = SettableFuture.create(); controller.addListener(new AbstractListener() { @Override public void completed() { completion.set(context); } @Override public void killed() { completion.set(context); } @Override public void error(Throwable cause) { completion.setException(cause); } }, Threads.SAME_THREAD_EXECUTOR); // Block for completion. try { return completion.get(); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof Exception) { throw (Exception) cause; } throw Throwables.propagate(cause); } catch (InterruptedException e) { try { Futures.getUnchecked(controller.stop()); } catch (Throwable t) { // no-op } // reset the interrupt Thread.currentThread().interrupt(); return null; } }
From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpBlobStore.java
@SuppressWarnings("FutureReturnValueIgnored") private void getAfterCredentialRefresh(DownloadCommand cmd, SettableFuture<Boolean> outerF) { acquireDownloadChannel().addListener((Future<Channel> chP) -> { if (!chP.isSuccess()) { outerF.setException(chP.cause()); return; }/*from www. jav a 2 s . c o m*/ Channel ch = chP.getNow(); ch.writeAndFlush(cmd).addListener((f) -> { try { if (f.isSuccess()) { outerF.set(true); } else { Throwable cause = f.cause(); if (cause instanceof HttpException) { HttpResponse response = ((HttpException) cause).response(); if (cacheMiss(response.status())) { outerF.set(false); return; } } outerF.setException(cause); } } finally { releaseDownloadChannel(ch); } }); }); }
From source file:com.microsoft.assetmanagement.files.SharepointListsClientWithFiles.java
/** * Gets the file./*from www . ja v a 2s. c om*/ * * @param listName * the list name * @param itemId * the item id * @param fileClient * the file Client * @return the file */ public ListenableFuture<DocumentLibraryItem> getFileFromDocumentLibrary(final String listName, final String itemId, final FileClient fileClient) { final SettableFuture<DocumentLibraryItem> result = SettableFuture.create(); ListenableFuture<SPFile> picture = getSPFileFromPictureLibrary(listName, itemId); Futures.addCallback(picture, new FutureCallback<SPFile>() { @Override public void onFailure(Throwable t) { result.setException(t); } @Override public void onSuccess(SPFile spFile) { // TODO:Review if we can use chaining. ListenableFuture<byte[]> file = fileClient.getFile(spFile.getData("Name").toString(), listName); Futures.addCallback(file, new FutureCallback<byte[]>() { @Override public void onFailure(Throwable t) { result.setException(t); }; @Override public void onSuccess(byte[] payload) { result.set(new DocumentLibraryItem(payload, itemId)); } }); } }); return result; }
From source file:com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncTable.java
private void insertInternal(JsonObject json, final SettableFuture<E> finalFuture) { ListenableFuture<JsonObject> internalFuture = mInternalTable.insert(json); Futures.addCallback(internalFuture, new FutureCallback<JsonObject>() { @Override//from w ww .j a v a 2s.c o m public void onFailure(Throwable throwable) { finalFuture.setException(throwable); } @Override public void onSuccess(JsonObject result) { finalFuture.set(parseResults(result).get(0)); } }); }
From source file:org.apache.omid.transaction.HBaseSyncPostCommitter.java
@Override public ListenableFuture<Void> removeCommitTableEntry(AbstractTransaction<? extends CellId> transaction) { SettableFuture<Void> updateSCFuture = SettableFuture.create(); HBaseTransaction tx = HBaseTransactionManager.enforceHBaseTransactionAsParam(transaction); commitTableUpdateTimer.start();//from w w w . j a v a 2s .co m try { commitTableClient.completeTransaction(tx.getStartTimestamp()).get(); updateSCFuture.set(null); } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOG.warn("{}: interrupted during commit table entry delete", tx, e); updateSCFuture.setException( new TransactionManagerException(tx + ": interrupted during commit table entry delete")); } catch (ExecutionException e) { LOG.warn("{}: can't remove commit table entry", tx, e); updateSCFuture.setException(new TransactionManagerException(tx + ": can't remove commit table entry")); } finally { commitTableUpdateTimer.stop(); } return updateSCFuture; }
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// w w w . ja va 2s . com 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); }
From source file:org.apache.hadoop.hive.ql.exec.tez.WmTezSession.java
public ListenableFuture<WmTezSession> waitForAmRegistryAsync(int timeoutMs, ScheduledExecutorService timeoutPool) { SettableFuture<WmTezSession> future = SettableFuture.create(); synchronized (amPluginInfoLock) { if (amPluginInfo != null) { future.set(this); return future; }/* w ww .j a v a2 s . c o m*/ if (amRegistryFuture != null) { // We don't need this for now, so do not support it. future.setException(new RuntimeException("Multiple waits are not suported")); return future; } amRegistryFuture = future; if (timeoutMs <= 0) return future; // TODO: replace with withTimeout after we get the relevant guava upgrade. this.timeoutTimer = timeoutPool.schedule(new TimeoutRunnable(), timeoutMs, TimeUnit.MILLISECONDS); } return future; }
From source file:co.cask.cdap.internal.app.runtime.AbstractProgramController.java
/** * Force this controller into error state. * @param t The/*from w w w.j a v a 2s .com*/ */ protected final <V> void error(Throwable t, SettableFuture<V> future) { failureCause = t; state.set(State.ERROR); if (future != null) { future.setException(t); } caller.error(t); }
From source file:com.microsoft.tooling.msservices.serviceexplorer.NodeActionListenerAsync.java
public ListenableFuture<Void> actionPerformedAsync(final NodeActionEvent actionEvent) { Callable<Boolean> booleanCallable = beforeAsyncActionPerfomed(); boolean shouldRun = true; try {/* w ww. j av a 2s .c o m*/ shouldRun = booleanCallable.call(); } catch (Exception ignored) { } final SettableFuture<Void> future = SettableFuture.create(); if (shouldRun) { DefaultLoader.getIdeHelper().runInBackground(actionEvent.getAction().getNode().getProject(), progressMessage, true, false, null, new Runnable() { @Override public void run() { try { actionPerformed(actionEvent); future.set(null); } catch (AzureCmdException e) { future.setException(e); } } }); } else { future.set(null); } return future; }