Package jetbrains.mps.smodel
Class ModelAccess
- java.lang.Object
 - 
- jetbrains.mps.smodel.AbstractModelAccess
 - 
- jetbrains.mps.smodel.ModelAccess
 
 
 
- 
- All Implemented Interfaces:
 ModelCommandExecutor,ModelAccess
public abstract class ModelAccess extends AbstractModelAccess implements ModelCommandExecutor, ModelAccess
This if front-end for legacy code that deals with a single instance of MA (available through MA.instance()). There are 2 implementations generally available, DefaultModelAccess and WorkbenchModelAccess. Neither is an openapi.ModelAccess available from SRepository#getModelAccess() call, opeanpi.MA instances from repository now merely delegate to the singleton available from #instance() method. For now, WMA provides implementation of methods that deal with Project (i.e. undo support), therefore we keep methods with Project as part of this class implementation API. Instead, we shall implement execute* methods in respective openapi.MA implementations bound to project repositories and remove Project-aware methods from this class altogether. We may want to keep this class for another release as DMA and WMA have different perspective on platform locking (latter adds IDEA platform locks), and with that, we may still delegate general read/write actions of repository's MA to this singleton. The actual implementation ofModelAccessinterface methods Probably it is better to merge it withProjectModelAccessandModelAccessBasewhich currently simply delegate all methods to this class- See Also:
 ModelAccess
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected static org.apache.log4j.LoggerLOGprotected static ModelAccessourInstance- 
Fields inherited from class jetbrains.mps.smodel.AbstractModelAccess
myCommandActionDispatcher, myReadActionDispatcher, myWriteActionDispatcher 
 - 
 
- 
Constructor Summary
Constructors Modifier Constructor Description protectedModelAccess() 
- 
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidassertNotWriteFromRead()booleancanRead()Indicates, whether the current thread holds the read lockbooleancanWrite()Indicates, whether the current thread holds the write lockabstract voidexecuteCommand(Runnable r)Represents a write action executed with respect to platform undo mechanism.voidexecuteCommandInEDT(Runnable r)Represents a write action executed with respect to platform undo mechanism, runs asynchronously from EDT thread.voidexecuteUndoTransparentCommand(Runnable r)FIXME need thorough documentation Executed code has model write, is treated as a command, the only difference is that changes from the transparent action merged with the that of the previous undoable commandprotected LockgetReadLock()protected LockgetWriteLock()booleanhasScheduledWrites()static ModelAccessinstance()Deprecated.booleanisCommandAction()booleanisInsideCommand()protected voidonCommandFinished()protected voidonCommandStarted()<T> TrunReadAction(Computable<T> c)<T> TrunWriteAction(Computable<T> c)booleansetReadEnabledFlag(boolean flag)Deprecated.<T> TtryRead(Computable<T> c)Returns the result of the computation, null if locking was unsuccessful.- 
Methods inherited from class jetbrains.mps.smodel.AbstractModelAccess
addCommandListener, addReadActionListener, addWriteActionListener, checkReadAccess, checkWriteAccess, removeCommandListener, removeReadActionListener, removeWriteActionListener 
- 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
- 
Methods inherited from interface org.jetbrains.mps.openapi.module.ModelAccess
addCommandListener, addReadActionListener, addWriteActionListener, checkReadAccess, checkWriteAccess, removeCommandListener, removeReadActionListener, removeWriteActionListener, runReadAction, runReadInEDT, runWriteAction, runWriteInEDT 
- 
Methods inherited from interface jetbrains.mps.smodel.ModelCommandExecutor
checkReadAccess, checkWriteAccess, flushEventQueue, runReadAction, runReadInEDT, runWriteAction, runWriteInEDT, tryRead 
 - 
 
 - 
 
- 
- 
Field Detail
- 
LOG
protected static final org.apache.log4j.Logger LOG
 
- 
ourInstance
protected static ModelAccess ourInstance
 
 - 
 
- 
Method Detail
- 
instance
@Deprecated public static ModelAccess instance()
Deprecated.It is better to useSRepository.getModelAccess()method to get the repository access.- Since:
 - 3.1
 
 
- 
getReadLock
protected Lock getReadLock()
 
- 
getWriteLock
protected Lock getWriteLock()
 
- 
runReadAction
public final <T> T runReadAction(Computable<T> c)
- Specified by:
 runReadActionin interfaceModelCommandExecutor
 
- 
runWriteAction
public final <T> T runWriteAction(Computable<T> c)
- Specified by:
 runWriteActionin interfaceModelCommandExecutor
 
- 
tryRead
public final <T> T tryRead(Computable<T> c)
Description copied from interface:ModelCommandExecutorReturns the result of the computation, null if locking was unsuccessful.- Specified by:
 tryReadin interfaceModelCommandExecutor- Returns:
 
 
- 
assertNotWriteFromRead
protected final void assertNotWriteFromRead()
 
- 
hasScheduledWrites
public boolean hasScheduledWrites()
 
- 
canRead
public boolean canRead()
Description copied from interface:ModelAccessIndicates, whether the current thread holds the read lock- Specified by:
 canReadin interfaceModelAccess- Specified by:
 canReadin interfaceModelCommandExecutor
 
- 
canWrite
public boolean canWrite()
Description copied from interface:ModelAccessIndicates, whether the current thread holds the write lock- Specified by:
 canWritein interfaceModelAccess- Specified by:
 canWritein interfaceModelCommandExecutor
 
- 
isInsideCommand
public final boolean isInsideCommand()
- Specified by:
 isInsideCommandin interfaceModelCommandExecutor
 
- 
executeCommand
public abstract void executeCommand(Runnable r)
Description copied from interface:ModelAccessRepresents a write action executed with respect to platform undo mechanism. This method shall be invoked from EDT thread only. UnlikeModelAccess.executeCommandInEDT(Runnable), this method executes synchronously- Specified by:
 executeCommandin interfaceModelAccess
 
- 
executeCommandInEDT
public final void executeCommandInEDT(Runnable r)
Description copied from interface:ModelAccessRepresents a write action executed with respect to platform undo mechanism, runs asynchronously from EDT thread. This method may be invoked from any thread.- Specified by:
 executeCommandInEDTin interfaceModelAccess
 
- 
executeUndoTransparentCommand
public final void executeUndoTransparentCommand(Runnable r)
Description copied from interface:ModelAccessFIXME need thorough documentation Executed code has model write, is treated as a command, the only difference is that changes from the transparent action merged with the that of the previous undoable command- Specified by:
 executeUndoTransparentCommandin interfaceModelAccess
 
- 
isCommandAction
public boolean isCommandAction()
- Specified by:
 isCommandActionin interfaceModelAccess- Returns:
 trueif there's a command (either withModelAccess.executeCommand(Runnable)orModelAccess.executeCommandInEDT(Runnable)) being executed
 
- 
onCommandStarted
protected void onCommandStarted()
- Overrides:
 onCommandStartedin classAbstractModelAccess
 
- 
onCommandFinished
protected void onCommandFinished()
- Overrides:
 onCommandFinishedin classAbstractModelAccess
 
- 
setReadEnabledFlag
@Deprecated public boolean setReadEnabledFlag(boolean flag)
Deprecated.Description copied from interface:ModelCommandExecutorEnables canRead() without actually acquiring the read lock (screw you, ReadWriteLock!). Requires read lock in the "parent" thread. Thread local. Returns previous value, to which it must be reset after use (in finally{}).- Specified by:
 setReadEnabledFlagin interfaceModelCommandExecutor- Returns:
 - previous value
 
 
 - 
 
 -