public abstract class CancelCriterion extends Object
checkCancelInProgress(Throwable)
. Generally the pattern is to check
before performing an operation, check if the service is canceled before propgrating
an exception futher up the stack, and check for cancelation 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 String |
cancelInProgress()
Indicate if the service is in the progress of being cancelled.
|
void |
checkCancelInProgress(Throwable e)
See if the current operation is being cancelled.
|
abstract RuntimeException |
generateCancelledException(Throwable e)
Template factory method for generating the exception to be thrown by
checkCancelInProgress(Throwable) . |
public abstract String cancelInProgress()
InterruptedException
,
that the current operation should be cancelled.public final void checkCancelInProgress(Throwable e)
RuntimeException
(usually a CancelException
).e
- an underlying exception or null if there is no exception
that triggered this checkcancelInProgress()
public abstract RuntimeException generateCancelledException(Throwable e)
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.e
- an underlying exception, if anyCopyright © 1997-2017 Pivotal Software, Inc. All rights reserved.