[CDO] EMFObservables are not being notified [message #426458] |
Tue, 06 January 2009 18:14 |
Stephen McCants Messages: 92 Registered: July 2009 |
Member |
|
|
Hello
I recently switched from CDO 2.0.0.200810281527 to 2.0.0.v200812191119, and it seems that my
EMFObservables are no longer being notified of changes to the model. I wrote this unit test to try
to figure things out:
public class MyListener implements IChangeListener{
private boolean called = false;
public void handleChange(ChangeEvent event)
{
System.out.println("Listener called");
called = true;
}
public boolean getCalled()
{
return called;
}
}
public void testViews() throws InterruptedException
{
// Create a Folder in transaction 1
CDOTransaction transaction1 = session.openTransaction();
Resource createResource = transaction1.getOrCreateResource("/lltest");
// Create a folder
Folder folder = DirectoryFactory.eINSTANCE.createFolder();
folder.setName("lltest");
createResource.getContents().add(folder);
// Create
transaction1.commit();
// Get a view
CDOSession session2 = configuration.openSession();
CDOView view = session2.openView();
CDOResource viewResource = view.getResource("/lltest");
assertThat(viewResource.cdoID(), is(((CDOResource)createResource).cdoID()));
Folder viewFolder = (Folder) viewResource.getContents().get(0);
assertThat(viewFolder.cdoID(), is(folder.cdoID()));
// Setup an observable (but first create a fake realm, since we don't have a real one from a GUI)
Realm fakeRealm = new Realm()
{
@Override
public boolean isCurrent()
{
// This is only for a unit test case, so it is always true
return true;
}
};
IObservableValue observable = EMFObservables.observeValue(fakeRealm, viewFolder,
DirectoryPackage.Literals.ELEMENT__NAME);
MyListener listener = new MyListener();
observable.addChangeListener(listener);
// Change the name
folder.setName("a new name");
transaction1.commit();
Thread.sleep(10000); // Give the listener a chance to be called
assertThat(listener.getCalled(), is(true));
// Delete the folder
createResource.getContents().clear();
transaction1.commit();
// Make sure the view sees the change
assertThat(viewResource.getContents().size(), is(0));
}
Any ideas on what I'm doing wrong would be appreciated. Thanks!
Sincerely,
Stephen McCants
|
|
|
Re: [CDO] EMFObservables are not being notified [message #426460 is a reply to message #426458] |
Tue, 06 January 2009 20:12 |
Simon Mc Duff Messages: 596 Registered: July 2009 |
Senior Member |
|
|
Is it failing at
assertThat(listener.getCalled(), is(true)); ?
Or somewhere else ?
Simon
Stephen McCants wrote:
> Hello
>
> I recently switched from CDO 2.0.0.200810281527 to 2.0.0.v200812191119,
> and it seems that my EMFObservables are no longer being notified of
> changes to the model. I wrote this unit test to try to figure things out:
>
> public class MyListener implements IChangeListener{
> private boolean called = false;
>
> public void handleChange(ChangeEvent event)
> {
> System.out.println("Listener called");
> called = true;
> }
>
> public boolean getCalled()
> {
> return called;
> }
> }
>
> public void testViews() throws InterruptedException
> {
> // Create a Folder in transaction 1
> CDOTransaction transaction1 = session.openTransaction();
> Resource createResource =
> transaction1.getOrCreateResource("/lltest");
> // Create a folder
> Folder folder = DirectoryFactory.eINSTANCE.createFolder();
> folder.setName("lltest");
> createResource.getContents().add(folder);
> // Create
> transaction1.commit();
>
> // Get a view
> CDOSession session2 = configuration.openSession();
> CDOView view = session2.openView();
> CDOResource viewResource = view.getResource("/lltest");
> assertThat(viewResource.cdoID(),
> is(((CDOResource)createResource).cdoID()));
> Folder viewFolder = (Folder) viewResource.getContents().get(0);
> assertThat(viewFolder.cdoID(), is(folder.cdoID()));
>
> // Setup an observable (but first create a fake realm, since we
> don't have a real one from a GUI)
> Realm fakeRealm = new Realm()
> {
> @Override
> public boolean isCurrent()
> {
> // This is only for a unit test case, so it is always true
> return true;
> }
> };
> IObservableValue observable =
> EMFObservables.observeValue(fakeRealm, viewFolder,
> DirectoryPackage.Literals.ELEMENT__NAME);
> MyListener listener = new MyListener();
> observable.addChangeListener(listener);
>
> // Change the name
> folder.setName("a new name");
> transaction1.commit();
> Thread.sleep(10000); // Give the listener a chance to be called
> assertThat(listener.getCalled(), is(true));
>
> // Delete the folder
> createResource.getContents().clear();
> transaction1.commit();
>
> // Make sure the view sees the change
> assertThat(viewResource.getContents().size(), is(0));
> }
>
> Any ideas on what I'm doing wrong would be appreciated. Thanks!
>
> Sincerely,
> Stephen McCants
|
|
|
|
Re: [CDO] EMFObservables are not being notified [message #426462 is a reply to message #426458] |
Tue, 06 January 2009 21:18 |
Simon Mc Duff Messages: 596 Registered: July 2009 |
Senior Member |
|
|
Hi Stephen,
The notification you will receive using CDO is only a INvalidate
notifications without any informations of which EStructuralFeature
changed. I never tried it with Observable value but I suspect without
this information you should never be notified. (this do not explain why
it was working before)
To have such information you need to activate view.ChangeSubcriptionPolicy.
http://wiki.eclipse.org/New_And_Noteworthy_for_CDO_2.0#Chang e_subscription
I suspect that without this information in the Notification... you will
never received the notifications yourself.. But again take my advice as
not final since I never played with IObservableValue.
Simon
Stephen McCants wrote:
> Hello
>
> I recently switched from CDO 2.0.0.200810281527 to 2.0.0.v200812191119,
> and it seems that my EMFObservables are no longer being notified of
> changes to the model. I wrote this unit test to try to figure things out:
>
> public class MyListener implements IChangeListener{
> private boolean called = false;
>
> public void handleChange(ChangeEvent event)
> {
> System.out.println("Listener called");
> called = true;
> }
>
> public boolean getCalled()
> {
> return called;
> }
> }
>
> public void testViews() throws InterruptedException
> {
> // Create a Folder in transaction 1
> CDOTransaction transaction1 = session.openTransaction();
> Resource createResource =
> transaction1.getOrCreateResource("/lltest");
> // Create a folder
> Folder folder = DirectoryFactory.eINSTANCE.createFolder();
> folder.setName("lltest");
> createResource.getContents().add(folder);
> // Create
> transaction1.commit();
>
> // Get a view
> CDOSession session2 = configuration.openSession();
> CDOView view = session2.openView();
> CDOResource viewResource = view.getResource("/lltest");
> assertThat(viewResource.cdoID(),
> is(((CDOResource)createResource).cdoID()));
> Folder viewFolder = (Folder) viewResource.getContents().get(0);
> assertThat(viewFolder.cdoID(), is(folder.cdoID()));
>
> // Setup an observable (but first create a fake realm, since we
> don't have a real one from a GUI)
> Realm fakeRealm = new Realm()
> {
> @Override
> public boolean isCurrent()
> {
> // This is only for a unit test case, so it is always true
> return true;
> }
> };
> IObservableValue observable =
> EMFObservables.observeValue(fakeRealm, viewFolder,
> DirectoryPackage.Literals.ELEMENT__NAME);
> MyListener listener = new MyListener();
> observable.addChangeListener(listener);
>
> // Change the name
> folder.setName("a new name");
> transaction1.commit();
> Thread.sleep(10000); // Give the listener a chance to be called
> assertThat(listener.getCalled(), is(true));
>
> // Delete the folder
> createResource.getContents().clear();
> transaction1.commit();
>
> // Make sure the view sees the change
> assertThat(viewResource.getContents().size(), is(0));
> }
>
> Any ideas on what I'm doing wrong would be appreciated. Thanks!
>
> Sincerely,
> Stephen McCants
|
|
|
|
|
Re: [CDO] EMFObservables are not being notified [message #426466 is a reply to message #426463] |
Wed, 07 January 2009 12:24 |
|
Stephen,
Thanks for fixing the wiki!
It's hard in the development stream to keep the docs up to date...
Cheers
/Eike
----
http://thegordian.blogspot.com
Stephen McCants schrieb:
> That fixed it. I suspect when the command changed from set to add
> that it was simply removed from my code instead of fixed. I also
> corrected the wiki to show to function:
>
> transaction.options().addChangeSubscriptionPolicy(CDOAdapter Policy.ALL);
>
> and not the old style:
>
> transaction.options().showChangeSubscriptionPolicy(CDOAdapte rPolicy.ALL);
>
> Thanks for your help!
>
> Sincerely,
> Stephen McCants
>
> Simon McDuff wrote:
>> Hi Stephen,
>>
>>
>> The notification you will receive using CDO is only a INvalidate
>> notifications without any informations of which EStructuralFeature
>> changed. I never tried it with Observable value but I suspect without
>> this information you should never be notified. (this do not explain
>> why it was working before)
>>
>> To have such information you need to activate
>> view.ChangeSubcriptionPolicy.
>>
>> http://wiki.eclipse.org/New_And_Noteworthy_for_CDO_2.0#Chang e_subscription
>>
>>
>>
>> I suspect that without this information in the Notification... you
>> will never received the notifications yourself.. But again take my
>> advice as not final since I never played with IObservableValue.
>>
>> Simon
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Powered by
FUDForum. Page generated in 0.03547 seconds