public abstract class CancelCriterion
extends java.lang.Object
checkCancelInProgress(Throwable)
. Generally the pattern is to check before performing an
operation, check if the service is canceled before propagating an exception further up the stack,
and check for cancellation inside a long loop. Eg.
while (true) { c.checkCancelInProgress(null); try { dispatchEvents(); } catch (IOException e) { c.checkCancelInProgress(e); throw e; } }
CancelException
Constructor and Description |
---|
CancelCriterion() |
Modifier and Type | Method and Description |
---|---|
abstract java.lang.String |
cancelInProgress()
Indicate if the service is in the progress of being cancelled.
|
void |
checkCancelInProgress(java.lang.Throwable e)
See if the current operation is being cancelled.
|
protected java.lang.String |
checkFailure()
Use this utility function in your implementation of cancelInProgress() and cancelled() to
indicate a system failure
|
abstract java.lang.RuntimeException |
generateCancelledException(java.lang.Throwable throwable)
Template factory method for generating the exception to be thrown by
checkCancelInProgress(Throwable) . |
boolean |
isCancelInProgress()
Checks to see if a cancellation is in progress.
|
public abstract java.lang.String cancelInProgress()
InterruptedException
, that the current operation should be
cancelled.protected java.lang.String checkFailure()
public void checkCancelInProgress(java.lang.Throwable e)
RuntimeException
(usually a CancelException
).e
- an underlying exception or null if there is no exception that triggered this checkcancelInProgress()
public abstract java.lang.RuntimeException generateCancelledException(java.lang.Throwable throwable)
checkCancelInProgress(Throwable)
. Override this to specify different exception for
checkCancelInProgress() to throw.
This method should wrap the exception in a service specific CancelationException (eg
CacheClosedException). or return null if the service is not being canceled.throwable
- an underlying exception, if anypublic boolean isCancelInProgress()