List of usage examples for com.google.common.util.concurrent Futures immediateFailedFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFailedFuture(Throwable throwable)
From source file:org.esbtools.eventhandler.lightblue.UnparseableDocumentEvent.java
@Override public Future<?> lookupDocument() { return Futures.immediateFailedFuture(exception); }
From source file:com.google.devtools.kythe.platform.shared.FileDataDirectory.java
@Override public Future<byte[]> startLookup(String path, String digest) { try {/* ww w. ja va 2s. c om*/ return Futures.immediateFuture(Files.asByteSource(new File(PathUtil.join(rootDirectory, path))).read()); } catch (Throwable t) { return Futures.immediateFailedFuture(t); } }
From source file:org.thingsboard.rule.engine.util.EntitiesRelatedEntityIdAsyncLoader.java
public static ListenableFuture<EntityId> findEntityAsync(TbContext ctx, EntityId originator, RelationsQuery relationsQuery) { RelationService relationService = ctx.getRelationService(); EntityRelationsQuery query = buildQuery(originator, relationsQuery); ListenableFuture<List<EntityRelation>> asyncRelation = relationService.findByQuery(ctx.getTenantId(), query);//from w w w .j a v a 2 s. c om if (relationsQuery.getDirection() == EntitySearchDirection.FROM) { return Futures.transformAsync(asyncRelation, r -> CollectionUtils.isNotEmpty(r) ? Futures.immediateFuture(r.get(0).getTo()) : Futures.immediateFuture(null)); } else if (relationsQuery.getDirection() == EntitySearchDirection.TO) { return Futures.transformAsync(asyncRelation, r -> CollectionUtils.isNotEmpty(r) ? Futures.immediateFuture(r.get(0).getFrom()) : Futures.immediateFuture(null)); } return Futures.immediateFailedFuture(new IllegalStateException("Unknown direction")); }
From source file:com.spotify.folsom.client.NotConnectedClient.java
private <T> ListenableFuture<T> fail() { return Futures.immediateFailedFuture(new MemcacheClosedException("Not connected")); }
From source file:com.sk89q.worldguard.protection.databases.AbstractProtectionDatabase.java
@Override public ListenableFuture<?> load(RegionManager manager, boolean async) { try {/*from ww w .j a va 2 s . c om*/ load(manager); } catch (ProtectionDatabaseException e) { return Futures.immediateFailedFuture(e); } return Futures.immediateCheckedFuture(this); }
From source file:org.esbtools.eventhandler.lightblue.UnparseableNotification.java
@Override public Future<Collection<DocumentEvent>> toDocumentEvents() { return Futures.immediateFailedFuture(exception); }
From source file:google.registry.testing.ForwardingURLFetchService.java
@Override public Future<HTTPResponse> fetchAsync(HTTPRequest request) { try {//from w ww. j av a 2 s . c o m return Futures.immediateFuture(fetch(request)); } catch (Exception e) { return Futures.immediateFailedFuture(e); } }
From source file:io.v.android.impl.google.services.beam.VBeamServer.java
@Override public synchronized ListenableFuture<GetIntentOut> getIntent(VContext ctx, ServerCall call, String secret) { evictStaleRequests();/*from www . j av a 2 s . c o m*/ if (requestMap.remove(secret) != null) { try { return Futures.transform(callback.createIntent(ctx, call), new AsyncFunction<Pair<String, byte[]>, GetIntentOut>() { @Override public ListenableFuture<GetIntentOut> apply(Pair<String, byte[]> input) throws Exception { return convertIntent(input); } }); } catch (Throwable t) { return Futures.immediateFailedFuture(t); } } return Futures.immediateFailedFuture(new VException("Bad request")); }
From source file:org.opendaylight.openflowplugin.api.openflow.OFPContext.java
/** * About to stop services in cluster not master anymore or going down * @return Future most of services need time to be closed * @param deviceDisconnected true if clustering services stopping by device disconnect *//*from w ww .jav a 2s .c o m*/ default ListenableFuture<Void> stopClusterServices(final boolean deviceDisconnected) { return Futures.immediateFailedFuture(new RejectedExecutionException( "Cannot stop abstract services, check implementation of cluster services")); }
From source file:io.v.impl.google.lib.discovery.DiscoveryImpl.java
@Override public ListenableFuture<Void> advertise(VContext ctx, Advertisement ad, List<BlessingPattern> visibility) throws VException { ListenableFutureCallback<Void> cb = new ListenableFutureCallback<>(); nativeAdvertise(nativeRef, ctx, ad, visibility, cb); return Futures.withFallback(cb.getFuture(ctx), new FutureFallback<Void>() { public ListenableFuture<Void> create(Throwable t) { if (t instanceof CancellationException) { return Futures.immediateFuture(null); }/* ww w.ja v a 2 s . c om*/ return Futures.immediateFailedFuture(t); } }); }