Closed jpasski closed 8 years ago
Reading up on this forum post highlights an issue I
could easily hit: modifying the contents of an ECPProject
in a non-UI
thread. Eugen Neufeld and Edgar Mueller of EclipseSource responded to the
thread. Eugen's response indicates using EMF transactions:
Possible solutions to your problem would be to either use EMF transaction or use CDO as a backend (for which ECP has a provider). In case of EMF transaction, you would need to wrap all calls, that access the model, in commands.
Idea is as follows:
AdapterFactoryEditingDomain.getEditingDomainFor(project)
TransactionalEditingDomain
. The
EMFStore provider is of this type.
ChangeCommand
and override its doExecute
with what's being
edited. Construct it with an instance of Notifier
, which an EObject
is.
This begs the question: what about when a new Assessment
is being
created? In the case where Assessment
is being modified, then it seems
straighter forward. Looking at the example, Edgar creates a new Player
and then adds this to the ECPProject
contents directly. This would be the
same thing I'd do with an Assessment
. Cool.CommandStack
of the EditingDomain
and execute
the change
command.Seems straightforward.
Useful plugins:
Now reading Chapter 3.3.2 "EMF.Edit Commands" of the EMF book... OK, so a
ChangeCommand
uses the change recorder under the hood to create whatever
commands are necessary via arbitrary model changes. This seems like the best
way to do things.
So given an object, the service would return a ChangeCommand
instance. Can
ChangeCommand
s be composed? Doesn't seem so. Its constructor uses
ChangeRecorder
or Notifier
so no. That means the doExecute
would have to
perform all changes. OK.
The AddAssessment handler is called in the UI thread. It then calls an OSGi service to modify the
ECPProject
. Since this is now outside of the UI thread, which results in multi-threaded access to the model. From the EMF FAQ:EMF transactions, according to this forum response, should be a safe way to modify a model instance in multiple threads. This bug tracks modifying
AddApplicationSubscriber.addAsApplication
.