Class AbstractFuture<R,S,T extends Task<R,S>>

java.lang.Object
de.linusdev.lutils.async.AbstractFuture<R,S,T>
All Implemented Interfaces:
Future<R,S>, HasAsyncManager
Direct Known Subclasses:
CompletableFuture, ExecutableFuture

public abstract class AbstractFuture<R,S,T extends Task<R,S>> extends Object implements Future<R,S>
  • Field Details

    • asyncManager

      @NotNull protected final @NotNull AsyncManager asyncManager
    • task

      @Nullable protected final T extends Task<R,S> task
    • canceled

      protected volatile boolean canceled
    • started

      protected volatile boolean started
    • done

      protected volatile boolean done
    • lock

      protected final Object lock
    • before

      @Nullable protected volatile @Nullable Consumer<Future<R,S>> before
    • then

      @Nullable protected volatile @Nullable ResultConsumer<R,S> then
    • result

      @Nullable protected volatile @Nullable ComputationResult<R,S> result
  • Constructor Details

    • AbstractFuture

      protected AbstractFuture(@Nullable T task, @NotNull @NotNull AsyncManager asyncManager)
  • Method Details

    • getTask

      @Nullable protected T getTask()
    • cancel

      @NotNull public @NotNull Future<R,S> cancel()
      Description copied from interface: Future
      Cancels this future, if it is not already executing.
      Specified by:
      cancel in interface Future<R,S>
      Returns:
      the canceled Future
    • isCanceled

      public boolean isCanceled()
      Specified by:
      isCanceled in interface Future<R,S>
      Returns:
      true if this Future is canceled.
    • hasStarted

      public boolean hasStarted()
      Specified by:
      hasStarted in interface Future<R,S>
      Returns:
      true if this Future has started its execution.
    • isDone

      public boolean isDone()
      Specified by:
      isDone in interface Future<R,S>
      Returns:
      true if this Future is done (execution finished and result or error is ready).
    • beforeExecution

      @NotNull public @NotNull Future<R,S> beforeExecution(@NotNull @NotNull Consumer<Future<R,S>> consumer)
      Description copied from interface: Future
      Given consumer will be called before the Future will be executed. The Future can still be canceled.
      Specified by:
      beforeExecution in interface Future<R,S>
      Parameters:
      consumer - Consumer that will be called before execution
      Returns:
      the Future itself.
    • then

      @NotNull public @NotNull Future<R,S> then(@NotNull @NotNull ResultConsumer<R,S> consumer)
      Description copied from interface: Future
      Given consumer will be called after Future's execution has finished and result or error is ready.
      Specified by:
      then in interface Future<R,S>
      Parameters:
      consumer - ResultConsumer
      Returns:
      the Future itself.
    • get

      @NotNull public @NotNull ComputationResult<R,S> get() throws InterruptedException
      Description copied from interface: Future
      Waits the current Thread until this Future has been executed. If execution has already finished, this method will return immediately.
      Specified by:
      get in interface Future<R,S>
      Returns:
      ComputationResult containing the result, secondary result and a potential error.
      Throws:
      InterruptedException - if interrupted while waiting
    • getAsyncManager

      @NotNull public @NotNull AsyncManager getAsyncManager()
      Specified by:
      getAsyncManager in interface HasAsyncManager