Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 409870

Summary: [preferences] Shared state among Preferences instances
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: ClientAssignee: Project Inbox <orion.client-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: libingw
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mark Macdonald CLA 2013-06-04 11:56:50 EDT
Libing has this code, which updates the "recent searches" pref:

> serviceRegistry.getService("orion.core.preference").getPreferences("/window/favorites").then(function(prefs) {
>     prefs.put("recentSearch", newSearches);  // put the new value
>     eventTarget.dispatchEvent({ type: "recentSearchesChanged" });
> });

The above code invokes an event handler, who tries to get the new pref value by doing this:

> serviceRegistry.getService("orion.core.preference").getPreferences("/window/favorites").then(function(prefs) {
>     var searches = prefs.get("recentSearch");    // doesn't get the new value
>     // ...
> });

The event handler receives a stale value for the "recentSearch" pref.

I didn't debug this, but I think it's because the getPreferences() call hands out a new Preferences instance every time, and the instances do not know about each other's pending changes until they get flushed to the back end store (or some other asynchronous event happens, whatever it is). This means you need to pass the actual Preferences object around to all clients, or they risk getting stale values.

It would be convenient if the pending changes were known to all Preferences instances. Is this feasible? It seems simpler than full blown cross-tab preferences (something we've discussed in the past) since everything is in the same window.
Comment 1 John Arthorne CLA 2015-05-05 14:52:50 EDT
Closing as part of a mass clean up of inactive bugs. Please reopen if this problem still occurs or is relevant to you. For more details see:

https://dev.eclipse.org/mhonarc/lists/orion-dev/msg03444.html