Bug 428837 - ExtendedObjectSupplier look should be ordered based on service.ranking
Summary: ExtendedObjectSupplier look should be ordered based on service.ranking
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 4.4   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.4 M6   Edit
Assignee: Thomas Schindl CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 392977
  Show dependency tree
 
Reported: 2014-02-23 02:37 EST by Thomas Schindl CLA
Modified: 2014-03-06 09:46 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schindl CLA 2014-02-23 02:37:16 EST
We should allow vendors to overload an ExtendedObjectSupplier by contributing a service with a higher service.ranking.

Although this works currently we are relying on an implementation detail of Equinox when doing the look up. We should simply order the returned services based on their ranking value
Comment 1 Thomas Watson CLA 2014-02-24 08:46:26 EST
(In reply to Thomas Schindl from comment #0)
> We should allow vendors to overload an ExtendedObjectSupplier by
> contributing a service with a higher service.ranking.
> 
> Although this works currently we are relying on an implementation detail of
> Equinox when doing the look up. We should simply order the returned services
> based on their ranking value

Out of curiosity, what is the equinox detail?
Comment 2 Thomas Schindl CLA 2014-02-24 09:02:42 EST
As far as I can read the JavaDoc BundleContext#getServiceReferences() does not spec that the returned list is sorted by service.ranking - IIRC asked you some time ago and you stated that it is the case for Equinox but I'm not feeling easy to depend on this.

If you update your JavaDoc to explicitly state that I can rely on the order (if you look at getServiceReference() the order is guaranteed!) than I'm happy to go without my patch.

The gerrit review is https://git.eclipse.org/r/#/c/22432/
Comment 3 Thomas Watson CLA 2014-02-24 09:32:25 EST
(In reply to Thomas Schindl from comment #2)
> As far as I can read the JavaDoc BundleContext#getServiceReferences() does
> not spec that the returned list is sorted by service.ranking - IIRC asked
> you some time ago and you stated that it is the case for Equinox but I'm not
> feeling easy to depend on this.

Yes, you did, I have a bad memory ;-)

> 
> If you update your JavaDoc to explicitly state that I can rely on the order
> (if you look at getServiceReference() the order is guaranteed!) than I'm
> happy to go without my patch.

You cannot depend on the order here and it is not likely we can change the javadoc.

> 
> The gerrit review is https://git.eclipse.org/r/#/c/22432/

I put a comment in gerrit on the patch.  It does not look correct to me.  Here is my comment:

ServiceReference is comparable already, should be no need to implement your own comparable here. You don't take into account the service.id if the rankings are equal. Also, the sorting here is going from lowest to highest. So would the 'highest' reference be at the end of the list, not [0].
Comment 4 Thomas Schindl CLA 2014-02-24 11:36:31 EST
Thanks Tom - i uploaded the patch in a rush ;-) Interesting enough your comment on gerrit is not showing up.

I've uploaded a new review which uses simply Array.sort() and because I have you looking at it - is it safe to resort the result from the call or should I make a copy and sort that one?
Comment 5 Thomas Watson CLA 2014-02-24 12:05:41 EST
(In reply to Thomas Schindl from comment #4)
> Thanks Tom - i uploaded the patch in a rush ;-) Interesting enough your
> comment on gerrit is not showing up.

I was afraid of that, that is why I put the comment here in the bug also.  I put the comment directly on the file change in gerrit instead as a review.

> 
> I've uploaded a new review which uses simply Array.sort() and because I have
> you looking at it - is it safe to resort the result from the call or should
> I make a copy and sort that one?

That is already a snapshot copy from the framework, no need to make another copy.  But you still are sorting in ascending order which is not correct if you continue to use the first element from the sorted list:

supplier = (ExtendedObjectSupplier) bundleContext.getService(refs[0]);

I think you must use a reverse comparator in this case:

   Arrays.sort(refs, java.util.Collections.reverseOrder());
Comment 6 Thomas Schindl CLA 2014-02-24 12:13:17 EST
Silly me - I read the JavaDoc wrong! Pushed a new review which reverses the order
Comment 8 Thomas Schindl CLA 2014-03-06 09:46:01 EST
checked in I20140305-2000