Class ARFutureWithFlag<T>

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addListener​(AConsumer<Self> l)
      Adds a listener to the future's completion status.
      <T2> ARFuture<Tuple2<T,​T2>> and​(ARFuture<T2> f)
      Chains this future with another, combining their results into a Tuple2.
      ARFuture<T> apply​(AConsumer<T> c)
      Executes a consumer upon successful completion, preserving the original result.
      ARFuture<T> apply​(ARunnable c)
      Executes a runnable upon successful completion, preserving the original result.
      void cancel()
      Cancels the future.
      <E> ARFuture<E> decompose​(java.lang.Class<E> t)  
      void done​(T value)
      Completes the future with the given value.
      Self error​(java.lang.Throwable e)
      Completes the future with the given error.
      T get()
      Gets the result of the future, waiting if necessary, and throws an exception on error/cancel.
      T get​(int timeout)  
      T get​(long timout)
      Gets the result of the future with a timeout, waiting if necessary.
      java.lang.Throwable getError()
      Gets the error Throwable if the future is in an error state.
      T getNow()
      Gets the result value if the future is already done, otherwise returns null.
      T getNowElse​(T elseValue)
      Gets the result value if the future is already done, otherwise returns the provided default value.
      java.lang.Object getNowRaw()
      Gets the raw result object.
      T getSeconds​(int timout)  
      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.
      <E> @NotNull ARFuture<E> map​(@NotNull AFunction<T,​E> f)
      Transforms the successful result into a different type using the provided function.
      <E> @NotNull ARFuture<E> mapRFuture​(@NotNull AFunction<T,​ARFuture<E>> f)
      Transforms the successful result into another ARFuture.
      <E> ARFuture<E> mapSafe​(@NotNull AFunction<T,​E> f)
      Transforms the successful result into a different type in a safe context (e.g., dedicated executor).
      @NotNull AFuture mapToFuture​(@NotNull AConsumer<T> f)
      Maps the result to a void AFuture and converts the result to an AFuture.
      <E> @NotNull ARFuture<E> mapWL​(@NotNull AFunction<T,​E> f)
      Transforms the successful result into a different type using a function wrapped for Log context.
      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.
      ARFuture<T> to​(@NotNull AFuture f)  
      ARFuture<T> to​(@NotNull ARFuture<T> f)
      Transfers the final status (done/error/cancel) to another future.
      ARFuture<T> to​(@NotNull AConsumer<T> task, int timeout, ARunnable onTimeout)
      Registers a success callback with a timeout action.
      ARFuture<T> to​(AConsumer<T> onDone)
      Registers a callback to be executed upon successful completion.
      ARFuture<T> to​(AConsumer<T> onDone, AConsumer<java.lang.Throwable> onError)
      Registers a callback for success and another for error.
      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.
      AFuture toFuture()
      Converts this ARFuture into a void AFuture.
      java.lang.String toString()  
      ARFutureWithFlag<T> toWithFlag()
      Casts this ARFuture to its flag-carrying subclass.
      Self tryCancel()  
      boolean tryDone​(T value)
      Attempts to complete the future with the given value.
      boolean tryError​(@NotNull java.lang.Throwable error)  
      boolean tryRequest()  
      boolean updateStatus​(java.lang.Object result)
      Attempts to set the final result status using CompareAndSet.
      void waitSuccessful()  
      boolean waitSuccessful​(long timeout)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ARFutureWithFlag

        public ARFutureWithFlag()
    • Method Detail

      • tryRequest

        public boolean tryRequest()
      • to

        public ARFuture<T> to​(@NotNull
                              @NotNull AConsumer<T> task,
                              int timeout,
                              ARunnable onTimeout)
        Description copied from interface: ARFuture
        Registers a success callback with a timeout action.
        Specified by:
        to in interface ARFuture<T>
        Parameters:
        task - The consumer that accepts the result value.
        timeout - The timeout in seconds.
        onTimeout - The runnable to execute on timeout.
        Returns:
        This future instance.
      • toWithFlag

        public ARFutureWithFlag<T> toWithFlag()
        Description copied from interface: ARFuture
        Casts this ARFuture to its flag-carrying subclass.
        Specified by:
        toWithFlag in interface ARFuture<T>
        Returns:
        The ARFutureWithFlag instance.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • and

        public <T2> ARFuture<Tuple2<T,​T2>> and​(ARFuture<T2> f)
        Description copied from interface: ARFuture
        Chains this future with another, combining their results into a Tuple2.
        Specified by:
        and in interface ARFuture<T>
        Type Parameters:
        T2 - The type of the other future's result.
        Parameters:
        f - The other future.
        Returns:
        A new ARFuture with a Tuple2 result.
      • to

        public ARFuture<T> to​(AConsumer<T> onDone,
                              AConsumer<java.lang.Throwable> onError)
        Description copied from interface: ARFuture
        Registers a callback for success and another for error.
        Specified by:
        to in interface ARFuture<T>
        Parameters:
        onDone - The consumer that accepts the result value.
        onError - The consumer that accepts the throwable error.
        Returns:
        This future instance.
      • to

        public ARFuture<T> to​(AConsumer<T> onDone)
        Description copied from interface: ARFuture
        Registers a callback to be executed upon successful completion.
        Specified by:
        to in interface ARFuture<T>
        Parameters:
        onDone - The consumer that accepts the result value.
        Returns:
        This future instance.
      • done

        public void done​(T value)
        Description copied from interface: ARFuture
        Completes the future with the given value.
        Specified by:
        done in interface ARFuture<T>
        Parameters:
        value - The result value.
      • tryDone

        public boolean tryDone​(T value)
        Description copied from interface: ARFuture
        Attempts to complete the future with the given value.
        Specified by:
        tryDone in interface ARFuture<T>
        Parameters:
        value - The result value.
        Returns:
        true if the status was updated, false otherwise.
      • get

        public T get()
        Description copied from interface: ARFuture
        Gets the result of the future, waiting if necessary, and throws an exception on error/cancel.
        Specified by:
        get in interface ARFuture<T>
        Returns:
        The result value (T).
      • get

        public T get​(int timeout)
      • getSeconds

        public T getSeconds​(int timout)
      • get

        public T get​(long timout)
        Description copied from interface: ARFuture
        Gets the result of the future with a timeout, waiting if necessary.
        Specified by:
        get in interface ARFuture<T>
        Parameters:
        timout - The timeout in milliseconds.
        Returns:
        The result value (T).
      • getNow

        public T getNow()
        Description copied from interface: ARFuture
        Gets the result value if the future is already done, otherwise returns null.
        Specified by:
        getNow in interface ARFuture<T>
        Returns:
        The result T or null.
      • getNowElse

        public T getNowElse​(T elseValue)
        Description copied from interface: ARFuture
        Gets the result value if the future is already done, otherwise returns the provided default value.
        Specified by:
        getNowElse in interface ARFuture<T>
        Parameters:
        elseValue - The default value to return if not done.
        Returns:
        The result T or elseValue.
      • mapSafe

        public <E> ARFuture<E> mapSafe​(@NotNull
                                       @NotNull AFunction<T,​E> f)
        Description copied from interface: ARFuture
        Transforms the successful result into a different type in a safe context (e.g., dedicated executor).
        Specified by:
        mapSafe in interface ARFuture<T>
        Type Parameters:
        E - The new result type.
        Parameters:
        f - The function to apply to the result.
        Returns:
        A new ARFuture with the transformed result.
      • mapToFuture

        @NotNull
        public @NotNull AFuture mapToFuture​(@NotNull
                                            @NotNull AConsumer<T> f)
        Description copied from interface: ARFuture
        Maps the result to a void AFuture and converts the result to an AFuture.
        Specified by:
        mapToFuture in interface ARFuture<T>
        Parameters:
        f - The consumer to apply to the result.
        Returns:
        An AFuture representing the completion of the consumer's execution.
      • mapRFuture

        @NotNull
        public <E> @NotNull ARFuture<E> mapRFuture​(@NotNull
                                                   @NotNull AFunction<T,​ARFuture<E>> f)
        Description copied from interface: ARFuture
        Transforms the successful result into another ARFuture.
        Specified by:
        mapRFuture in interface ARFuture<T>
        Type Parameters:
        E - The new result type.
        Parameters:
        f - The function returning the new ARFuture.
        Returns:
        A new ARFuture that completes with the result of the future returned by f.
      • mapWL

        @NotNull
        public <E> @NotNull ARFuture<E> mapWL​(@NotNull
                                              @NotNull AFunction<T,​E> f)
        Description copied from interface: ARFuture
        Transforms the successful result into a different type using a function wrapped for Log context.
        Specified by:
        mapWL in interface ARFuture<T>
        Type Parameters:
        E - The new result type.
        Parameters:
        f - The function to apply to the result.
        Returns:
        A new ARFuture with the transformed result.
      • map

        @NotNull
        public <E> @NotNull ARFuture<E> map​(@NotNull
                                            @NotNull AFunction<T,​E> f)
        Description copied from interface: ARFuture
        Transforms the successful result into a different type using the provided function.
        Specified by:
        map in interface ARFuture<T>
        Type Parameters:
        E - The new result type.
        Parameters:
        f - The function to apply to the result.
        Returns:
        A new ARFuture with the transformed result.
      • apply

        public ARFuture<T> apply​(ARunnable c)
        Description copied from interface: ARFuture
        Executes a runnable upon successful completion, preserving the original result.
        Specified by:
        apply in interface ARFuture<T>
        Parameters:
        c - The runnable to execute.
        Returns:
        A new ARFuture with the same original result.
      • apply

        public ARFuture<T> apply​(AConsumer<T> c)
        Description copied from interface: ARFuture
        Executes a consumer upon successful completion, preserving the original result.
        Specified by:
        apply in interface ARFuture<T>
        Parameters:
        c - The consumer to execute with the result.
        Returns:
        A new ARFuture with the same original result.
      • decompose

        public <E> ARFuture<E> decompose​(java.lang.Class<E> t)
      • to

        public ARFuture<T> to​(@NotNull
                              @NotNull ARFuture<T> f)
        Description copied from interface: ARFuture
        Transfers the final status (done/error/cancel) to another future.
        Specified by:
        to in interface ARFuture<T>
        Parameters:
        f - The target future.
        Returns:
        This future instance.
      • toFuture

        public AFuture toFuture()
        Description copied from interface: ARFuture
        Converts this ARFuture into a void AFuture.
        Specified by:
        toFuture in interface ARFuture<T>
        Returns:
        The resulting AFuture.
      • onCancel

        public Self onCancel​(ARunnable l)
        Description copied from interface: AFutureBase
        Registers a listener to be executed if the future completes with a cancellation.
        Specified by:
        onCancel in interface AFutureBase<Self extends AFutureBase<Self>>
        Parameters:
        l - The runnable task to execute on cancellation.
      • onCancel

        public Self onCancel​(AConsumer<Self> l)
        Description copied from interface: AFutureBase
        Registers a listener to be executed if the future completes with a cancellation.
        Specified by:
        onCancel in interface AFutureBase<Self extends AFutureBase<Self>>
        Parameters:
        l - The consumer that accepts the future instance on cancellation.
      • onError

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

        public boolean isFinalStatus()
        Description copied from interface: AFutureBase
        Checks if the future has reached a final state (Done, Error, or Canceled).
        Specified by:
        isFinalStatus in interface AFutureBase<Self extends AFutureBase<Self>>
        Returns:
        true if the status is final.
      • waitSuccessful

        public void waitSuccessful()
      • waitSuccessful

        public boolean waitSuccessful​(long timeout)
      • isError

        public boolean isError()
        Description copied from interface: AFutureBase
        Checks if the final status is an error.
        Specified by:
        isError in interface AFutureBase<Self extends AFutureBase<Self>>
        Returns:
        true if the future completed with an error.
      • error

        public Self error​(java.lang.Throwable e)
        Description copied from interface: AFutureBase
        Completes the future with the given error.
        Specified by:
        error in interface AFutureBase<Self extends AFutureBase<Self>>
        Parameters:
        e - The Throwable error.
        Returns:
        This future instance for chaining.
      • getError

        public java.lang.Throwable getError()
        Description copied from interface: AFutureBase
        Gets the error Throwable if the future is in an error state.
        Specified by:
        getError in interface AFutureBase<Self extends AFutureBase<Self>>
        Returns:
        The error or null.
      • updateStatus

        public boolean updateStatus​(java.lang.Object result)
        Attempts to set the final result status using CompareAndSet.
        Specified by:
        updateStatus in interface AFutureBase<Self extends AFutureBase<Self>>
        Parameters:
        result - The result object (or Throwable for error, CANCEL_VALUE for cancel).
        Returns:
        true if the status was successfully updated.
      • isNotDone

        public boolean isNotDone()
        Description copied from interface: AFutureBase
        Checks if the future has not reached the Done state.
        Specified by:
        isNotDone in interface AFutureBase<Self extends AFutureBase<Self>>
        Returns:
        true if the future is pending or in an Error/Canceled state.
      • isDone

        public boolean isDone()
        Description copied from interface: AFutureBase
        Checks if the future has reached the Done state (completed successfully).
        Specified by:
        isDone in interface AFutureBase<Self extends AFutureBase<Self>>
        Returns:
        true if completed successfully.
      • isCanceled

        public boolean isCanceled()
        Description copied from interface: AFutureBase
        Checks if the future has been canceled.
        Specified by:
        isCanceled in interface AFutureBase<Self extends AFutureBase<Self>>
        Returns:
        true if canceled.
      • timeoutError

        public Self timeoutError​(int seconds,
                                 java.lang.String text)
        Description copied from interface: AFutureBase
        Sets a timeout duration in seconds, after which the future is automatically marked as an error.
        Specified by:
        timeoutError in interface AFutureBase<Self extends AFutureBase<Self>>
        Parameters:
        seconds - Timeout duration.
        text - Error message text.
        Returns:
        This future instance for chaining.
      • timeout

        public Self timeout​(int seconds,
                            ARunnable task)
        Description copied from interface: AFutureBase
        Sets a timeout duration in seconds, executing a task if the timeout occurs.
        Specified by:
        timeout in interface AFutureBase<Self extends AFutureBase<Self>>
        Parameters:
        seconds - Timeout duration.
        task - The task to run on timeout.
        Returns:
        This future instance for chaining.
      • timeoutMs

        public Self timeoutMs​(long ms,
                              ARunnable task)
        Description copied from interface: AFutureBase
        Sets a timeout duration in milliseconds, executing a task if the timeout occurs.
        Specified by:
        timeoutMs in interface AFutureBase<Self extends AFutureBase<Self>>
        Parameters:
        ms - Timeout duration in milliseconds.
        task - The task to run on timeout.
        Returns:
        This future instance for chaining.
      • timeoutMs

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

        public boolean addListener​(AConsumer<Self> l)
        Description copied from interface: AFutureBase
        Adds a listener to the future's completion status.
        Specified by:
        addListener in interface AFutureBase<Self extends AFutureBase<Self>>
        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

        public Self to​(java.util.concurrent.Executor executor,
                       ARunnable t)
        Description copied from interface: AFutureBase
        Executes a runnable task on the provided executor upon successful completion.
        Specified by:
        to in interface AFutureBase<Self extends AFutureBase<Self>>
        Parameters:
        executor - The executor to run the task on.
        t - The runnable task.
        Returns:
        This future instance for chaining.
      • to

        public Self to​(ARunnable t)
        Description copied from interface: AFutureBase
        Executes a runnable task upon successful completion in the current context.
        Specified by:
        to in interface AFutureBase<Self extends AFutureBase<Self>>
        Parameters:
        t - The runnable task.
        Returns:
        This future instance for chaining.
      • getNowRaw

        public java.lang.Object getNowRaw()
        Description copied from interface: AFutureBase
        Gets the raw result object. Intended for internal implementation use.
        Specified by:
        getNowRaw in interface AFutureBase<Self extends AFutureBase<Self>>
        Returns:
        The raw result object (which may be NULL, CANCEL_VALUE, or Throwable).
      • tryError

        public boolean tryError​(@NotNull
                                @NotNull java.lang.Throwable error)
        Specified by:
        tryError in interface AFutureBase<Self extends AFutureBase<Self>>