T - type of resultTError - type of errorpublic class AsyncWork<T,TError extends Exception> extends Object implements ISynchronizationPoint<TError>
| Modifier and Type | Class and Description |
|---|---|
static interface |
AsyncWork.AsyncWorkListener<T,TError>
Listener with one method by possible state.
|
| Constructor and Description |
|---|
AsyncWork()
Constructor.
|
AsyncWork(T result,
TError error)
Create an unblocked point with the given result and error.
|
AsyncWork(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 synchronization point to be unblocked.
|
void |
blockPause(long logAfter)
Really block, using wait method (used by threading system to know when a thread can be resumed).
|
T |
blockResult(long timeout)
Block until this AsyncWork is unblocked or the given timeout expired,
and return the result in case of success, or throw the error or cancellation.
|
void |
cancel(CancelException reason)
Cancel this synchronization point: unblock it immediately, and set the cancellation reason.
|
void |
error(TError error)
Unblock with an error.
|
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 unblocked because of a cancellation.
|
boolean |
isUnblocked()
Return true if unblocked (success or cancelled).
|
void |
listenInline(AsyncWork.AsyncWorkListener<T,TError> listener)
Add a listener to be called when this AsyncWork is unblocked.
|
void |
listenInline(AsyncWork<T,TError> sp)
Forward the result, error, or cancellation to the given AsyncWork.
|
void |
listenInline(Listener<T> onready,
ISynchronizationPoint<TError> onErrorAndCancel)
Call onready on success, or forward error/cancellation to onErrorAndCancel.
|
void |
listenInline(Listener<T> onready,
Listener<TError> onerror,
Listener<CancelException> oncancel)
Call one of the given listener depending on result.
|
void |
listenInline(Runnable r)
Call listener when unblocked (whatever the result is successful, has error or is cancelled).
|
void |
listenInline(Runnable onready,
ISynchronizationPoint<TError> onErrorAndCancel)
Call listener when unblocked, or forward error/cancellation to onErrorOrCancel.
|
void |
listenInline(SynchronizationPoint<TError> sp)
Transfer the result of this blocking point to the given synchronization point:
unblock it on success, call error method on error, or call cancel method on cancellation.
|
void |
reset()
Reset this AsyncWork point to reuse it.
|
void |
unblockCancel(CancelException event)
Cancel this AsyncWork.
|
void |
unblockError(TError error)
Unblock this AsyncWork with an error.
|
void |
unblockSuccess(T result)
Unblock this AsyncWork with the given result.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitblockException, blockThrow, forwardCancel, isSuccessful, listenAsync, listenAsync, listenAsyncSP, listenInline, listenInlineSP, listenInlineSP, onCancel, onError, onException, onSuccess, synchWithNoError, toAsyncWorkVoidpublic AsyncWork()
public AsyncWork(T result, TError error)
public AsyncWork(T result, TError error, CancelException cancel)
public T getResult()
public TError getError()
ISynchronizationPointgetError in interface ISynchronizationPoint<TError extends Exception>public CancelException getCancelEvent()
ISynchronizationPointgetCancelEvent in interface ISynchronizationPoint<TError extends Exception>public boolean isCancelled()
ISynchronizationPointisCancelled in interface ISynchronizationPoint<TError extends Exception>public boolean hasError()
ISynchronizationPointhasError in interface ISynchronizationPoint<TError extends Exception>public Collection<?> getAllListeners()
ISynchronizationPointgetAllListeners in interface ISynchronizationPoint<TError extends Exception>public void listenInline(AsyncWork.AsyncWorkListener<T,TError> listener)
public void listenInline(AsyncWork<T,TError> sp)
public void listenInline(SynchronizationPoint<TError> sp)
ISynchronizationPointlistenInline in interface ISynchronizationPoint<TError extends Exception>public void listenInline(Listener<T> onready, Listener<TError> onerror, Listener<CancelException> oncancel)
public void listenInline(Listener<T> onready, ISynchronizationPoint<TError> onErrorAndCancel)
public void listenInline(Runnable onready, ISynchronizationPoint<TError> onErrorAndCancel)
ISynchronizationPointlistenInline in interface ISynchronizationPoint<TError extends Exception>public void listenInline(Runnable r)
ISynchronizationPointlistenInline in interface ISynchronizationPoint<TError extends Exception>public void unblockSuccess(T result)
public void unblockError(TError error)
public void error(TError error)
ISynchronizationPointerror in interface ISynchronizationPoint<TError extends Exception>public void unblockCancel(CancelException event)
public void cancel(CancelException reason)
ISynchronizationPointcancel in interface ISynchronizationPoint<TError extends Exception>public void block(long timeout)
ISynchronizationPointblock in interface ISynchronizationPoint<TError extends Exception>public T blockResult(long timeout) throws TError extends Exception, CancelException
timeout - in milliseconds. 0 or negative value means infinite.TError extends ExceptionCancelExceptionpublic void blockPause(long logAfter)
ISynchronizationPointblockPause in interface ISynchronizationPoint<TError extends Exception>public boolean isUnblocked()
ISynchronizationPointisUnblocked in interface ISynchronizationPoint<TError extends Exception>public void reset()
Copyright © 2018. All rights reserved.