|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl
public class TransactionalEditingDomainImpl
The default implementation of the transactional editing domain.
Since 1.2, this class implements the Adaptable
interface to adapt
to the following optional API:
TransactionalEditingDomain.DefaultOptions
TransactionalEditingDomain.Lifecycle
(since 1.3)Transaction.Option.Registry
(since 1.3)
Nested Class Summary | |
---|---|
static class |
TransactionalEditingDomainImpl.FactoryImpl
Default implementation of a transaction editing domain factory. |
protected class |
TransactionalEditingDomainImpl.LifecycleImpl
Default implementation of the InternalLifecycle protocol. |
static class |
TransactionalEditingDomainImpl.RegistryImpl
Implementation of the global editing domain registry. |
static class |
TransactionalEditingDomainImpl.ValidatorFactoryImpl
Default implementation of the validator factory |
Nested classes/interfaces inherited from class org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain |
---|
AdapterFactoryEditingDomain.AdapterFactoryEditingDomainResourceSet, AdapterFactoryEditingDomain.DomainTreeIterator<E>, AdapterFactoryEditingDomain.EditingDomainProvider |
Nested classes/interfaces inherited from interface org.eclipse.emf.transaction.TransactionalEditingDomain |
---|
TransactionalEditingDomain.DefaultOptions, TransactionalEditingDomain.Factory, TransactionalEditingDomain.Lifecycle, TransactionalEditingDomain.Registry |
Field Summary |
---|
Fields inherited from class org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain |
---|
adapterFactory, clipboard, commandStack, optimizeCopy, resourceSet, resourceToReadOnlyMap |
Constructor Summary | |
---|---|
TransactionalEditingDomainImpl(AdapterFactory adapterFactory)
Initializes me with my adapter factory and default implementations of a resource set and a command stack. |
|
TransactionalEditingDomainImpl(AdapterFactory adapterFactory,
ResourceSet resourceSet)
Initializes me with my adapter factory and a resource set, and a default command stack implementation. |
|
TransactionalEditingDomainImpl(AdapterFactory adapterFactory,
TransactionalCommandStack stack)
Initializes me with my adapter factory and a command stack, and a default resource set implementation. |
|
TransactionalEditingDomainImpl(AdapterFactory adapterFactory,
TransactionalCommandStack stack,
ResourceSet resourceSet)
Initializes me with my adapter factory, command stack, and resource set. |
Method Summary | ||
---|---|---|
void |
activate(InternalTransaction tx)
Activates (starts) the specified transaction. |
|
void |
addResourceSetListener(ResourceSetListener l)
Adds a resource set listener to me, to receive notifications of changes to the resource set when transactions commit. |
|
void |
broadcastUnbatched(Notification notification)
Broadcasts the specified notification to listeners as a singleton list, in a situation where batching is not possible because events are occurring outside of any transaction context. |
|
protected TransactionChangeRecorder |
createChangeRecorder(ResourceSet rset)
May be overridden by subclasses to create a custom change recorder implementation. |
|
protected TransactionalEditingDomainImpl.LifecycleImpl |
createLifecycle()
Creates a new lifecycle implementation. |
|
protected Transaction.OptionMetadata.Registry |
createOptionMetadataRegistry()
Creates a new transaction option metadata registry. |
|
RunnableWithResult<Object> |
createPrivilegedRunnable(Runnable runnable)
Wraps the specified runnable to give it access to the currently
active transaction. |
|
void |
deactivate(InternalTransaction tx)
Deactivates the specified transaction. |
|
void |
dispose()
Disposes of this editing domain and any resources that it has allocated. |
|
void |
endPrivileged(PrivilegedRunnable<?> runnable)
Returns me to my previous owner, upon completion of the specified privileged runnable. |
|
InternalTransaction |
getActiveTransaction()
Obtains the transaction that currently has access to me, and whose thread of execution is active. |
|
|
getAdapter(Class<? extends T> adapterType)
Obtains an instance of the specified adapter type. |
|
protected ResourceSetListener[] |
getAggregatePrecommitListeners()
Obtains a copy of my aggregate pre-commit listener list as an array, for safe iteration that allows concurrent updates to the original list. |
|
TransactionChangeRecorder |
getChangeRecorder()
Obtains the change recorder that I use to track changes in my resource set. |
|
protected static String |
getDebugID(Transaction tx)
Obtains an ID suitable for display in debug/trace messages. |
|
protected static String |
getDebugID(TransactionalEditingDomain domain)
Obtains an ID suitable for display in debug/trace messages. |
|
Map<?,?> |
getDefaultTransactionOptions()
Obtains a read-only view of the editing domain's default transaction options. |
|
String |
getID()
Obtains my unique ID. |
|
protected TransactionalEditingDomainImpl.LifecycleImpl |
getLifecycle()
Obtains my lazily-created lifecycle implementation. |
|
protected Transaction.OptionMetadata.Registry |
getOptionMetadata()
Obtains my lazily-created transaction option metadata registry. |
|
protected ResourceSetListener[] |
getPostcommitListeners()
Obtains a copy of my post-commit listener list as an array, for safe iteration that allows concurrent updates to the original list. |
|
protected ResourceSetListener[] |
getPrecommitListeners()
Obtains a copy of my pre-commit listener list as an array, for safe iteration that allows concurrent updates to the original list. |
|
protected InternalTransactionalCommandStack |
getTransactionalCommandStack()
Obtains my command stack as the internal interface. |
|
Map<Object,Object> |
getUndoRedoOptions()
Retrieves the undo/redo options that should be used when creating transactions. |
|
TransactionValidator |
getValidator()
Gets the validator that transactions should use to validate themselves upon committing. |
|
TransactionValidator.Factory |
getValidatorFactory()
Obtains the factory that this transactional editing domain uses to create validators for transaction validation. |
|
protected void |
postcommit(InternalTransaction tx)
Performs post-commit processing of the specified transaction. |
|
void |
precommit(InternalTransaction tx)
Performs the pre-commit notifications and processing of trigger comamnds. |
|
void |
removeResourceSetListener(ResourceSetListener l)
Removes a resource set listener from me. |
|
Object |
runExclusive(Runnable read)
Runs an operation that requires exclusive access to my resource set, for reading. |
|
void |
setDefaultTransactionOptions(Map<?,?> options)
Sets the default transaction options. |
|
void |
setID(String id)
Sets my unique ID. |
|
protected void |
setValidator(TransactionValidator newValidator)
|
|
void |
setValidatorFactory(TransactionValidator.Factory validatorFactory)
Sets the factory to use when creating validators for transaction validation. |
|
void |
startPrivileged(PrivilegedRunnable<?> runnable)
Transfers ownership of this editing domain to the specified privileged runnable. |
|
InternalTransaction |
startTransaction(boolean readOnly,
Map<?,?> options)
Creates and starts a new transaction. |
|
void |
yield()
Temporarily yields access to another read-only transaction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.eclipse.emf.edit.domain.EditingDomain |
---|
createCommand, createOverrideCommand, createResource, getChildren, getClipboard, getCommandStack, getNewChildDescriptors, getOptimizeCopy, getParent, getResourceSet, getRoot, getTreePath, isControllable, isReadOnly, loadResource, setClipboard, treeIterator |
Constructor Detail |
---|
public TransactionalEditingDomainImpl(AdapterFactory adapterFactory, TransactionalCommandStack stack, ResourceSet resourceSet)
adapterFactory
- my adapter factorystack
- my command stackresourceSet
- my resource setpublic TransactionalEditingDomainImpl(AdapterFactory adapterFactory, TransactionalCommandStack stack)
adapterFactory
- my adapter factorystack
- my command stackpublic TransactionalEditingDomainImpl(AdapterFactory adapterFactory, ResourceSet resourceSet)
adapterFactory
- my adapter factoryresourceSet
- my resource setpublic TransactionalEditingDomainImpl(AdapterFactory adapterFactory)
adapterFactory
- my adapter factoryMethod Detail |
---|
protected TransactionChangeRecorder createChangeRecorder(ResourceSet rset)
rset
- a resource set in which to record changes
public final String getID()
TransactionalEditingDomain
TransactionalEditingDomain.Registry
(if I am registered).
getID
in interface TransactionalEditingDomain
TransactionalEditingDomain.Registry.getEditingDomain(String)
public final void setID(String id)
TransactionalEditingDomain
TransactionalEditingDomain.Registry
,
then I am re-registered under this new ID. However, if I am registered
statically on the org.eclipse.emf.transaction.editingDomains
extension point, then my ID cannot be changed.
setID
in interface TransactionalEditingDomain
id
- my new unique identifierTransactionalEditingDomain.getID()
,
TransactionalEditingDomain.Registry.add(String, TransactionalEditingDomain)
protected static String getDebugID(TransactionalEditingDomain domain)
domain
- the editing domain for which to get the debug ID
public void addResourceSetListener(ResourceSetListener l)
TransactionalEditingDomain
addResourceSetListener
in interface TransactionalEditingDomain
l
- a new resource set listenerResourceSetListener.isPrecommitOnly()
,
ResourceSetListener.isPostcommitOnly()
public void removeResourceSetListener(ResourceSetListener l)
TransactionalEditingDomain
removeResourceSetListener
in interface TransactionalEditingDomain
l
- a resource set listener to removeprotected InternalTransactionalCommandStack getTransactionalCommandStack()
public Object runExclusive(Runnable read) throws InterruptedException
TransactionalEditingDomain
RunnableWithResult
interface, then its result is returned after it completes. Moreover,
(and this is a very good reason to implement this extension interface),
if the transaction rolls back on commit, then the RunnableWithResult
is provided with the error status indicating this condition. Even read-only
transactions can roll back when, for example, another thread concurrently
modifies the model (in violation of the transaction protocol), and it is
important to know when corrupted data may have been read.
Note that this method will block the current thread until exclusive access to the resource set can be obtained. However, it is safe to call this method on the Eclipse UI thread because special precaution is taken to ensure that liveness is maintained (using mechanisms built into the Job Manager).
Note: Since the 1.2 release, the
TransactionUtil.runExclusive(TransactionalEditingDomain, RunnableWithResult)
utility provides type-safe execution of runnables returning results and
should be preferred over this API.
runExclusive
in interface TransactionalEditingDomain
read
- a read-only operation to execute
RunnableWithResult
and the transaction did not roll back;
null
, otherwise
InterruptedException
- if the current thread is interrupted while
waiting for access to the resource setTransactionUtil#runExclusive(RunnableWithResult)
,
Transaction.commit()
public void yield()
TransactionalEditingDomain
TransactionalEditingDomain
supports any number of pseudo-concurrent
read-only transactions. Transactions that are expected to be
long-running should yield frequently, as a task running in a progress
monitor is expected to check for cancellation frequently. However, there
is a higher cost (in time) associated with yielding, so it should not
be overdone.
Only read-only transactions may yield, and only the transaction that is currently active in the editing domain may yield. The yielding transaction may be nested, but not within a read/write transaction at any depth.
Upon yielding, some other read-only transaction that is attempting to start or to return from a yield will take control of the editing domain. Control is never yielded to a read/write transaction (not even to a read-only transaction nested in a read/write) because this would introduce dirty reads (transactions reading uncommitted changes). If there are no other read-only transactions to receive the transfer of control, then the call returns immediately. Otherwise, control is transferred in FIFO fashion to waiting transactions.
yield
in interface TransactionalEditingDomain
public InternalTransaction startTransaction(boolean readOnly, Map<?,?> options) throws InterruptedException
InternalTransactionalEditingDomain
startTransaction
in interface InternalTransactionalEditingDomain
readOnly
- true
if the transaction is intended only
to read the resource set; false
if it will modify itoptions
- the options to apply to the transaction (as specified by
the TransactionalCommandStack
interface
InterruptedException
- if the current thread is interrupted while
waiting for the transaction to startInternalTransactionalEditingDomain.activate(InternalTransaction)
protected static String getDebugID(Transaction tx)
tx
- the transaction for which to get the debug ID
public TransactionChangeRecorder getChangeRecorder()
InternalTransactionalEditingDomain
getChangeRecorder
in interface InternalTransactionalEditingDomain
public TransactionValidator getValidator()
InternalTransactionalEditingDomain
getValidator
in interface InternalTransactionalEditingDomain
protected void setValidator(TransactionValidator newValidator)
protected final ResourceSetListener[] getPrecommitListeners()
protected final ResourceSetListener[] getAggregatePrecommitListeners()
protected final ResourceSetListener[] getPostcommitListeners()
public InternalTransaction getActiveTransaction()
InternalTransactionalEditingDomain
getActiveTransaction
in interface InternalTransactionalEditingDomain
null
if no transaction
is currently activepublic void activate(InternalTransaction tx) throws InterruptedException
InternalTransactionalEditingDomain
Note that only the thread that owns a transaction may activate it. Also, a nested read-write transaction cannot be activated if its parent transaction is read-only, unless the read-write transaction has the 'unprotected' option.
activate
in interface InternalTransactionalEditingDomain
tx
- the transaction to activate
InterruptedException
- if the current thread is interrupted while
waiting for me to activate its transactionInternalTransactionalEditingDomain.getActiveTransaction()
,
TransactionalEditingDomain.yield()
,
InternalTransactionalEditingDomain.startTransaction(boolean, Map)
,
InternalTransactionalEditingDomain.deactivate(InternalTransaction)
public void deactivate(InternalTransaction tx)
InternalTransactionalEditingDomain
active transaction
.
The current thread must own the transaction that it is attempting to deactivate and this transaction must currently be my active transaction.
Note that a transaction must ensure that this method is called when it closes, either by commit or by rollback, and at most once.
deactivate
in interface InternalTransactionalEditingDomain
tx
- the transaction to deactivateInternalTransactionalEditingDomain.activate(InternalTransaction)
,
Transaction.commit()
,
Transaction.rollback()
public void precommit(InternalTransaction tx) throws RollbackException
InternalTransactionalEditingDomain
precommit
in interface InternalTransactionalEditingDomain
tx
- the transaction that is being committed
RollbackException
- if any of the pre-commit listeners forces
rollback of the transaction. The caller must honour this rollback
request by actually rolling back
the transactionTransaction.commit()
,
Transaction.rollback()
,
ResourceSetListener.transactionAboutToCommit(org.eclipse.emf.transaction.ResourceSetChangeEvent)
protected void postcommit(InternalTransaction tx)
tx
- the transaction that has committedpublic void broadcastUnbatched(Notification notification)
InternalTransactionalEditingDomain
broadcastUnbatched
in interface InternalTransactionalEditingDomain
notification
- the notification to send to resource set listenersNotificationFilter.READ
,
ResourceSetListener
,
FilterManager.selectUnbatched(java.util.List, NotificationFilter)
public final RunnableWithResult<Object> createPrivilegedRunnable(Runnable runnable)
TransactionalEditingDomain
runnable
to give it access to the currently
active transaction. This is useful for two or more cooperating threads
to share a transaction (read-only or read-write), executing code in
the a runnable
on one thread in the context of another
thread's transaction.
For example, in an Eclipse UI application, this might be used when a long-running task in a modal context thread needs to synchronously execute some operation on the UI thread, which operation needs to read or write the editing domain. e.g.,
Runnable uiBoundAction = // ... Runnable privileged = domain.createPrivilegedRunnable(uiBoundAction); Display.syncExec(privileged);
Note that it is critically important that this mechanism only be used to share a transaction with another thread synchronously. Or, more generally, during the execution of the privileged runnable, the thread that originally owned the transaction no longer does, and may not access the editing domain. Upon completion of the privileged runnable, the transaction is returned to its original owner.
Also, the resulting runnable may only be executed while the currently
active transaction remains active. Any attempt to execute the runnable
after this transaction has committed or while a nested transaction is
active will result in an IllegalStateException
.
Note: Since the 1.2 release, the
TransactionUtil.createPrivilegedRunnable(TransactionalEditingDomain, RunnableWithResult)
utility provides type-safe privileged access for runnables returning
results and should be preferred over this API.
createPrivilegedRunnable
in interface TransactionalEditingDomain
runnable
- a runnable to execute in the context of the active
transaction, on any thread
runnable
is a RunnableWithResult
, then the privileged runnable will
inherit its result when it completesTransactionUtil.createPrivilegedRunnable(TransactionalEditingDomain, RunnableWithResult)
public void startPrivileged(PrivilegedRunnable<?> runnable)
InternalTransactionalEditingDomain
startPrivileged
in interface InternalTransactionalEditingDomain
runnable
- the runnable whose thread is to borrow mepublic void endPrivileged(PrivilegedRunnable<?> runnable)
InternalTransactionalEditingDomain
endPrivileged
in interface InternalTransactionalEditingDomain
runnable
- the runnable whose thread had borrowed mepublic void dispose()
TransactionalEditingDomain
Note that editing domains registered on the extension point may not be disposed.
dispose
in interface TransactionalEditingDomain
public Map<Object,Object> getUndoRedoOptions()
InternalTransactionalEditingDomain
getUndoRedoOptions
in interface InternalTransactionalEditingDomain
public <T> T getAdapter(Class<? extends T> adapterType)
Adaptable
getAdapter
in interface Adaptable
T
- the interface for which to get an adapteradapterType
- the required interface
null
if I do not supply this interfacepublic Map<?,?> getDefaultTransactionOptions()
TransactionalEditingDomain.DefaultOptions
getDefaultTransactionOptions
in interface TransactionalEditingDomain.DefaultOptions
public void setDefaultTransactionOptions(Map<?,?> options)
TransactionalEditingDomain.DefaultOptions
setDefaultTransactionOptions
in interface TransactionalEditingDomain.DefaultOptions
options
- the new options. The options are copied from the mappublic void setValidatorFactory(TransactionValidator.Factory validatorFactory)
validatorFactory
- the factory to setpublic TransactionValidator.Factory getValidatorFactory()
If the validator factory has yet to be initialized, it is initialized using the default validator factory.
protected final TransactionalEditingDomainImpl.LifecycleImpl getLifecycle()
protected TransactionalEditingDomainImpl.LifecycleImpl createLifecycle()
protected final Transaction.OptionMetadata.Registry getOptionMetadata()
protected Transaction.OptionMetadata.Registry createOptionMetadataRegistry()
|
Copyright 2002, 2007 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |