public class CancellableThreads extends Object
execute(Interruptable)
, which will capture the executing thread and make sure it is interrupted in the case
cancellation.Modifier and Type | Class and Description |
---|---|
static class |
CancellableThreads.ExecutionCancelledException |
static interface |
CancellableThreads.Interruptable |
Constructor and Description |
---|
CancellableThreads() |
Modifier and Type | Method and Description |
---|---|
void |
cancel(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.
|
boolean |
isCancelled() |
protected void |
onCancel(String reason,
Throwable suppressedException)
called if
checkForCancel() was invoked after the operation was cancelled. |
public boolean isCancelled()
public void checkForCancel()
onCancel(String, java.lang.Throwable)
for custom failure logicprotected void onCancel(String reason, @Nullable Throwable 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 cancel(String reason)
checkForCancel()
will be failed with the given reasonCopyright © 2009–2016. All rights reserved.