@Beta @PublicAPI public interface CancelObserverCallback to propagate cancel requests into long running tasks.
Cancel request propagation is part of the functionality provided by
ProgressObserver, however it is a cross cutting concern, so it is exposed as a separate interface.
Thread safety: implementations are not required to be thread safe. Observed processes must be prepared for working with non thread safe observers. Consequently observer methods can be called only on the thread invoked the observed function. Alternatively proper synchronization must be ensured by the observed code.
Please note that this interface is marked with
Betaannotation, so it can be subject of incompatible changes or removal in any of the later releases.
boolean isCancelled()Returns whether cancellation of current operation has been requested.
Long running/memory intensive operations should poll to see if cancelation has been requested. Since time-out based cancelations might be implemented polling should not be done too often.
It is expected that implementations wont return
truevalue returned. It is also expected that implementations tolerate multiple calls regardless of the cancallation state.
Please note that test cases might check for too frequent invocations, so the propagation of any
AssertionErrorthrown by this method should not be obstructed.
It is usually expected that the cancelled task should throw
CancellationExceptionand this behavior should be documented in their APIdocs.
- true if cancellation has been requested, false otherwise.