List of usage examples for com.google.common.util.concurrent Futures immediateFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFuture(@Nullable V value)
From source file:producerstest.SimpleProducerModule.java
@Produces @Qual(5)/* w ww .ja v a 2 s .com*/ @SuppressWarnings("unused") // unthrown exception for test static ListenableFuture<String> futureStrThrowingException() throws IOException { return Futures.immediateFuture("future str throwing exception"); }
From source file:io.crate.executor.SinglePageTaskResult.java
@Override public ListenableFuture<PageableTaskResult> fetch(PageInfo pageInfo) { return Futures.immediateFuture(PageableTaskResult.EMPTY_PAGABLE_RESULT); }
From source file:producerstest.multibindings.MultibindingProducerModule.java
@Produces @IntoMap @IntKey(42) static ListenableFuture<String> futureFor42() { return Futures.immediateFuture("forty two"); }
From source file:itx.opendaylight.examples.cluster.demoakka.impl.ODLClusterSingleton.java
@Override public ListenableFuture<Void> closeServiceInstance() { LOG.info("We lost Leadership"); isLeader.set(false); return Futures.immediateFuture(null); }
From source file:com.eviware.loadui.util.BeanInjector.java
@Nonnull public static <T> ListenableFuture<T> getBeanFuture(@Nonnull final Class<T> cls) { Object cachedObject = INSTANCE.beanCache.getIfPresent(cls); if (cachedObject != null) { return Futures.immediateFuture(cls.cast(cachedObject)); } else {// www .ja v a 2 s. co m return new BeanFuture<>(cls); } }
From source file:com.facebook.buck.parser.PipelineNodeCache.java
/** * Helper for de-duping jobs against the cache. * * @param jobSupplier a supplier to use to create the actual job. * @return future describing the job. It can either be an immediate future (result cache hit), * ongoing job (job cache hit) or a new job (miss). *//* w w w.j a va 2 s .com*/ protected final ListenableFuture<T> getJobWithCacheLookup(final Cell cell, final K key, JobSupplier<T> jobSupplier) throws BuildTargetException { Optional<T> cacheLookupResult = cache.lookupComputedNode(cell, key); if (cacheLookupResult.isPresent()) { return Futures.immediateFuture(cacheLookupResult.get()); } ListenableFuture<T> speculativeCacheLookupResult = jobsCache.get(key); if (speculativeCacheLookupResult != null) { return speculativeCacheLookupResult; } // We use a SettableFuture to resolve any races between threads that are trying to create the // job for the given key. The SettableFuture is cheap to throw away in case we didn't "win" and // can be easily "connected" to a future that actually does work in case we did. SettableFuture<T> resultFutureCandidate = SettableFuture.create(); ListenableFuture<T> resultFutureInCache = jobsCache.putIfAbsent(key, resultFutureCandidate); if (resultFutureInCache != null) { // Another thread succeeded in putting the new value into the cache. return resultFutureInCache; } // Ok, "our" candidate future went into the jobsCache, schedule the job and 'chain' the result // to the SettableFuture, so that anyone else waiting on it will get the same result. final SettableFuture<T> resultFuture = resultFutureCandidate; try { ListenableFuture<T> nodeJob = Futures.transformAsync(jobSupplier.get(), input -> Futures.immediateFuture(cache.putComputedNodeIfNotPresent(cell, key, input))); resultFuture.setFuture(nodeJob); } catch (Throwable t) { resultFuture.setException(t); throw t; } return resultFuture; }
From source file:org.opendaylight.messenger.impl.MessengerService.java
@Override public Future<RpcResult<GetLastMessageDatetimeOutput>> getLastMessageDatetime() { final String messDatetime = messProv.getlastMessageDatatime(); if (messDatetime != null && !messDatetime.isEmpty()) { final GetLastMessageDatetimeOutput messOutput = new GetLastMessageDatetimeOutputBuilder() .setMessageDatetime(messDatetime).build(); return Futures .immediateFuture(RpcResultBuilder.<GetLastMessageDatetimeOutput>success(messOutput).build()); } else {/*from w w w . ja va 2s .c o m*/ return Futures.immediateFuture(RpcResultBuilder.<GetLastMessageDatetimeOutput>failed().build()); } }
From source file:io.v.impl.google.rpc.StreamImpl.java
@Override public ListenableFuture<Object> recv(final Type type) { ListenableFutureCallback<byte[]> callback = new ListenableFutureCallback<>(); nativeRecv(nativeRef, callback);/*from ww w. j a v a2 s .c o m*/ return VFutures.withUserLandChecks(ctx, Futures.transform(callback.getVanillaFuture(), new AsyncFunction<byte[], Object>() { @Override public ListenableFuture<Object> apply(byte[] result) throws Exception { return Futures.immediateFuture(VomUtil.decode(result, type)); } })); }
From source file:io.v.v23.syncbase.nosql.RowImpl.java
@Override public ListenableFuture<Object> get(VContext ctx, final Type type) { return Futures.transform(client.get(ctx, schemaVersion), new AsyncFunction<byte[], Object>() { @Override/*from w ww . j a v a2s.c o m*/ public ListenableFuture<Object> apply(byte[] data) throws Exception { return Futures.immediateFuture(VomUtil.decode(data, type)); } }); }
From source file:de.metas.ui.web.vaadin.window.view.WindowViewListener2EditorListenerWrapper.java
@Override public ListenableFuture<Object> requestValue(final PropertyPath propertyPath) { final WindowViewListener windowViewListener = getWindowViewListener(); if (windowViewListener == null) { return Futures.immediateFuture(null); }//from w w w. j a va 2s.c om return windowViewListener.viewRequestValue(propertyPath); }