Class CompletableActorFuture<V>
java.lang.Object
io.camunda.zeebe.scheduler.future.CompletableActorFuture<V>
- All Implemented Interfaces:
ActorFuture<V>,Future<V>,BiConsumer<V,Throwable>
Completable future implementation that is garbage free and reusable
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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 overActorFuture.andThen(Function, Executor)for the case where the next step does not require the result of this future.voidTo be used by scheduler onlybooleancancel(boolean mayInterruptIfRunning) booleanclose()future is reusable after closevoidstatic <V> CompletableActorFuture<V> completed(V result) static <V> CompletableActorFuture<V> completedExceptionally(Throwable throwable) voidcompleteExceptionally(String failure, Throwable throwable) voidcompleteExceptionally(Throwable throwable) voidcompleteWith(CompletableActorFuture<V> otherFuture) get()longbooleanbooleanbooleanisClosed()booleanbooleanisDone()join()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.void<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.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.camunda.zeebe.scheduler.future.ActorFuture
accept, toCompletableFutureMethods inherited from interface java.util.function.BiConsumer
andThenMethods inherited from interface java.util.concurrent.Future
exceptionNow, resultNow, state
-
Constructor Details
-
CompletableActorFuture
public CompletableActorFuture()
-
-
Method Details
-
setAwaitingResult
public void setAwaitingResult() -
completed
-
completedExceptionally
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceFuture<V>
-
isDone
public boolean isDone() -
get
- Specified by:
getin interfaceFuture<V>- Throws:
ExecutionExceptionInterruptedException
-
get
public V get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException, InterruptedException - Specified by:
getin interfaceFuture<V>- Throws:
ExecutionExceptionTimeoutExceptionInterruptedException
-
isAwaitingResult
public boolean isAwaitingResult() -
complete
- Specified by:
completein interfaceActorFuture<V>
-
completeExceptionally
- Specified by:
completeExceptionallyin interfaceActorFuture<V>
-
completeExceptionally
- Specified by:
completeExceptionallyin interfaceActorFuture<V>
-
join
- Specified by:
joinin interfaceActorFuture<V>
-
join
- Specified by:
joinin interfaceActorFuture<V>
-
block
Description copied from interface:ActorFutureTo be used by scheduler only- Specified by:
blockin interfaceActorFuture<V>
-
onComplete
Description copied from interface:ActorFutureRegisters 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 useActorFuture.onComplete(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 }); - Specified by:
onCompletein interfaceActorFuture<V>- Parameters:
consumer- the consumer which should be called after the future was completed
-
onComplete
Description copied from interface:ActorFutureRegisters 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 (useActorFuture.onComplete(BiConsumer)instead), as it has some extra overhead for synchronization.- Specified by:
onCompletein interfaceActorFuture<V>- Parameters:
consumer- the callback which should be called after the future was completedexecutor- the executor on which the callback will be executed
-
isCompletedExceptionally
public boolean isCompletedExceptionally()- Specified by:
isCompletedExceptionallyin interfaceActorFuture<V>
-
getException
- Specified by:
getExceptionin interfaceActorFuture<V>
-
andThen
Description copied from interface:ActorFutureConvenience wrapper overActorFuture.andThen(Function, Executor)for the case where the next step does not require the result of this future.- Specified by:
andThenin interfaceActorFuture<V>
-
andThen
Description copied from interface:ActorFutureSimilar 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.- Specified by:
andThenin interfaceActorFuture<V>- 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
Description copied from interface:ActorFutureSimilar 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.
- Specified by:
thenApplyin interfaceActorFuture<V>- 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.
-
close
public boolean close()future is reusable after close -
isClosed
public boolean isClosed() -
completeWith
-
toString
-
getCompletedAt
public long getCompletedAt()
-