This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 404461 - service.ranking is not respected when getting IContextFunction OSGi services
Summary: service.ranking is not respected when getting IContextFunction OSGi services
Status: CLOSED DUPLICATE of bug 429466
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.4 M6   Edit
Assignee: platform-runtime-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-27 11:45 EDT by Cole Markham CLA
Modified: 2014-03-04 13:40 EST (History)
4 users (show)

See Also:


Attachments
Proposed patch to track service.ranking and ungetService when replacing (2.34 KB, patch)
2013-03-27 12:10 EDT, Cole Markham CLA
no flags Details | Diff
Proposed patch to track service.ranking and ungetService when replacing existing (2.52 KB, patch)
2013-03-27 12:53 EDT, Cole Markham CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Cole Markham CLA 2013-03-27 11:45:29 EDT
EclipseContextOSGi gets all services that implement IContextFunction and stores them by their service.context.key property. If there are multiple services with the same context key, the last one loaded will overwrite the others. This has two consequences:

1. It does not respect the service.ranking property. In fact, because the services references are ordered by the service ranking when returned from the bundle context, it will actually use the service with the lowest ranking.

2. In the constructor when processing existing services, no check is made to see if an existing service reference is stored for a given context key, therefore ungetService is never called. This is handled properly in the serviceChanged handler.


Workaround: because the service with the lowest ranking overwrites all others, setting a lower service.ranking allows control of which is used.
Comment 1 Cole Markham CLA 2013-03-27 12:10:27 EDT
Created attachment 229108 [details]
Proposed patch to track service.ranking and ungetService when replacing
Comment 2 Cole Markham CLA 2013-03-27 12:53:55 EDT
Created attachment 229113 [details]
Proposed patch to track service.ranking and ungetService when replacing existing

Fixed bug in patch
Comment 3 Paul Webster CLA 2013-04-02 08:52:27 EDT
Wouldn't it be better to just store the valid service refs sorted in some way instead of just storing one?

PW
Comment 4 Lars Vogel CLA 2013-04-02 11:15:11 EDT
Fix looks good to me, having the one with the highest number injected is definitely an improvement against current behavior.
Comment 5 Lars Vogel CLA 2013-04-02 11:16:00 EDT
Increasing prio, I think getting the lowest prio service is relatively critical.
Comment 6 Paul Webster CLA 2013-04-02 11:29:33 EDT
It needs to be reconsidered.  First off, we don't keep track of the refs (just one we've determined).  Also, there's a section in the patch that says FIXME ... should be fixed.

PW
Comment 7 Lars Vogel CLA 2014-03-04 13:40:04 EST
I think this is a dup of Bug 429466

*** This bug has been marked as a duplicate of bug 429466 ***