Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMFStore] Detecting changes of operations
[EMFStore] Detecting changes of operations [message #1693170] Wed, 22 April 2015 08:47 Go to next message
Yuriy Flyud is currently offline Yuriy FlyudFriend
Messages: 12
Registered: January 2015
Location: Lviv, Ukraine
Junior Member
I tried to improve performance of application and noticed that I can perform some actions not on every model change but after some operation.

I created a SimpleOperationObserver instance where I fire changes using model ids of AbstractOperation argument in operationPerformed method. The problem is that I cannot get deleted objects from this method, as Project.getModelElement(ModelElementId) returns null for objects that do not exist withing the project anymore.

Is there a nice solution to get all added/modified/deleted EObject elements after some operation or command?
Re: [EMFStore] Detecting changes of operations [message #1693919 is a reply to message #1693170] Wed, 29 April 2015 09:47 Go to previous messageGo to next message
Edgar Mueller is currently offline Edgar MuellerFriend
Messages: 89
Registered: March 2011
Member
Hi Yuriy,

sorry for the delay, I somehow missed your question.
Yes, there is such a possibility to retrieve deleted elements (or their
respective IDs) but you need to adhere two things:

- you need to use the internal API, since we intentionally did not
expose any of the data structures that maintain deleted elements and
- you need to use commands and you can only retrieve deleted elements
within such a command

Here's basic example that illustrates both points which is based on our
tests:

@Test
public void getIdForDeletedElement() {

final Project project = getProject();
final TestElement testElement = Create.testElement();
Add.toProject(getLocalProject(), testElement);

final ModelElementId testElementId =
project.getModelElementId(testElement);

new EMFStoreCommand() {
@Override
protected void doRun() {
project.deleteModelElement(testElement);

// necessary cast to IdEObjectCollectionImpl
final ModelElementId testElementIdAfterDeletion =
((IdEObjectCollectionImpl) project)
.getDeletedModelElementId(testElement);
assertEquals(testElementId, testElementIdAfterDeletion);
}
}.run(false);

// after command completion the element is gone
assertNull(project.getModelElementId(testElement));
}

Hope this helps,
Edgar

> I tried to improve performance of application and noticed that I can
> perform some actions not on every model change but after some operation.
>
> I created a SimpleOperationObserver instance where I fire changes using
> model ids of AbstractOperation argument in operationPerformed method.
> The problem is that I cannot get deleted objects from this method, as
> Project.getModelElement(ModelElementId) returns null for objects that do
> not exist withing the project anymore.
>
> Is there a nice solution to get all added/modified/deleted EObject
> elements after some operation or command?


--
Edgar Mueller

Get Professional Eclipse Support: http://eclipsesource.com/munich
Re: [EMFStore] Detecting changes of operations [message #1694580 is a reply to message #1693919] Wed, 06 May 2015 12:52 Go to previous messageGo to next message
Yuriy Flyud is currently offline Yuriy FlyudFriend
Messages: 12
Registered: January 2015
Location: Lviv, Ukraine
Junior Member
Hi Edgar,
Thank you so much for your answer! This works as expected and finally I could remove all the rude workarounds. There is only one thing left. In the end of my "operationPerformed" method I notify all observers about changed/deleted objects. This looks like this:
ESWorkspaceProviderImpl.getObserverBus().notify(ESLocalProjectContentObserver.class).projectContentChanged(project, changedObjects, deletedObjects);
One of the observers is a Decorator that decorates the navigator in a separate thread. The exception I get is the following:
_____________________________________________________________________________________
!ENTRY org.eclipse.emf.emfstore.common.model 2 2 2015-05-06 15:41:07.284
!MESSAGE Command Observer threw exception
!STACK 0
java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at org.eclipse.emf.emfstore.internal.client.model.impl.ProjectSpaceBase.addOperations(ProjectSpaceBase.java:191)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationManager.operationsRecorded(OperationManager.java:177)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationRecorder.operationsRecorded(OperationRecorder.java:306)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationRecorder.commandCompleted(OperationRecorder.java:521)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationRecorder.commandCompleted(OperationRecorder.java:468)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationManager.commandCompleted(OperationManager.java:226)
at org.eclipse.emf.emfstore.internal.client.model.changeTracking.commands.EMFStoreCommandNotifier$3.run(EMFStoreCommandNotifier.java:96)
at org.eclipse.emf.emfstore.common.ESSafeRunner.run(ESSafeRunner.java:38)
at org.eclipse.emf.emfstore.internal.client.model.changeTracking.commands.EMFStoreCommandNotifier.notifiyListenersAboutCommandCompleted(EMFStoreCommandNotifier.java:104)
at org.eclipse.emf.emfstore.internal.client.model.changeTracking.commands.EMFStoreBasicCommandStack.execute(EMFStoreBasicCommandStack.java:79)
at org.eclipse.emf.emfstore.internal.client.model.util.AbstractEMFStoreCommand.aRun(AbstractEMFStoreCommand.java:108)
at org.eclipse.emf.emfstore.internal.client.model.util.EMFStoreCommandWithResult.run(EMFStoreCommandWithResult.java:59)
at org.eclipse.emf.emfstore.client.util.RunESCommand.runWithResult(RunESCommand.java:171)
at org.eclipse.emf.emfstore.internal.client.model.impl.api.ESWorkspaceImpl.getLocalProject(ESWorkspaceImpl.java:176)
at com.ibi.id.ui.navigator.decorators.ValidationFailedDecorator.decorate(ValidationFailedDecorator.java:45)
at org.eclipse.ui.internal.decorators.LightweightDecoratorDefinition.decorate(LightweightDecoratorDefinition.java:269)
at org.eclipse.ui.internal.decorators.LightweightDecoratorManager$LightweightRunnable.run(LightweightDecoratorManager.java:81)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.decorators.LightweightDecoratorManager.decorate(LightweightDecoratorManager.java:365)
at org.eclipse.ui.internal.decorators.LightweightDecoratorManager.getDecorations(LightweightDecoratorManager.java:347)
at org.eclipse.ui.internal.decorators.DecorationScheduler$1.ensureResultCached(DecorationScheduler.java:371)
at org.eclipse.ui.internal.decorators.DecorationScheduler$1.run(DecorationScheduler.java:331)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

_____________________________________________________________________________________

Looks like ESWorkspaceProvider.INSTANCE.getWorkspace().getLocalProject(element) is not thread safe. Is there some special way for calling EMFStore functionality (e.g. through ESCommand)? Are there any other ways to provide thread safety?
Thank you in advance!
Re: [EMFStore] Detecting changes of operations [message #1694693 is a reply to message #1693919] Thu, 07 May 2015 08:34 Go to previous messageGo to next message
Yuriy Flyud is currently offline Yuriy FlyudFriend
Messages: 12
Registered: January 2015
Location: Lviv, Ukraine
Junior Member
Edgar, in addition to my reply about ConcurrentModificationException there is one more issue that really looks like a bug and is more related to the original question.

The getDeletedModelElement method works fine. But only when performing new operations. For undo - deleted elements can't be retrieved by the id I get from operation affected elements. I get nothing also when calling getModelElement by the same id here.

I don't think this is an expected behavior but need you input before creating an issue in Bugzilla.
Re: [EMFStore] Detecting changes of operations [message #1695083 is a reply to message #1694693] Mon, 11 May 2015 21:13 Go to previous messageGo to next message
Edgar Mueller is currently offline Edgar MuellerFriend
Messages: 89
Registered: March 2011
Member
Hi Yuriy,

regarding the ConcurrentModificationException: I'll try to investigate
this, but please feel to free to report this as a bug. Meanwhile, you
could you try to fallback to the internal API (see implementation of
ESWorkspace#getLocalProject(EObject)) that avoids the outer command.

Concerning the undo/redo issue: how did you implement redo/undo?
Ideally, can you provide a test case?

Thanks,
Edgar

> Edgar, in addition to my reply about ConcurrentModificationException
> there is one more issue that really looks like a bug and is more related
> to the original question.
>
> The getDeletedModelElement method works fine. But only when performing
> new operations. For undo - deleted elements can't be retrieved by the id
> I get from operation affected elements. I get nothing also when calling
> getModelElement by the same id here.
>
> I don't think this is an expected behavior but need you input before
> creating an issue in Bugzilla.


--
Edgar Mueller

Get Professional Eclipse Support: http://eclipsesource.com/munich
Re: [EMFStore] Detecting changes of operations [message #1695300 is a reply to message #1695083] Wed, 13 May 2015 11:54 Go to previous messageGo to next message
Yuriy Flyud is currently offline Yuriy FlyudFriend
Messages: 12
Registered: January 2015
Location: Lviv, Ukraine
Junior Member
Edgar,

Here is the undo sample:
new UIUndoLastOperationController(getShell(), requireSelection(ESLocalProjectImpl.class))
                .execute();

I register observer via:
((ESLocalProjectImpl) esLocalProject).toInternalAPI().getOperationManager().addOperationObserver(observer);


Regarding internal API - I will try. I will create the issue as well after some additional investigation.
Thanks!

Best regards,
Yuriy
Re: [EMFStore] Detecting changes of operations [message #1695722 is a reply to message #1695300] Mon, 18 May 2015 15:42 Go to previous messageGo to next message
Edgar Mueller is currently offline Edgar MuellerFriend
Messages: 89
Registered: March 2011
Member
Yuriy,

thanks for the info.

The reason for getDeletedModelElement returning null during an undo of a
reversed create (that is, a delete) is a current limitation of our API,
since we always clear our internal deleted element caches when a delete
operation has been applied, which causes the getDeletedModelElement to
find nothing. Please file a bug for this issue.

Depending on what you are trying to do with the deleted element, a
possible workaround might be to check if you have a
CreateDeleteOperation in the operationUndone method of your observer.
If it returns true for isDelete() you can obtain the deleted element via
getModelElement(). Note though, that this might not cover all your use
cases, since getModelElement returns a copy of the deleted element.

Thanks,
Edgar

Am 13.05.2015 13:54, schrieb Yuriy Flyud:
> Edgar,
>
> Here is the undo sample:
> new UIUndoLastOperationController(getShell(),
> requireSelection(ESLocalProjectImpl.class))
> .execute();
> I register observer via:
> ((ESLocalProjectImpl)
> esLocalProject).toInternalAPI().getOperationManager().addOperationObserver(observer);
>
>
> Regarding internal API - I will try. I will create the issue as well
> after some additional investigation.
> Thanks!
>
> Best regards,
> Yuriy


--
Edgar Mueller

Get Professional Eclipse Support: http://eclipsesource.com/munich
Re: [EMFStore] Detecting changes of operations [message #1696078 is a reply to message #1695722] Thu, 21 May 2015 14:04 Go to previous message
Yuriy Flyud is currently offline Yuriy FlyudFriend
Messages: 12
Registered: January 2015
Location: Lviv, Ukraine
Junior Member
Thank you Edgar,

The corresponding issues have been reported. And using internal API really prevents the Concurrent Modification exceptions.

Best regards,
Yuriy
Previous Topic:[EDAPT] Migration validation issue
Next Topic:[Teneo] Waiting Teneo Threads Prevent JVM From Shutting Down
Goto Forum:
  


Current Time: Mon Sep 21 17:29:21 GMT 2020

Powered by FUDForum. Page generated in 0.02363 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top