T - type of resultTError - type of errorpublic class AsyncSupplier<T,TError extends Exception> extends Object implements IAsync<TError>, Future<T>
| Modifier and Type | Class and Description |
|---|---|
static interface |
AsyncSupplier.Listener<T,TError extends Exception>
Listener with one method by possible state.
|
| Constructor and Description |
|---|
AsyncSupplier()
Constructor.
|
AsyncSupplier(T result,
TError error)
Create an unblocked point with the given result and error.
|
AsyncSupplier(T result,
TError error,
CancelException cancel)
Create an unblocked point with the given result, error and cancellation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
block(long timeout)
Pause the current thread to wait for this asynchronous unit to be unblocked.
|
boolean |
blockPauseCondition()
Return true if blockPause should still block.
|
T |
blockResult(long timeout)
Block until this AsyncSupplier is unblocked or the given timeout expired,
and return the result in case of success, or throw the error or cancellation.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
void |
cancel(CancelException reason)
Cancel this object: unblock it immediately, and set the cancellation reason.
|
<TError2 extends Exception> |
convertError(Function<TError,TError2> converter)
Create an AsyncSupplier from the given one, adapting the error.
|
void |
error(TError error)
Unblock with an error.
|
void |
forward(AsyncSupplier<T,TError> sp)
Forward the result, error, or cancellation to the given AsyncSupplier.
|
<TError2 extends Exception> |
forward(AsyncSupplier<T,TError2> sp,
Function<TError,TError2> errorConverter)
Forward the result, error, or cancellation to the given AsyncSupplier.
|
T |
get() |
T |
get(long timeout,
TimeUnit unit) |
Collection<?> |
getAllListeners()
Return a collection with all listeners, only for debugging purposes.
|
CancelException |
getCancelEvent()
Get the reason of the cancellation.
|
TError |
getError()
Return the error.
|
T |
getResult() |
boolean |
hasError()
Return true if unblocked because of an error.
|
boolean |
isCancelled()
Return true if this object is cancelled.
|
boolean |
isDone()
Return true if unblocked (success or cancelled).
|
void |
listen(AsyncSupplier.Listener<T,TError> listener)
Add a listener to be called when this AsyncSupplier is unblocked.
|
void |
onDone(Async<TError> sp)
Transfer the result of this asynchronous unit to the given one:
unblock it on success, call error method on error, or call cancel method on cancellation.
|
void |
onDone(Consumer<T> onready)
Call one of the given listener on success.
|
void |
onDone(Consumer<T> onready,
Consumer<TError> onerror,
Consumer<CancelException> oncancel)
Call one of the given listener depending on result.
|
void |
onDone(Consumer<T> onready,
IAsync<TError> onErrorAndCancel)
Call onready on success, or forward error/cancellation to onErrorAndCancel.
|
<TError2 extends Exception> |
onDone(Consumer<T> onready,
IAsync<TError2> onErrorAndCancel,
Function<TError,TError2> errorConverter)
Call onready on success, or forward error/cancellation to onErrorAndCancel.
|
void |
onDone(Runnable r)
Call listener when unblocked (whatever the result is successful, has error or is cancelled).
|
void |
onDone(Runnable onready,
IAsync<TError> onErrorAndCancel)
Call listener when unblocked, or forward error/cancellation to onErrorOrCancel.
|
void |
reset()
Reset this AsyncSupplier point to reuse it.
|
boolean |
thenDoOrStart(Consumer<T> consumer,
String taskDescription,
byte taskPriority)
Call consumer immediately (in current thread) if done, or start a CPU task on done.
|
boolean |
thenDoOrStart(Consumer<T> consumer,
String taskDescription,
byte taskPriority,
IAsync<TError> onErrorOrCancel)
Call consumer immediately (in current thread) if done, or start a CPU task on done.
|
<T2> AsyncSupplier<T2,TError> |
thenStart(Task.Parameter<T,T2,TError> task,
boolean evenIfErrorOrCancel)
Start the given task when this asynchronous unit is unblocked.
|
void |
unblockCancel(CancelException event)
Cancel this AsyncSupplier.
|
void |
unblockError(TError error)
Unblock this AsyncSupplier with an error.
|
void |
unblockSuccess(T result)
Unblock this AsyncSupplier with the given result.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitblockException, blockPause, blockThrow, forwardIfNotSuccessful, isSuccessful, logListenerError, onCancel, onDone, onDone, onDone, onDone, onError, onErrorOrCancel, onSuccess, thenDoOrStart, thenDoOrStart, thenDoOrStart, thenStart, thenStart, thenStart, thenStart, thenStart, thenStart, toAsyncSupplierpublic AsyncSupplier()
public AsyncSupplier(T result, TError error)
public AsyncSupplier(T result, TError error, CancelException cancel)
public final T getResult()
public final CancelException getCancelEvent()
CancellablegetCancelEvent in interface Cancellablepublic final boolean isCancelled()
CancellableisCancelled in interface Future<T>isCancelled in interface Cancellablepublic final boolean hasError()
IAsyncpublic Collection<?> getAllListeners()
IAsyncgetAllListeners in interface IAsync<TError extends Exception>public final void listen(AsyncSupplier.Listener<T,TError> listener)
public final void forward(AsyncSupplier<T,TError> sp)
public final <TError2 extends Exception> void forward(AsyncSupplier<T,TError2> sp, Function<TError,TError2> errorConverter)
public final void onDone(Runnable r)
IAsyncpublic final void onDone(Async<TError> sp)
IAsyncpublic final void onDone(Consumer<T> onready, Consumer<TError> onerror, Consumer<CancelException> oncancel)
public final void onDone(Consumer<T> onready, IAsync<TError> onErrorAndCancel)
public final void onDone(Runnable onready, IAsync<TError> onErrorAndCancel)
IAsyncpublic final <TError2 extends Exception> void onDone(Consumer<T> onready, IAsync<TError2> onErrorAndCancel, Function<TError,TError2> errorConverter)
public final <TError2 extends Exception> AsyncSupplier<T,TError2> convertError(Function<TError,TError2> converter)
public <T2> AsyncSupplier<T2,TError> thenStart(Task.Parameter<T,T2,TError> task, boolean evenIfErrorOrCancel)
public boolean thenDoOrStart(Consumer<T> consumer, String taskDescription, byte taskPriority)
public boolean thenDoOrStart(Consumer<T> consumer, String taskDescription, byte taskPriority, IAsync<TError> onErrorOrCancel)
public final void unblockSuccess(T result)
public final void unblockError(TError error)
public final void error(TError error)
IAsyncpublic void unblockCancel(CancelException event)
public final void cancel(CancelException reason)
Cancellablecancel in interface Cancellablepublic final void block(long timeout)
IAsyncpublic final T blockResult(long timeout) throws TError extends Exception, CancelException
timeout - in milliseconds. 0 or negative value means infinite.TError extends ExceptionCancelExceptionpublic boolean blockPauseCondition()
IAsyncblockPauseCondition in interface IAsync<TError extends Exception>public final boolean isDone()
IAsyncpublic final void reset()
public final T get() throws InterruptedException, ExecutionException
get in interface Future<T>InterruptedExceptionExecutionExceptionpublic final T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get in interface Future<T>InterruptedExceptionExecutionExceptionTimeoutExceptionCopyright © 2019. All rights reserved.