Class CompletableActorFuture<V>

java.lang.Object
io.camunda.zeebe.scheduler.future.CompletableActorFuture<V>
All Implemented Interfaces:
ActorFuture<V>, Future<V>, BiConsumer<V,Throwable>

public final class CompletableActorFuture<V> extends Object implements ActorFuture<V>
Completable future implementation that is garbage free and reusable
  • Constructor Details

    • CompletableActorFuture

      public CompletableActorFuture()
  • Method Details

    • setAwaitingResult

      public void setAwaitingResult()
    • completed

      public static <V> CompletableActorFuture<V> completed(V result)
    • completedExceptionally

      public static <V> CompletableActorFuture<V> completedExceptionally(Throwable throwable)
    • cancel

      public boolean cancel(boolean mayInterruptIfRunning)
      Specified by:
      cancel in interface Future<V>
    • isCancelled

      public boolean isCancelled()
      Specified by:
      isCancelled in interface Future<V>
    • isDone

      public boolean isDone()
      Specified by:
      isDone in interface Future<V>
    • get

      Specified by:
      get in interface Future<V>
      Throws:
      ExecutionException
      InterruptedException
    • get

      public V get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException, InterruptedException
      Specified by:
      get in interface Future<V>
      Throws:
      ExecutionException
      TimeoutException
      InterruptedException
    • isAwaitingResult

      public boolean isAwaitingResult()
    • complete

      public void complete(V value)
      Specified by:
      complete in interface ActorFuture<V>
    • completeExceptionally

      public void completeExceptionally(String failure, Throwable throwable)
      Specified by:
      completeExceptionally in interface ActorFuture<V>
    • completeExceptionally

      public void completeExceptionally(Throwable throwable)
      Specified by:
      completeExceptionally in interface ActorFuture<V>
    • join

      public V join()
      Specified by:
      join in interface ActorFuture<V>
    • join

      public V join(long timeout, TimeUnit timeUnit)
      Specified by:
      join in interface ActorFuture<V>
    • block

      public void block(ActorTask onCompletion)
      Description copied from interface: ActorFuture
      To be used by scheduler only
      Specified by:
      block in interface ActorFuture<V>
    • onComplete

      public void onComplete(BiConsumer<V,Throwable> consumer)
      Description copied from interface: ActorFuture
      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 use ActorFuture.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:
      onComplete in interface ActorFuture<V>
      Parameters:
      consumer - the consumer which should be called after the future was completed
    • onComplete

      public void onComplete(BiConsumer<V,Throwable> consumer, Executor executor)
      Description copied from interface: ActorFuture
      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 (use ActorFuture.onComplete(BiConsumer) instead), as it has some extra overhead for synchronization.
      Specified by:
      onComplete in interface ActorFuture<V>
      Parameters:
      consumer - the callback which should be called after the future was completed
      executor - the executor on which the callback will be executed
    • isCompletedExceptionally

      public boolean isCompletedExceptionally()
      Specified by:
      isCompletedExceptionally in interface ActorFuture<V>
    • getException

      public Throwable getException()
      Specified by:
      getException in interface ActorFuture<V>
    • andThen

      public <U> ActorFuture<U> andThen(Supplier<ActorFuture<U>> next, Executor executor)
      Description copied from interface: ActorFuture
      Convenience wrapper over ActorFuture.andThen(Function, Executor) for the case where the next step does not require the result of this future.
      Specified by:
      andThen in interface ActorFuture<V>
    • andThen

      public <U> ActorFuture<U> andThen(Function<V,ActorFuture<U>> next, Executor executor)
      Description copied from interface: ActorFuture
      Similar to CompletableFuture.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:
      andThen in interface ActorFuture<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

      public <U> ActorFuture<U> thenApply(Function<V,U> next, Executor executor)
      Description copied from interface: ActorFuture
      Similar to CompletableFuture.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:
      thenApply in interface ActorFuture<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

      public void completeWith(CompletableActorFuture<V> otherFuture)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCompletedAt

      public long getCompletedAt()