Interface AFutureBase<Self extends AFutureBase<Self>>

  • Type Parameters:
    Self - The concrete future type (AFuture or ARFuture) for fluent chaining.
    All Known Subinterfaces:
    AFuture, ARFuture<T>
    All Known Implementing Classes:
    ARFutureWithFlag

    public interface AFutureBase<Self extends AFutureBase<Self>>
    Base interface defining the common life cycle, status, and chaining methods for all asynchronous operations (AFuture and ARFuture).
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      boolean addListener​(AConsumer<Self> l)
      Adds a listener to the future's completion status.
      default Self addListener2​(AConsumer<Self> l)  
      void cancel()
      Cancels the future.
      Self error​(java.lang.Throwable e)
      Completes the future with the given error.
      java.lang.Throwable getError()
      Gets the error Throwable if the future is in an error state.
      java.lang.Object getNowRaw()
      Gets the raw result object.
      boolean isCanceled()
      Checks if the future has been canceled.
      boolean isDone()
      Checks if the future has reached the Done state (completed successfully).
      boolean isError()
      Checks if the final status is an error.
      boolean isFinalStatus()
      Checks if the future has reached a final state (Done, Error, or Canceled).
      boolean isNotDone()
      Checks if the future has not reached the Done state.
      Self onCancel​(AConsumer<Self> l)
      Registers a listener to be executed if the future completes with a cancellation.
      Self onCancel​(ARunnable l)
      Registers a listener to be executed if the future completes with a cancellation.
      Self onError​(AConsumer<java.lang.Throwable> l)
      Registers a listener to be executed if the future completes with an error.
      void setError​(java.lang.Throwable e)
      Sets the error Throwable.
      Self timeout​(int seconds, ARunnable task)
      Sets a timeout duration in seconds, executing a task if the timeout occurs.
      Self timeoutError​(int seconds, java.lang.String text)
      Sets a timeout duration in seconds, after which the future is automatically marked as an error.
      Self timeoutMs​(long ms, AConsumer<Self> task)
      Sets a timeout duration in milliseconds, executing a consumer with this future if the timeout occurs.
      Self timeoutMs​(long ms, ARunnable task)
      Sets a timeout duration in milliseconds, executing a task if the timeout occurs.
      Self to​(ARunnable t)
      Executes a runnable task upon successful completion in the current context.
      Self to​(java.util.concurrent.Executor executor, ARunnable t)
      Executes a runnable task on the provided executor upon successful completion.
      Self tryCancel()  
      boolean tryError​(@NotNull java.lang.Throwable error)  
      boolean updateStatus​(java.lang.Object result)  
    • Method Detail

      • onCancel

        Self onCancel​(ARunnable l)
        Registers a listener to be executed if the future completes with a cancellation.
        Parameters:
        l - The runnable task to execute on cancellation.
      • updateStatus

        boolean updateStatus​(java.lang.Object result)
      • onCancel

        Self onCancel​(AConsumer<Self> l)
        Registers a listener to be executed if the future completes with a cancellation.
        Parameters:
        l - The consumer that accepts the future instance on cancellation.
      • onError

        Self onError​(AConsumer<java.lang.Throwable> l)
        Registers a listener to be executed if the future completes with an error.
        Parameters:
        l - The consumer that accepts the Throwable error.
        Returns:
        This future instance for chaining.
      • isFinalStatus

        boolean isFinalStatus()
        Checks if the future has reached a final state (Done, Error, or Canceled).
        Returns:
        true if the status is final.
      • isError

        boolean isError()
        Checks if the final status is an error.
        Returns:
        true if the future completed with an error.
      • error

        Self error​(java.lang.Throwable e)
        Completes the future with the given error.
        Parameters:
        e - The Throwable error.
        Returns:
        This future instance for chaining.
      • getError

        java.lang.Throwable getError()
        Gets the error Throwable if the future is in an error state.
        Returns:
        The error or null.
      • setError

        void setError​(java.lang.Throwable e)
        Sets the error Throwable. Same as error(Throwable).
        Parameters:
        e - The Throwable error.
      • isNotDone

        boolean isNotDone()
        Checks if the future has not reached the Done state.
        Returns:
        true if the future is pending or in an Error/Canceled state.
      • isDone

        boolean isDone()
        Checks if the future has reached the Done state (completed successfully).
        Returns:
        true if completed successfully.
      • isCanceled

        boolean isCanceled()
        Checks if the future has been canceled.
        Returns:
        true if canceled.
      • cancel

        void cancel()
        Cancels the future.
      • timeoutError

        Self timeoutError​(int seconds,
                          java.lang.String text)
        Sets a timeout duration in seconds, after which the future is automatically marked as an error.
        Parameters:
        seconds - Timeout duration.
        text - Error message text.
        Returns:
        This future instance for chaining.
      • timeout

        Self timeout​(int seconds,
                     ARunnable task)
        Sets a timeout duration in seconds, executing a task if the timeout occurs.
        Parameters:
        seconds - Timeout duration.
        task - The task to run on timeout.
        Returns:
        This future instance for chaining.
      • timeoutMs

        Self timeoutMs​(long ms,
                       ARunnable task)
        Sets a timeout duration in milliseconds, executing a task if the timeout occurs.
        Parameters:
        ms - Timeout duration in milliseconds.
        task - The task to run on timeout.
        Returns:
        This future instance for chaining.
      • timeoutMs

        Self timeoutMs​(long ms,
                       AConsumer<Self> task)
        Sets a timeout duration in milliseconds, executing a consumer with this future if the timeout occurs.
        Parameters:
        ms - Timeout duration in milliseconds.
        task - The consumer to run on timeout.
        Returns:
        This future instance for chaining.
      • addListener

        boolean addListener​(AConsumer<Self> l)
        Adds a listener to the future's completion status.
        Parameters:
        l - The consumer that accepts the future instance upon finalization.
        Returns:
        true if the listener was successfully added (and the future was not yet finalized).
      • to

        Self to​(java.util.concurrent.Executor executor,
                ARunnable t)
        Executes a runnable task on the provided executor upon successful completion.
        Parameters:
        executor - The executor to run the task on.
        t - The runnable task.
        Returns:
        This future instance for chaining.
      • to

        Self to​(ARunnable t)
        Executes a runnable task upon successful completion in the current context.
        Parameters:
        t - The runnable task.
        Returns:
        This future instance for chaining.
      • getNowRaw

        java.lang.Object getNowRaw()
        Gets the raw result object. Intended for internal implementation use.
        Returns:
        The raw result object (which may be NULL, CANCEL_VALUE, or Throwable).
      • tryError

        boolean tryError​(@NotNull
                         @NotNull java.lang.Throwable error)
      • tryCancel

        Self tryCancel()