List of usage examples for com.google.common.util.concurrent SettableFuture setException
@Override public boolean setException(Throwable throwable)
From source file:io.v.android.security.BlessingsManager.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CODE_MINT_BLESSINGS: { if (mintFuture == null) { // shouldn't really happen break; }// w w w . j av a2 s . c o m SettableFuture<Blessings> future = mintFuture; mintFuture = null; // Extract VOM-encoded blessings. if (data == null) { future.setException(new VException("NULL blessing response")); break; } if (resultCode != Activity.RESULT_OK) { future.setException(new VException( "Error getting blessing: " + data.getStringExtra(BlessingActivity.EXTRA_ERROR))); break; } byte[] blessingsVom = data.getByteArrayExtra(BlessingActivity.EXTRA_REPLY); if (blessingsVom == null || blessingsVom.length <= 0) { future.setException(new VException("Got null blessings.")); break; } // VOM-Decode blessings. try { Blessings blessings = (Blessings) VomUtil.decode(blessingsVom, Blessings.class); future.set(blessings); } catch (VException e) { future.setException(e); } break; } } // Remove this fragment from the invoking activity. FragmentTransaction transaction = getActivity().getFragmentManager().beginTransaction(); transaction.remove(this); transaction.commit(); super.onActivityResult(requestCode, resultCode, data); }
From source file:com.blacklocus.jres.JresBulkRequestor.java
private void indexNextBatch() throws InterruptedException { List<JresBulkable> bulk = new ArrayList<JresBulkable>(batchSize); List<SettableFuture<JresBulkItemResult>> futures = new ArrayList<SettableFuture<JresBulkItemResult>>( batchSize);/*w w w . java2 s . c om*/ int numDocs = 0; FuturedDocument futuredDocument; // Poll with a long-enough timeout to promote batch aggregation, but not so long as to keep things in limbo // for a long time. while (numDocs < batchSize && null != (futuredDocument = poll())) { futures.add(futuredDocument.future); bulk.add(futuredDocument.bulkable); ++numDocs; } if (bulk.size() > 0) { assert numDocs > 0; LOG.info("Submitting bulk index of " + numDocs + " products."); if (LOG.isDebugEnabled()) { LOG.debug(bulk.toString()); } JresBulkReply bulkReply = jres.quest(new JresBulk(targetIndex, targetType, bulk)); List<JresBulkItemResult> results = Lists.newArrayList(bulkReply.getResults()); assert futures.size() == results.size(); for (int i = 0; i < results.size(); i++) { SettableFuture<JresBulkItemResult> future = futures.get(i); JresBulkItemResult result = results.get(i); if (result.getResult().hasError()) { future.setException(new RuntimeException(result.getResult().getError())); } else { future.set(result); } } } else { // reading too hard, sleep a bit Thread.sleep(sleepIntervalMs); } }
From source file:com.sam.moca.async.LocalAsynchronousExecutor.java
@Override public <V> Future<V> executeAsynchronously(Callable<V> callable) { SettableFuture<V> future = SettableFuture.create(); ServerContext contextNullable = ServerUtils.getCurrentContextNullable(); try {//www .j a v a 2 s . co m V value = callable.call(); future.set(value); if (contextNullable != null) { contextNullable.commit(); } } catch (Throwable e) { future.setException(e); if (contextNullable != null) { try { contextNullable.rollback(); } catch (MocaException e1) { _logger.warn("There was a problem rolling back transaction " + "for executing " + callable + " when it failed!"); } } } return future; }
From source file:com.canoo.dolphin.server.context.DolphinContextTaskQueue.java
public Future<Void> addTask(final Runnable task) { Assert.requireNonNull(task, "task"); taskLock.lock();/* w ww . j a v a 2 s . c om*/ try { final SettableFuture<Void> future = SettableFuture.create(); tasks.add(new Runnable() { @Override public void run() { try { task.run(); future.set(null); } catch (Exception e) { future.setException(e); } } }); LOG.trace("Tasks added to Dolphin Platform context {}", dolphinSessionId); taskCondition.signal(); return future; } finally { taskLock.unlock(); } }
From source file:eu.esdihumboldt.hale.common.headless.transform.Transformation.java
private static void failure(SettableFuture<Boolean> result, IJobChangeEvent event) { // signal if was canceled /*// www. j a v a 2 s . c o m * XXX disabled as the transform job will cancel the export job if it * fails */ // if (event.getResult().matches(IStatus.CANCEL)) { // result.cancel(false); // } String jobName = event.getJob() != null ? event.getJob().getName() : "unknown"; String msg = "Error occured in job \"" + jobName + "\""; if (event.getResult() != null && event.getResult().getMessage() != null) { msg = msg + ": " + event.getResult().getMessage(); } // try setting exception if (event.getResult() != null && event.getResult().getException() != null) { log.error(msg, event.getResult().getException()); if (!result.setException(event.getResult().getException())) { log.error("Exception could not be set on future (already completed or cancelled)"); } return; } log.error(msg); // in case there was no exception or setting it failed, just state that // execution was not successful if (!result.set(false)) { log.error("Failure could not be set on future (already completed or cancelled)"); } }
From source file:org.apache.hadoop.hive.ql.exec.tez.SampleTezSessionState.java
@Override public SettableFuture<WmTezSession> waitForAmRegistryAsync(int timeoutMs, ScheduledExecutorService timeoutPool) { final SampleTezSessionState session = this; final SettableFuture<WmTezSession> future = SettableFuture.create(); Futures.addCallback(waitForAmRegFuture, new FutureCallback<Boolean>() { @Override//w w w . jav a 2 s.co m public void onSuccess(Boolean result) { future.set(session); } @Override public void onFailure(Throwable t) { future.setException(t); } }); return future; }
From source file:c5db.replication.C5GeneralizedReplicator.java
/** * This method assumes that the receiptFuture is "done". If the future is set with a value, * return its value, the ReplicatorReceipt. On the other hand, if it is an exception, set * the completionFuture with that exception and return null. A null return value guarantees * the completionFuture has been set with an exception. *//* www. j a v a 2 s . co m*/ @Nullable private ReplicatorReceipt getReceiptOrSetException(ReceiptWithCompletionFuture receiptWithCompletionFuture) { ListenableFuture<ReplicatorReceipt> receiptFuture = receiptWithCompletionFuture.receiptFuture; SettableFuture<?> completionFuture = receiptWithCompletionFuture.completionFuture; assert receiptFuture.isDone(); try { ReplicatorReceipt receipt = C5Futures.getUninterruptibly(receiptFuture); if (receipt == null) { completionFuture.setException(new IOException("replicator returned a null receipt")); } return receipt; } catch (ExecutionException e) { completionFuture.setException(e); return null; } }
From source file:org.anhonesteffort.chnlbrkr.stream.ChannelRequestHandler.java
public ChannelRequestHandler(SettableFuture<ChannelRequestHandler> future, ChannelRequest.Reader request, String chnlzrId, long timeoutMs) { this.future = future; this.request = request; this.chnlzrId = chnlzrId; this.timeoutMs = timeoutMs; timeoutTask = new TimerTask() { @Override/*from w w w . j a v a2 s . c o m*/ public void run() { if (future.setException( new TimeoutException(chnlzrId + " chnlzr request response timeout exceeded"))) { context.close(); } } }; }
From source file:org.retrostore.android.net.DataFetcher.java
/** * Turn the synchronous API requests into an asynchronous one and return a listenable future * with the result./*from ww w . ja va 2s . com*/ */ public ListenableFuture<List<App>> getAppsAsync() { final SettableFuture<List<App>> future = SettableFuture.create(); mRequestExecutor.execute(new Runnable() { @Override public void run() { try { List<App> apps = mClient.fetchApps(0, 100); updateCache(apps); future.set(apps); } catch (ApiException e) { future.setException(e); } } }); return future; }
From source file:org.pentaho.osgi.bridge.KarafCapability.java
@Override public Future<Boolean> install() { SettableFuture<Boolean> installFuture = SettableFuture.<Boolean>create(); try {/*from w w w . jav a 2 s .c o m*/ manager.watchForInstall(feature, installFuture); featuresService.installFeature(feature, EnumSet.noneOf(FeaturesService.Option.class)); } catch (Exception e) { logger.error("Unknown error installing feature", e); installFuture.set(false); installFuture.setException(e); } return installFuture; }