CoastalHacking / semiotics-main

Semiotics models and stand-alone product / UI
Apache License 2.0
0 stars 0 forks source link

Modify AddApplicationSubscriber.addAsApplication to use an EMF Change Command #38

Closed jpasski closed 8 years ago

jpasski commented 8 years ago

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:

The expectation is that a complete instance of the model (including resources and resource set, if present) should only be accessed by one thread at a time, and that the synchronization should be provided by the application at a higher level.

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.

jpasski commented 8 years ago

EMF Transactions

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:

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 ChangeCommands 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.