Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] EMFObservables are not being notified
[CDO] EMFObservables are not being notified [message #426458] Tue, 06 January 2009 18:14 Go to next message
Stephen McCants is currently offline Stephen McCantsFriend
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 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
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 #426461 is a reply to message #426460] Tue, 06 January 2009 20:35 Go to previous messageGo to next message
Stephen McCants is currently offline Stephen McCantsFriend
Messages: 92
Registered: July 2009
Member
Hi Simon,
It is failing there. Also, I never see my system.out.println() from inside the listener.
--Stephen

Simon McDuff wrote:
> Is it failing at
>
> assertThat(listener.getCalled(), is(true)); ?
>
> Or somewhere else ?
>
>
> Simon
Re: [CDO] EMFObservables are not being notified [message #426462 is a reply to message #426458] Tue, 06 January 2009 21:18 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
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 #426463 is a reply to message #426462] Tue, 06 January 2009 23:20 Go to previous messageGo to next message
Stephen McCants is currently offline Stephen McCantsFriend
Messages: 92
Registered: July 2009
Member
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
Re: [CDO] EMFObservables are not being notified [message #426464 is a reply to message #426463] Wed, 07 January 2009 00:38 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
Stephen McCants wrote:
> 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:

Thank you Stephen !

>
> 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
Re: [CDO] EMFObservables are not being notified [message #426466 is a reply to message #426463] Wed, 07 January 2009 12:24 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
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


Previous Topic:java.lang.NumberFormatException when reading a model
Next Topic:[CDO] CDO2.0 and Eclipse 3.5 using p2
Goto Forum:
  


Current Time: Thu Mar 28 08:07:24 GMT 2024

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

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

Back to the top