Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Usage of IListener/Adapter(How to get a changed Model by an iListener/Adapter)
Usage of IListener/Adapter [message #1688325] Fri, 20 March 2015 13:37 Go to next message
Daniel Seybold is currently offline Daniel SeyboldFriend
Messages: 14
Registered: October 2014
Junior Member
Hi guys,

I've got model resource with the following elemnts/structure.
Model foo is the parent with a list of childs bar:

foo (instance of A)
--bar (Instance of B)
--bar (Instance of B)
--bar (Instance of B)
...

I've got a open View and
now I'd like to get noticed if another element of bar is added to the foo root element on the CDOServer

I've already found in the docs that you should prefer Adapters over the IListener because you'll get more information by an Adapter.

But is it possible to get the changed/added element (or at least the Class of the Element) by the Notification of the Adapater?
Or do I have to go through the whole Notification and compare my local instance of the model with the instance of the model provided by the notification?

Thanks in advance for your help!

Cheers,
Daniel

[Updated on: Fri, 20 March 2015 13:37]

Report message to a moderator

Re: Usage of IListener/Adapter [message #1688339 is a reply to message #1688325] Fri, 20 March 2015 14:00 Go to previous messageGo to next message
Erick Hagstrom is currently offline Erick HagstromFriend
Messages: 108
Registered: April 2014
Location: USA
Senior Member
Hi Daniel. If you add a single child to a list, you get an Add notification. The notifier is foo, the feature is the EStructuralFeature for the list of bar, and the newValue will be the bar you just added.
Re: Usage of IListener/Adapter [message #1690198 is a reply to message #1688339] Wed, 25 March 2015 16:20 Go to previous messageGo to next message
Daniel Seybold is currently offline Daniel SeyboldFriend
Messages: 14
Registered: October 2014
Junior Member
Hi Erick,

thanks for your help.

I have two follow up questions.

1. As long as I just add bar models everything is fine. But when I try to add a new model xyc to one of my bar models an exception is thrown.

The resulting structure should looks like:

foo (instance of A)
--bar (Instance of B)
----xyc (Instance C)
--bar (Instance of B)

But the registerd Adapter throws this Exception:

[ERROR] Invalid URI "cdo:proxy": java.lang.IllegalStateException: Different object was registered for OID1


Here is a snippet showing the initialisation of my CDOView:

view.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
foo.eAdapters().add(new CDOAdapter());


Am I missing some other view.options() ?

2. Can you provide me with some small code snippets showing the most elegant way to extract the changed delta from the org.eclipse.emf.common.notify.Notification when receiving the notifyChanged event.

Thanks a lot in advance!

Cheers,
Daniel
Re: Usage of IListener/Adapter [message #1690204 is a reply to message #1690198] Wed, 25 March 2015 16:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30354
Registered: July 2009
Senior Member
Daniel,

I can't comment on CDO related things, but you can have a look at these
to see how some of the EMF runtime adapters deal with notifications

org.eclipse.emf.ecore.util.EContentAdapter.handleContainment(Notification)
org.eclipse.emf.ecore.util.ECrossReferenceAdapter.handleCrossReference(EReference,
Notification)
org.eclipse.emf.ecore.change.util.ChangeRecorder.notifyChanged(Notification)



On 25/03/2015 5:20 PM, Daniel Seybold wrote:
> Hi Erick,
>
> thanks for your help.
>
> I have two follow up questions.
>
> 1. As long as I just add bar models everything is fine. But when I try
> to add a new model xyc to one of my bar models an exception is thrown.
>
> The resulting structure should looks like:
>
> foo (instance of A)
> --bar (Instance of B)
> ----xyc (Instance C) --bar (Instance of B)
>
> But the registerd Adapter throws this Exception:
>
>
> [ERROR] Invalid URI "cdo:proxy": java.lang.IllegalStateException:
> Different object was registered for OID1
>
>
> Here is a snippet showing the initialisation of my CDOView:
>
>
> view.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
> foo.eAdapters().add(new CDOAdapter());
>
>
> Am I missing some other view.options() ?
>
> 2. Can you provide me with some small code snippets showing the most
> elegant way to extract the changed delta from the
> org.eclipse.emf.common.notify.Notification when receiving the
> notifyChanged event.
>
> Thanks a lot in advance!
>
> Cheers,
> Daniel
Re: Usage of IListener/Adapter [message #1690208 is a reply to message #1690198] Wed, 25 March 2015 16:52 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6441
Registered: July 2009
Senior Member
Am 25.03.2015 um 17:20 schrieb Daniel Seybold:
> But the registerd Adapter throws this Exception:
> [ERROR] Invalid URI "cdo:proxy": java.lang.IllegalStateException: Different object was registered for OID1
Please paste the complete stack trace of the exception.

What CDO version are you using? Have you regenerated your meta models for CDO?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: Usage of IListener/Adapter [message #1690324 is a reply to message #1690208] Thu, 26 March 2015 15:30 Go to previous messageGo to next message
Daniel Seybold is currently offline Daniel SeyboldFriend
Messages: 14
Registered: October 2014
Junior Member
Hi Eike,

this is the complete stack trace:

[ERROR] Invalid URI "cdo:proxy": java.lang.IllegalStateException: Different object was registered for OID1
org.eclipse.emf.cdo.util.InvalidURIException: Invalid URI "cdo:proxy": java.lang.IllegalStateException: Different object was registered for OID1
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.registerProxyResource(AbstractCDOView.java:1457)
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.registerProxy(CDOResourceImpl.java:1180)
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.load(CDOResourceImpl.java:1086)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:220)
	at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:199)
	at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:259)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1473)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eContainer(BasicEObjectImpl.java:770)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstanceFeature(CDOLegacyWrapper.java:678)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstance(CDOLegacyWrapper.java:492)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.cdoInternalPostLoad(CDOLegacyWrapper.java:367)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.cleanObject(AbstractCDOView.java:1254)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.createObject(AbstractCDOView.java:1170)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:1055)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.convertIDToObject(AbstractCDOView.java:1395)
	at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertIDToObject(CDOStoreImpl.java:679)
	at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertToEMF(CDOStoreImpl.java:647)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.getValueFromRevision(CDOLegacyWrapper.java:761)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstanceFeature(CDOLegacyWrapper.java:615)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstance(CDOLegacyWrapper.java:492)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.cdoInternalPostInvalidate(CDOLegacyWrapper.java:385)
	at org.eclipse.emf.internal.cdo.view.CDOStateMachine$InvalidateTransition.execute(CDOStateMachine.java:1156)
	at org.eclipse.emf.internal.cdo.view.CDOStateMachine$InvalidateTransition.execute(CDOStateMachine.java:1)
	at org.eclipse.net4j.util.fsm.FiniteStateMachine.process(FiniteStateMachine.java:173)
	at org.eclipse.emf.internal.cdo.view.CDOStateMachine.invalidate(CDOStateMachine.java:388)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.invalidate(AbstractCDOView.java:1591)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.doInvalidate(CDOViewImpl.java:868)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl$InvalidationRunnable.run(CDOViewImpl.java:1710)
	at org.eclipse.net4j.util.concurrent.QueueRunner.work(QueueRunner.java:26)
	at org.eclipse.net4j.util.concurrent.QueueRunner.work(QueueRunner.java:1)
	at org.eclipse.net4j.util.concurrent.QueueWorker.doWork(QueueWorker.java:78)
	at org.eclipse.net4j.util.concurrent.QueueWorker.work(QueueWorker.java:70)
	at org.eclipse.net4j.util.concurrent.Worker$WorkerThread.run(Worker.java:209)
Caused by: java.lang.IllegalStateException: Different object was registered for OID1
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.registerObject(AbstractCDOView.java:1494)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.registerProxyResource(AbstractCDOView.java:1444)
	... 35 more


I am using CDO 4.3 on Client and Server side.
org.eclipse.emf.cdo_4.3.0.v20140520-1823


All CDO Plugins where donwloaded from https://www.eclipse.org/cdo/downloads/

Thanks in advance for your support.

Cheers,
Daniel
Re: Usage of IListener/Adapter [message #1690391 is a reply to message #1690324] Fri, 27 March 2015 05:38 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6441
Registered: July 2009
Senior Member
Am 26.03.2015 um 16:30 schrieb Daniel Seybold:
> Hi Eike,
>
> this is the complete stack trace:
>
>
> [ERROR] Invalid URI "cdo:proxy": java.lang.IllegalStateException: Different object was registered for OID1
> org.eclipse.emf.cdo.util.InvalidURIException: Invalid URI "cdo:proxy": java.lang.IllegalStateException: Different
> object was registered for OID1
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.registerProxyResource(AbstractCDOView.java:1457)
> at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.registerProxy(CDOResourceImpl.java:1180)
> at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.load(CDOResourceImpl.java:1086)
> at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
> at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
> at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
> at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:220)
> at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:199)
> at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:259)
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1473)
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eContainer(BasicEObjectImpl.java:770)
> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstanceFeature(CDOLegacyWrapper.java:678)
So you're using models that are not regenerated specifically for (native) use with CDO. Instead you fall back to CDO's
legacy model support. That should work in most cases (I haven't developed it) but often incurs performance or
scalability penalties. Have you tried to regenerate your model for CDO natively? Here's a how-to:
https://wiki.eclipse.org/CDO/Preparing_EMF_Models

It's possible that you problem goes away then or, if not, we know that it's not legacy mode related..

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstance(CDOLegacyWrapper.java:492)
> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.cdoInternalPostLoad(CDOLegacyWrapper.java:367)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.cleanObject(AbstractCDOView.java:1254)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.createObject(AbstractCDOView.java:1170)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:1055)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.convertIDToObject(AbstractCDOView.java:1395)
> at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertIDToObject(CDOStoreImpl.java:679)
> at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertToEMF(CDOStoreImpl.java:647)
> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.getValueFromRevision(CDOLegacyWrapper.java:761)
> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstanceFeature(CDOLegacyWrapper.java:615)
> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstance(CDOLegacyWrapper.java:492)
> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.cdoInternalPostInvalidate(CDOLegacyWrapper.java:385)
> at org.eclipse.emf.internal.cdo.view.CDOStateMachine$InvalidateTransition.execute(CDOStateMachine.java:1156)
> at org.eclipse.emf.internal.cdo.view.CDOStateMachine$InvalidateTransition.execute(CDOStateMachine.java:1)
> at org.eclipse.net4j.util.fsm.FiniteStateMachine.process(FiniteStateMachine.java:173)
> at org.eclipse.emf.internal.cdo.view.CDOStateMachine.invalidate(CDOStateMachine.java:388)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.invalidate(AbstractCDOView.java:1591)
> at org.eclipse.emf.internal.cdo.view.CDOViewImpl.doInvalidate(CDOViewImpl.java:868)
> at org.eclipse.emf.internal.cdo.view.CDOViewImpl$InvalidationRunnable.run(CDOViewImpl.java:1710)
> at org.eclipse.net4j.util.concurrent.QueueRunner.work(QueueRunner.java:26)
> at org.eclipse.net4j.util.concurrent.QueueRunner.work(QueueRunner.java:1)
> at org.eclipse.net4j.util.concurrent.QueueWorker.doWork(QueueWorker.java:78)
> at org.eclipse.net4j.util.concurrent.QueueWorker.work(QueueWorker.java:70)
> at org.eclipse.net4j.util.concurrent.Worker$WorkerThread.run(Worker.java:209)
> Caused by: java.lang.IllegalStateException: Different object was registered for OID1
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.registerObject(AbstractCDOView.java:1494)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.registerProxyResource(AbstractCDOView.java:1444)
> ... 35 more
>
>
> I am using CDO 4.3 on Client and Server side.
>
> org.eclipse.emf.cdo_4.3.0.v20140520-1823
>
>
> All CDO Plugins where donwloaded from https://www.eclipse.org/cdo/downloads/
>
> Thanks in advance for your support.
>
> Cheers,
> Daniel


Re: Usage of IListener/Adapter [message #1690996 is a reply to message #1690391] Wed, 01 April 2015 13:16 Go to previous message
Daniel Seybold is currently offline Daniel SeyboldFriend
Messages: 14
Registered: October 2014
Junior Member
Hi Eike,

thanks a lot for your help.

We have rebuilded the model as CDO native like you proposed and now it works like expected.

Cheers
Daniel
Previous Topic:Best strategy to use for <XML -> Custom-EMF model>
Next Topic:EOperation is not generated in the sub-class if the super type has one with the same signature
Goto Forum:
  


Current Time: Thu Aug 22 06:45:33 GMT 2019

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

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

Back to the top