Package io.aether.utils.futures
Class ARFutureWithFlag<T>
- java.lang.Object
-
- io.aether.utils.futures.ARFutureWithFlag<T>
-
- All Implemented Interfaces:
AFutureBase<ARFuture<T>>,ARFuture<T>,ToString
public class ARFutureWithFlag<T> extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ARFutureWithFlag()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddListener(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.voidcancel()Cancels the future.<E> ARFuture<E>decompose(java.lang.Class<E> t)voiddone(T value)Completes the future with the given value.Selferror(java.lang.Throwable e)Completes the future with the given error.Tget()Gets the result of the future, waiting if necessary, and throws an exception on error/cancel.Tget(int timeout)Tget(long timout)Gets the result of the future with a timeout, waiting if necessary.java.lang.ThrowablegetError()Gets the error Throwable if the future is in an error state.TgetNow()Gets the result value if the future is already done, otherwise returns null.TgetNowElse(T elseValue)Gets the result value if the future is already done, otherwise returns the provided default value.java.lang.ObjectgetNowRaw()Gets the raw result object.TgetSeconds(int timout)booleanisCanceled()Checks if the future has been canceled.booleanisDone()Checks if the future has reached the Done state (completed successfully).booleanisError()Checks if the final status is an error.booleanisFinalStatus()Checks if the future has reached a final state (Done, Error, or Canceled).booleanisNotDone()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 AFuturemapToFuture(@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.SelfonCancel(AConsumer<Self> l)Registers a listener to be executed if the future completes with a cancellation.SelfonCancel(ARunnable l)Registers a listener to be executed if the future completes with a cancellation.SelfonError(AFuture l)SelfonError(ARFuture<?> l)SelfonError(AConsumer<java.lang.Throwable> l)Registers a listener to be executed if the future completes with an error.voidsetError(java.lang.Throwable e)Sets the error Throwable.Selftimeout(int seconds, ARunnable task)Sets a timeout duration in seconds, executing a task if the timeout occurs.SelftimeoutError(int seconds, java.lang.String text)Sets a timeout duration in seconds, after which the future is automatically marked as an error.SelftimeoutMs(long ms, AConsumer<Self> task)Sets a timeout duration in milliseconds, executing a consumer with this future if the timeout occurs.SelftimeoutMs(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.Selfto(ARunnable t)Executes a runnable task upon successful completion in the current context.Selfto(java.util.concurrent.Executor executor, ARunnable t)Executes a runnable task on the provided executor upon successful completion.ARFuture<T>to2(java.util.concurrent.Executor executor, AConsumer<T> consumer)AFuturetoFuture()Converts this ARFuture into a void AFuture.java.lang.StringtoString()voidtoString(AString sb)ARFutureWithFlag<T>toWithFlag()Casts this ARFuture to its flag-carrying subclass.SelftryCancel()booleantryDone(T value)Attempts to complete the future with the given value.booleantryError(@NotNull java.lang.Throwable error)booleantryRequest()booleanupdateStatus(java.lang.Object result)Attempts to set the final result status using CompareAndSet.voidwaitSuccessful()booleanwaitSuccessful(long timeout)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.aether.utils.futures.AFutureBase
addListener, addListener2, cancel, error, getError, getNowRaw, isCanceled, isDone, isError, isFinalStatus, isNotDone, onCancel, onCancel, onError, onError, onError, setError, timeout, timeoutError, timeoutMs, timeoutMs, to, to, tryCancel, tryError, updateStatus
-
-
-
-
Method Detail
-
tryRequest
public boolean tryRequest()
-
to
public ARFuture<T> to(@NotNull @NotNull AConsumer<T> task, int timeout, ARunnable onTimeout)
Description copied from interface:ARFutureRegisters a success callback with a timeout action.
-
toWithFlag
public ARFutureWithFlag<T> toWithFlag()
Description copied from interface:ARFutureCasts this ARFuture to its flag-carrying subclass.- Specified by:
toWithFlagin interfaceARFuture<T>- Returns:
- The ARFutureWithFlag instance.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
and
public <T2> ARFuture<Tuple2<T,T2>> and(ARFuture<T2> f)
Description copied from interface:ARFutureChains this future with another, combining their results into a Tuple2.
-
to
public ARFuture<T> to(AConsumer<T> onDone, AConsumer<java.lang.Throwable> onError)
Description copied from interface:ARFutureRegisters a callback for success and another for error.
-
to
public ARFuture<T> to(AConsumer<T> onDone)
Description copied from interface:ARFutureRegisters a callback to be executed upon successful completion.
-
done
public void done(T value)
Description copied from interface:ARFutureCompletes the future with the given value.
-
tryDone
public boolean tryDone(T value)
Description copied from interface:ARFutureAttempts to complete the future with the given value.
-
get
public T get()
Description copied from interface:ARFutureGets the result of the future, waiting if necessary, and throws an exception on error/cancel.
-
get
public T get(int timeout)
-
getSeconds
public T getSeconds(int timout)
-
get
public T get(long timout)
Description copied from interface:ARFutureGets the result of the future with a timeout, waiting if necessary.
-
getNow
public T getNow()
Description copied from interface:ARFutureGets the result value if the future is already done, otherwise returns null.
-
getNowElse
public T getNowElse(T elseValue)
Description copied from interface:ARFutureGets the result value if the future is already done, otherwise returns the provided default value.- Specified by:
getNowElsein interfaceARFuture<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:ARFutureTransforms the successful result into a different type in a safe context (e.g., dedicated executor).
-
mapToFuture
@NotNull public @NotNull AFuture mapToFuture(@NotNull @NotNull AConsumer<T> f)
Description copied from interface:ARFutureMaps the result to a void AFuture and converts the result to an AFuture.- Specified by:
mapToFuturein interfaceARFuture<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:ARFutureTransforms the successful result into another ARFuture.- Specified by:
mapRFuturein interfaceARFuture<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:ARFutureTransforms the successful result into a different type using a function wrapped for Log context.
-
map
@NotNull public <E> @NotNull ARFuture<E> map(@NotNull @NotNull AFunction<T,E> f)
Description copied from interface:ARFutureTransforms the successful result into a different type using the provided function.
-
apply
public ARFuture<T> apply(ARunnable c)
Description copied from interface:ARFutureExecutes a runnable upon successful completion, preserving the original result.
-
apply
public ARFuture<T> apply(AConsumer<T> c)
Description copied from interface:ARFutureExecutes a consumer upon successful completion, preserving the 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:ARFutureTransfers the final status (done/error/cancel) to another future.
-
toFuture
public AFuture toFuture()
Description copied from interface:ARFutureConverts this ARFuture into a void AFuture.
-
onCancel
public Self onCancel(ARunnable l)
Description copied from interface:AFutureBaseRegisters a listener to be executed if the future completes with a cancellation.- Specified by:
onCancelin interfaceAFutureBase<Self extends AFutureBase<Self>>- Parameters:
l- The runnable task to execute on cancellation.
-
onCancel
public Self onCancel(AConsumer<Self> l)
Description copied from interface:AFutureBaseRegisters a listener to be executed if the future completes with a cancellation.- Specified by:
onCancelin interfaceAFutureBase<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:AFutureBaseRegisters a listener to be executed if the future completes with an error.- Specified by:
onErrorin interfaceAFutureBase<Self extends AFutureBase<Self>>- Parameters:
l- The consumer that accepts the Throwable error.- Returns:
- This future instance for chaining.
-
onError
public Self onError(AFuture l)
- Specified by:
onErrorin interfaceAFutureBase<Self extends AFutureBase<Self>>
-
onError
public Self onError(ARFuture<?> l)
- Specified by:
onErrorin interfaceAFutureBase<Self extends AFutureBase<Self>>
-
isFinalStatus
public boolean isFinalStatus()
Description copied from interface:AFutureBaseChecks if the future has reached a final state (Done, Error, or Canceled).- Specified by:
isFinalStatusin interfaceAFutureBase<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:AFutureBaseChecks if the final status is an error.- Specified by:
isErrorin interfaceAFutureBase<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:AFutureBaseCompletes the future with the given error.- Specified by:
errorin interfaceAFutureBase<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:AFutureBaseGets the error Throwable if the future is in an error state.- Specified by:
getErrorin interfaceAFutureBase<Self extends AFutureBase<Self>>- Returns:
- The error or null.
-
setError
public void setError(java.lang.Throwable e)
Description copied from interface:AFutureBaseSets the error Throwable. Same asAFutureBase.error(Throwable).- Specified by:
setErrorin interfaceAFutureBase<Self extends AFutureBase<Self>>- Parameters:
e- The Throwable error.
-
updateStatus
public boolean updateStatus(java.lang.Object result)
Attempts to set the final result status using CompareAndSet.- Specified by:
updateStatusin interfaceAFutureBase<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:AFutureBaseChecks if the future has not reached the Done state.- Specified by:
isNotDonein interfaceAFutureBase<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:AFutureBaseChecks if the future has reached the Done state (completed successfully).- Specified by:
isDonein interfaceAFutureBase<Self extends AFutureBase<Self>>- Returns:
- true if completed successfully.
-
isCanceled
public boolean isCanceled()
Description copied from interface:AFutureBaseChecks if the future has been canceled.- Specified by:
isCanceledin interfaceAFutureBase<Self extends AFutureBase<Self>>- Returns:
- true if canceled.
-
cancel
public void cancel()
Description copied from interface:AFutureBaseCancels the future.- Specified by:
cancelin interfaceAFutureBase<Self extends AFutureBase<Self>>
-
timeoutError
public Self timeoutError(int seconds, java.lang.String text)Description copied from interface:AFutureBaseSets a timeout duration in seconds, after which the future is automatically marked as an error.- Specified by:
timeoutErrorin interfaceAFutureBase<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:AFutureBaseSets a timeout duration in seconds, executing a task if the timeout occurs.- Specified by:
timeoutin interfaceAFutureBase<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:AFutureBaseSets a timeout duration in milliseconds, executing a task if the timeout occurs.- Specified by:
timeoutMsin interfaceAFutureBase<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:AFutureBaseSets a timeout duration in milliseconds, executing a consumer with this future if the timeout occurs.- Specified by:
timeoutMsin interfaceAFutureBase<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:AFutureBaseAdds a listener to the future's completion status.- Specified by:
addListenerin interfaceAFutureBase<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:AFutureBaseExecutes a runnable task on the provided executor upon successful completion.- Specified by:
toin interfaceAFutureBase<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:AFutureBaseExecutes a runnable task upon successful completion in the current context.- Specified by:
toin interfaceAFutureBase<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:AFutureBaseGets the raw result object. Intended for internal implementation use.- Specified by:
getNowRawin interfaceAFutureBase<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:
tryErrorin interfaceAFutureBase<Self extends AFutureBase<Self>>
-
tryCancel
public Self tryCancel()
- Specified by:
tryCancelin interfaceAFutureBase<Self extends AFutureBase<Self>>
-
-