List of usage examples for com.google.common.util.concurrent Futures immediateFailedFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFailedFuture(Throwable throwable)
From source file:com.spotify.folsom.retry.RetryingClient.java
@Override public <T> ListenableFuture<T> send(final Request<T> request) { final ListenableFuture<T> future = delegate.send(request); return Futures.catchingAsync(future, MemcacheClosedException.class, new AsyncFunction<MemcacheClosedException, T>() { @Override/*from w w w.j a va 2s . c om*/ public ListenableFuture<T> apply(final MemcacheClosedException e) { if (delegate.isConnected()) { return delegate.send(request); } else { return Futures.immediateFailedFuture(e); } } }); }
From source file:zipkin.storage.cassandra.CassandraDependenciesWriter.java
ListenableFuture<?> storeDependencies(long epochDayMillis, ByteBuffer dependencies) { Date startFlooredToDay = new Date(epochDayMillis); try {//from w w w. j a v a 2 s . co m BoundStatement bound = CassandraUtil.bindWithName(insertDependencies, "insert-dependencies") .setTimestamp("day", startFlooredToDay).setBytes("dependencies", dependencies); return session.executeAsync(bound); } catch (RuntimeException ex) { return Futures.immediateFailedFuture(ex); } }
From source file:org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataTreeShardThreePhaseCommitCohort.java
@SuppressWarnings("checkstyle:IllegalCatch") @Override/*from w w w .j a v a 2s. co m*/ public ListenableFuture<Boolean> canCommit() { try { dataTree.validate(modification); LOG.debug("DataTreeModification {} validated", modification); return CAN_COMMIT_FUTURE; } catch (DataValidationFailedException e) { LOG.warn("Data validation failed for {}", modification); LOG.trace("dataTree : {}", dataTree); return Futures.immediateFailedFuture( new TransactionCommitFailedException("Data did not pass validation.", e)); } catch (Exception e) { LOG.warn("Unexpected failure in validation phase", e); return Futures.immediateFailedFuture(e); } }
From source file:com.google.gapid.models.Capture.java
@Override protected ListenableFuture<Path.Capture> doLoad(File file) { if (file.length() == 0) { return Futures.immediateFailedFuture(new Exception("Trace file is empty!")); }/*from w w w . jav a 2 s . co m*/ String canonicalPath; try { File canonicalFile = file.getCanonicalFile(); canonicalPath = canonicalFile.getAbsolutePath(); if (canonicalFile.getParentFile() != null) { settings.lastOpenDir = canonicalFile.getParentFile().getAbsolutePath(); } } catch (IOException e) { if (file.getParentFile() != null) { settings.lastOpenDir = file.getParentFile().getAbsolutePath(); } return Futures.immediateFailedFuture(new Exception("Failed to load trace!", e)); } settings.addToRecent(canonicalPath); return client.loadCapture(canonicalPath); }
From source file:io.v.android.security.BlessingsManager.java
/** * Returns a new {@link ListenableFuture} whose result are the {@link Blessings} found in * {@link SharedPreferences} under the given key. * <p>/*from w w w. ja v a 2 s . com*/ * If no {@link Blessings} are found, mints a new set of {@link Blessings} and stores them * in {@link SharedPreferences} under the provided key. * <p> * This method may start an activity to handle the creation of new blessings, if needed. * Hence, you should be prepared that your activity may be stopped and re-started. * <p> * This method is re-entrant: if blessings need to be minted, multiple concurrent invocations * of this method will result in only the last invocation's future ever being invoked. This * means that it's safe to call this method from any of the android's lifecycle methods * (e.g., onCreate(), onStart(), onResume()). * <p> * This method must be invoked on the UI thread. * * @param context Vanadium context * @param activity android {@link Activity} requesting blessings * @param key a key under which the blessings are stored * @param setAsDefault if true, the returned {@link Blessings} will be set as default * blessings for the app * @return a new {@link ListenableFuture} whose result are the blessings * persisted under the given key */ public static ListenableFuture<Blessings> getBlessings(VContext context, final Activity activity, String key, boolean setAsDefault) { if (Looper.myLooper() != Looper.getMainLooper()) { return Futures .immediateFailedFuture(new VException("getBlessings() must be invoked " + "on the UI thread")); } try { Blessings blessings = readBlessings(context, activity, key, setAsDefault); if (blessings != null) { return Futures.immediateFuture(blessings); } } catch (VException e) { Log.e(TAG, "Malformed blessings in SharedPreferences. Minting new blessings: " + e.getMessage()); } return mintBlessings(context, activity, key, setAsDefault); }
From source file:org.thingsboard.server.service.script.AbstractJsInvokeService.java
@Override public ListenableFuture<Void> release(UUID scriptId) { String functionName = scriptIdToNameMap.get(scriptId); if (functionName != null) { try {//from w w w .j a v a 2 s . co m scriptIdToNameMap.remove(scriptId); blackListedFunctions.remove(scriptId); doRelease(scriptId, functionName); } catch (Exception e) { return Futures.immediateFailedFuture(e); } } return Futures.immediateFuture(null); }
From source file:com.orangerhymelabs.helenus.cassandra.table.TableService.java
public ListenableFuture<Table> create(Table table) { ListenableFuture<Boolean> dbFuture = databases.exists(table.databaseName()); return Futures.transformAsync(dbFuture, new AsyncFunction<Boolean, Table>() { @Override/*from ww w.j av a 2 s . c o m*/ public ListenableFuture<Table> apply(Boolean exists) throws Exception { if (exists) { try { ValidationEngine.validateAndThrow(table); return tables.create(table); } catch (ValidationException e) { return Futures.immediateFailedFuture(e); } } else { return Futures.immediateFailedFuture( new ItemNotFoundException("Database not found: " + table.databaseName())); } } }, MoreExecutors.directExecutor()); }
From source file:com.google.cloud.bigtable.grpc.async.RetryingRpcFutureFallback.java
@Override public ListenableFuture<ResponseT> create(Throwable t) throws Exception { if (t instanceof StatusRuntimeException) { StatusRuntimeException statusException = (StatusRuntimeException) t; Status.Code code = statusException.getStatus().getCode(); if (retryOptions.isRetryableRead(code)) { return backOffAndRetry(t); }/*from w ww. jav a 2s . co m*/ } return Futures.immediateFailedFuture(t); }
From source file:io.crate.executor.FetchedRowsPageableTaskResult.java
/** * Simply get a new TaskResult with the same backingArray with the new pageInfo on it. *//*from www . ja v a 2s . com*/ @Override public ListenableFuture<PageableTaskResult> fetch(PageInfo pageInfo) { if (backingArrayStartIdx + pageInfo.position() > backingArray.size()) { return Futures.immediateFailedFuture(new NoSuchElementException("backingArray exceeded")); } return Futures.<PageableTaskResult>immediateFuture( new FetchedRowsPageableTaskResult(backingArray, backingArrayStartIdx, pageInfo)); }
From source file:org.thingsboard.server.service.script.AbstractNashornJsInvokeService.java
@Override protected ListenableFuture<UUID> doEval(UUID scriptId, String functionName, String jsScript) { try {// ww w .j a va2 s . c om if (useJsSandbox()) { sandbox.eval(jsScript); } else { engine.eval(jsScript); } scriptIdToNameMap.put(scriptId, functionName); } catch (Exception e) { log.warn("Failed to compile JS script: {}", e.getMessage(), e); return Futures.immediateFailedFuture(e); } return Futures.immediateFuture(scriptId); }