Interface ActorFuture<V>
- All Superinterfaces:
BiConsumer<V,,Throwable> Future<V>
- All Known Implementing Classes:
CompletableActorFuture
interface for actor futures
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Method Summary
Modifier and TypeMethodDescriptiondefault void<U> ActorFuture<U> andThen(Function<V, ActorFuture<U>> next, Executor executor) Similar toCompletableFuture.thenCompose(Function)in that it applies a function to the result of this future, supporting chaining of futures while propagating exceptions.<U> ActorFuture<U> andThen(Supplier<ActorFuture<U>> next, Executor executor) Convenience wrapper overandThen(Function, Executor)for the case where the next step does not require the result of this future.voidTo be used by scheduler onlyvoidvoidcompleteExceptionally(String failure, Throwable throwable) voidcompleteExceptionally(Throwable throwable) booleanjoin()voidonComplete(BiConsumer<V, Throwable> consumer) Registers an consumer, which is executed after the future was completed.voidonComplete(BiConsumer<V, Throwable> consumer, Executor executor) Registers a consumer, which is executed after the future was completed.<U> ActorFuture<U> Similar toCompletableFuture.thenApply(Function)in that it applies a function to the result of this future, allowing you to change types on the fly.default CompletableFuture<V> Utility method to convert this future to aCompletableFuture.Methods inherited from interface java.util.function.BiConsumer
andThenMethods inherited from interface java.util.concurrent.Future
cancel, exceptionNow, get, get, isCancelled, isDone, resultNow, state
-
Method Details
-
complete
-
completeExceptionally
-
completeExceptionally
-
join
V join() -
join
-
block
To be used by scheduler only -
onComplete
Registers an consumer, which is executed after the future was completed. If the caller of this method is an actor, the consumer is executed in the caller's actor thread. If the caller is not an actor, the consumer is executed in the actor which completes this future. If the caller is not an actor, it is recommended to useonComplete(BiConsumer, Executor)instead.Example:
Actor A calls Actor B to retrieve an value. Actor B returns an future, which will be completed later with the right value. Actor A wants to do some work, after B returns the value. For that Actor A calls `#onComplete`, at this returned future, to register an consumer. After the future is completed, the registered consumer is called in the Actor A context.
Running in Actor A context:
final ActorFuture
future = ActorB.getValue(); future.onComplete(value, throwable -> { // do things - runs in Actor A context again }); - Parameters:
consumer- the consumer which should be called after the future was completed
-
onComplete
Registers a consumer, which is executed after the future was completed. The consumer is executed in the provided executor. It is recommended to not use this method if the caller is an actor (useonComplete(BiConsumer)instead), as it has some extra overhead for synchronization.- Parameters:
consumer- the callback which should be called after the future was completedexecutor- the executor on which the callback will be executed
-
isCompletedExceptionally
boolean isCompletedExceptionally() -
getException
Throwable getException() -
accept
- Specified by:
acceptin interfaceBiConsumer<V,Throwable>
-
toCompletableFuture
Utility method to convert this future to aCompletableFuture. The returned future will be completed when this future is completed.- Returns:
- a completable future
-
andThen
Convenience wrapper overandThen(Function, Executor)for the case where the next step does not require the result of this future. -
andThen
Similar toCompletableFuture.thenCompose(Function)in that it applies a function to the result of this future, supporting chaining of futures while propagating exceptions. Implementations may be somewhat inefficient and create intermediate futures, schedule completion callbacks on the provided executor etc. As such, it should be used for orchestrating futures in a non-performance critical context, for example for startup and shutdown sequences.- Type Parameters:
U- the type of the new future- Parameters:
next- function to apply to the result of this future.executor- The executor used to handle completion callbacks.- Returns:
- a new future that completes with the result of applying the function to the result of this future or exceptionally if this future completes exceptionally. This future can be used for further chaining.
-
thenApply
Similar toCompletableFuture.thenApply(Function)in that it applies a function to the result of this future, allowing you to change types on the fly.Implementations may be somewhat inefficient and create intermediate futures, schedule completion callbacks on the provided executor etc. As such, it should normally be used for orchestrating futures in a non-performance critical context, for example for startup and shutdown sequence.
- Type Parameters:
U- the type of the new future- Parameters:
next- function to apply to the result of this future.executor- The executor used to handle completion callbacks.- Returns:
- a new future that completes with the result of applying the function to the result of this future or exceptionally if this future completes exceptionally. This future can be used for further chaining.
-