Bug 125578 - [prefs] Refactoring the preference classes
Summary: [prefs] Refactoring the preference classes
Status: RESOLVED WONTFIX
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Compendium (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: equinox.compendium-inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: api
Depends on:
Blocks:
 
Reported: 2006-01-27 16:49 EST by DJ Houghton CLA
Modified: 2019-09-05 15:20 EDT (History)
4 users (show)

See Also:


Attachments
new class - ScopedPreferences (6.04 KB, text/plain)
2006-03-16 10:25 EST, DJ Houghton CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description DJ Houghton CLA 2006-01-27 16:49:17 EST
From the review of the runtime refactoring...

We would like to get rid of the core.runtime.Preferences class. We need to make sure we have a good story going forward though. 

People should be calling the IPreferencesService search methods.

When reviewing IPreferencesService we noticed that setting the search order for scopes is not thread safe. You set the search order and then later get prefs from the service. If 2 people set different search orders, then there is a problem.

Consider changing the IPreferencesService search methods to take an explicit list of contexts to search to prevent this problem. We considered this when originally designing the service but decided against it. We need to re-visit the reasons behind the design.
Comment 1 John Arthorne CLA 2006-01-30 11:20:09 EST
Moving bugs from code review out of inbox
Comment 2 John Arthorne CLA 2006-03-15 11:59:23 EST
Removing milestone (we're past M5)
Comment 3 DJ Houghton CLA 2006-03-16 10:25:03 EST
Created attachment 36417 [details]
new class - ScopedPreferences

Here is an attempt at making things simplier as well as thread safe.

Here is some sample code which uses the new class. The questionable thing is specifying the search order. We want to make this as easy as possible for clients. Have also thought about creating a SearchOrder class, etc but thought that just an array is simpliest.

Thoughts?

----------

List list = new ArrayList();
IProject project   = ResourcesPlugin.getWorkspace().getRoot().getProject("foo");
list.add(new ProjectScope(project));
for (int i = 0; i < ScopedPreferences.DEFAULT_ORDER.length; i++)
   list.add(ScopedPreferences.DEFAULT_ORDER[i]);
IScopeContext[] order = (IScopeContext[]) list.toArray(new IScopeContext[list.size()]);
ScopedPreferences preferences = new ScopedPreferences(BUNDLE_ID, order);
return preferences.get("key", "defaultValue");
Comment 4 DJ Houghton CLA 2006-03-31 11:42:02 EST
More information:

The original method that was causing us problems was #setDefaultLookupOrder. When you set the default lookup order, you actually set it at the granularity of a qualifier or qualifier and key pairing, NOT for all qualifiers.

So there is really only an issue if 2 clients are setting the default lookup order for the same plug-in id, at the same time. 

That being said, here is another alternative to adding a new class. Essentially we want to change the semantics of the scope context parameter in the search methods:
  get(qualifier, key, default, IScopeContext[])

Currently the contexts are optional, the order is irrelevant and they are only used as hints to find the real preference nodes as set by the default lookup order. Essentially we want to be able to say that the array of scope contexts that you pass in, is the exact search order to be used during lookup and the default lookup order should not be consulted.

- create a new empty interface called IScopeOrder
- have IScopeContext extend IScopeOrder
- in the implementation of #get:
      if (contexts instanceof IScopeOrder) {
        // use the exact order as specified
      } else {
        // we have IScopeContexts so perform the old lookup
      }

So now client code would look like:
    contexts = new IScopeOrder[] {...}
instead of:
    contexts = new IScopeContext[] {...}

Also note that minimally for 3.2 we need to update the javadoc for #setDefaultLookupOrder warning clients that there may be thread safety issues.
Comment 5 DJ Houghton CLA 2006-04-03 13:36:30 EDT
Here is another alternative to adding a new class/interface. We again change the semantics of the scope context array parameter to the search methods. In this case, the first arguement is a marker to indicate whether or not the array specifies the search order.

Constant defined:
  public static final IScopeContext EXACT = new InstanceScope();

Service search method Impl:
  // note: use == here and not equals()
  if (contexts[0] == EXACT) {
    // then use the specified contexts as the exact search order
  } else {
    // otherwise use the contexts as hints and use the default lookup order
  }
Comment 6 Jeff McAffer CLA 2006-04-04 21:23:35 EDT
Personally I prefer the approach in comment 5 at this point.  It is a bit more hacky but it does not introduce a new type/concept.  That approach feels more confusing in the long run.  In 3.3 we should revisit this and see about some new API.  DJ, do you want to open an new bug for 3.3?
Comment 7 Jeff McAffer CLA 2006-04-09 22:06:30 EDT
-1 for 3.2.  The scope of this problem is not a broad as originally feared as typically it is only a bundle itself that is accessing its own preferences and setting up the search order.  

We should however as part of 3.3 look to rationalize this.  In fact, we should look  to standardize scopes and searching in OSGi as extensions to the OSGi preference service.
Comment 8 Eclipse Genie CLA 2019-09-05 14:54:49 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 9 Thomas Watson CLA 2019-09-05 15:20:06 EDT
No plans to move this forward.