Interface ActorFuture<V>

All Superinterfaces:
BiConsumer<V,Throwable>, Future<V>
All Known Implementing Classes:
CompletableActorFuture

public interface ActorFuture<V> extends Future<V>, BiConsumer<V,Throwable>
interface for actor futures
  • Method Details

    • complete

      void complete(V value)
    • completeExceptionally

      void completeExceptionally(String failure, Throwable throwable)
    • completeExceptionally

      void completeExceptionally(Throwable throwable)
    • join

      V join()
    • join

      V join(long timeout, TimeUnit timeUnit)
    • block

      void block(ActorTask onCompletion)
      To be used by scheduler only
    • onComplete

      void onComplete(BiConsumer<V,Throwable> consumer)
      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 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
        });
       
      Parameters:
      consumer - the consumer which should be called after the future was completed
    • onComplete

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

      boolean isCompletedExceptionally()
    • getException

      Throwable getException()
    • accept

      default void accept(V value, Throwable throwable)
      Specified by:
      accept in interface BiConsumer<V,Throwable>
    • toCompletableFuture

      default CompletableFuture<V> toCompletableFuture()
      Utility method to convert this future to a CompletableFuture. The returned future will be completed when this future is completed.
      Returns:
      a completable future
    • andThen

      <U> ActorFuture<U> andThen(Supplier<ActorFuture<U>> next, Executor executor)
      Convenience wrapper over andThen(Function, Executor) for the case where the next step does not require the result of this future.
    • andThen

      <U> ActorFuture<U> andThen(Function<V,ActorFuture<U>> next, Executor executor)
      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.
      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

      <U> ActorFuture<U> thenApply(Function<V,U> next, Executor executor)
      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.

      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.