public class CancellableThreads
extends java.lang.Object
execute(Interruptable), which will capture the executing thread and make sure it is interrupted in the case
of cancellation.
Cancellation policy: This class does not support external interruption via Thread#interrupt(). Always use #cancel() instead.| Modifier and Type | Class and Description |
|---|---|
static class |
CancellableThreads.ExecutionCancelledException |
static interface |
CancellableThreads.Interruptable |
static interface |
CancellableThreads.IOInterruptable |
| Constructor and Description |
|---|
CancellableThreads() |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(java.lang.String reason)
cancel all current running operations.
|
void |
checkForCancel()
call this will throw an exception if operation was cancelled.
|
void |
execute(CancellableThreads.Interruptable interruptable)
run the Interruptable, capturing the executing thread.
|
void |
executeIO(CancellableThreads.IOInterruptable interruptable)
run the Interruptable, capturing the executing thread.
|
boolean |
isCancelled() |
protected void |
onCancel(java.lang.String reason,
java.lang.Exception suppressedException)
called if
checkForCancel() was invoked after the operation was cancelled. |
public boolean isCancelled()
public void checkForCancel()
onCancel(String, Exception) for custom failure logicprotected void onCancel(java.lang.String reason,
@Nullable
java.lang.Exception suppressedException)
checkForCancel() was invoked after the operation was cancelled.
the default implementation always throws an CancellableThreads.ExecutionCancelledException, suppressing
any other exception that occurred before cancellationreason - reason for failure supplied by the caller of cancel(java.lang.String)suppressedException - any error that was encountered during the execution before the operation was cancelled.public void execute(CancellableThreads.Interruptable interruptable)
cancel(String) will interrupt this thread
causing the call to prematurely return.interruptable - code to runpublic void executeIO(CancellableThreads.IOInterruptable interruptable) throws java.io.IOException
cancel(String) will interrupt this thread
causing the call to prematurely return.interruptable - code to runjava.io.IOExceptionpublic void cancel(java.lang.String reason)
checkForCancel() will be failed with the given reason