Class FluentFuture<V>
java.lang.Object
org.docx4j.com.google.common.util.concurrent.internal.InternalFutureFailureAccess
org.docx4j.com.google.common.util.concurrent.AbstractFuture<V>
org.docx4j.com.google.common.util.concurrent.GwtFluentFutureCatchingSpecialization<V>
org.docx4j.com.google.common.util.concurrent.FluentFuture<V>
- All Implemented Interfaces:
Future<V>,ListenableFuture<V>
- Direct Known Subclasses:
FluentFuture.TrustedFuture
@Beta
@GwtCompatible(emulated=true)
public abstract class FluentFuture<V>
extends GwtFluentFutureCatchingSpecialization<V>
A
ListenableFuture that supports fluent chains of operations. For example:
ListenableFuture<Boolean> adminIsLoggedIn =
FluentFuture.from(usersDatabase.getAdminUser())
.transform(User::getId, directExecutor())
.transform(ActivityService::isLoggedIn, threadPool)
.catching(RpcException.class, e -> false, directExecutor());
Alternatives
Frameworks
When chaining together a graph of asynchronous operations, you will often find it easier to use a framework. Frameworks automate the process, often adding features like monitoring, debugging, and cancellation. Examples of frameworks include:
CompletableFuture / CompletionStage
Users of CompletableFuture will likely want to continue using
CompletableFuture. FluentFuture is targeted at people who use ListenableFuture,
who can't use Java 8, or who want an API more focused than CompletableFuture. (If you
need to adapt between CompletableFuture and ListenableFuture, consider Future Converter.)
Extension
If you want a class likeFluentFuture but with extra methods, we recommend declaring your
own subclass of ListenableFuture, complete with a method like from(org.docx4j.com.google.common.util.concurrent.FluentFuture<V>) to adapt an
existing ListenableFuture, implemented atop a ForwardingListenableFuture that
forwards to that future and adds the desired methods.- Since:
- 23.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classA less abstract subclass of AbstractFuture.Nested classes/interfaces inherited from class org.docx4j.com.google.common.util.concurrent.AbstractFuture
AbstractFuture.Trusted<V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V> FluentFuture<V>from(FluentFuture<V> future) Deprecated.no need to use thisfinal FluentFuture<V>withTimeout(long timeout, TimeUnit unit, ScheduledExecutorService scheduledExecutor) Returns a future that delegates to this future but will finish early (via aTimeoutExceptionwrapped in anExecutionException) if the specified timeout expires.Methods inherited from class org.docx4j.com.google.common.util.concurrent.AbstractFuture
addListener, afterDone, cancel, get, get, interruptTask, isCancelled, isDone, maybePropagateCancellationTo, pendingToString, set, setException, setFuture, toString, tryInternalFastPathGetFailure, wasInterrupted
-
Constructor Details
-
FluentFuture
FluentFuture()
-
-
Method Details
-
from
Deprecated.no need to use thisSimply returns its argument.- Since:
- NEXT
-
withTimeout
@GwtIncompatible public final FluentFuture<V> withTimeout(long timeout, TimeUnit unit, ScheduledExecutorService scheduledExecutor) Returns a future that delegates to this future but will finish early (via aTimeoutExceptionwrapped in anExecutionException) if the specified timeout expires. If the timeout expires, not only will the output future finish, but also the input future (this) will be cancelled and interrupted.- Parameters:
timeout- when to time out the futureunit- the time unit of the time parameterscheduledExecutor- The executor service to enforce the timeout.
-