Class CancellableReadAction
- java.lang.Object
 - 
- jetbrains.mps.smodel.CancellableReadAction
 
 
- 
- All Implemented Interfaces:
 Runnable
public abstract class CancellableReadAction extends Object implements Runnable
EXPERIMENTAL FUNCTIONALITY, DON'T USE OUTSIDE OF MPS.IMPORTANT! Instances of the class are stateful and shall not be reused!
Facilitates
ModelAccessto cancel model read actions. Pass instance of this class instead of a regularRunnabletoModelAccess.runReadAction(Runnable)orModelAccess.runReadInEDT(Runnable)to indicate the outcome of read action is not essential/vital and the action could get cancelled.
Beware,ModelAccessimplementation is not obliged to honour this kind of runnables. If it does, it sendscancel()request to allCancellableReadActionat its own discretion, usually when a write or command action comes up. Depending onModelAccessimplementation, it might not be reasonable to useCancellableReadActionfrom a thread that is dedicated to writes/commands (e.g. EDT) as there's no chance for cancellation then.Read action may get cancelled prior to start and therefore subclass may not get control at all. Subclasses shall check
isCancelRequested()from time to time (as appropriate with respect to own safe locations) and stop execution as soon as possible once the flag has been noticed. Subclasses shall invokeconfirmCancel()in case they terminate execution according toisCancelRequested()request, and shall not perform any special activities if they complete in a regular fashion.
Right now there's no API to figure out cancellation/completion state of the action once it's over. The API might get added if a need arises. PLEASE don't try to guess internal state based on existing protected methods, introduce a dedicated, well-documented method instead.There's no counterpart to support
Computablecode that produces a value. Subclasses may declare own return value accessor with proper default value for the case read action had not been started at all.- Since:
 - 2018.3
 
 
- 
- 
Constructor Summary
Constructors Constructor Description CancellableReadAction() 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcancel()This is what external code use to indicate its intention to stop execution of this read actionprotected voidconfirmCancel()Subclasses shall invoke in response toisCancelRequested()they intend to honour.protected abstract voidexecute()Override with model read activities, pollisCancelRequested()as appropriateprotected booleanisCancelRequested()Note, this method shall not be used outside ofexecute()(i.e.voidrun() 
 - 
 
- 
- 
Method Detail
- 
cancel
public final void cancel()
This is what external code use to indicate its intention to stop execution of this read action 
- 
confirmCancel
protected final void confirmCancel()
Subclasses shall invoke in response toisCancelRequested()they intend to honour. Generally, it's the last call prior to return fromexecute()in case of cancellation. Don't invoke it in case of regular completion ofexecute(). 
- 
isCancelRequested
protected final boolean isCancelRequested()
Note, this method shall not be used outside ofexecute()(i.e. it doesn't make sense for post-mortem analysis)- Returns:
 trueif external code issued a cancel request
 
- 
execute
protected abstract void execute()
Override with model read activities, pollisCancelRequested()as appropriate 
 - 
 
 -