Also have a look at [1] which maintains a map of services in sorted order. Chetan Mehrotra [1] https://gist.github.com/chetanmeh/3918574
On Tue, Nov 26, 2013 at 12:03 PM, Sean Steimer <[email protected]> wrote: > Bertrand, > > Thanks for the reply. I'm interested to look into the ServiceTracker, as > that's not a concept I was previously aware of. > > I decided to just add a getServiceRanking() method to my interface and sort > based on that value in my bind method. I'm not sure that's the most > elegant solution since there's no guarantee (other than interface as > contract) that implementations will actually return their service ranking > from that method, but it will certainly work in this case since I have > control over the interface & implementations. > > --Sean > > > On Mon, Nov 25, 2013 at 10:16 PM, Bertrand Delacretaz < > [email protected]> wrote: > >> Hi, >> >> On Tuesday, November 26, 2013, Sean Steimer wrote: >> >> > ...Is there a way to force unbind and bind to happen for all Services >> which >> > implement MyServiceInterface anytime a single instance changes?... >> >> I don't think so. >> >> > ...Alternatively, is there a good way to retrieve the service.ranking >> value >> > from my bind method, so that I can just sort them there?... >> >> the simplest is to sort the ServiceReference objects, which as per [1] take >> the service ranking into account for comparison. Lowest service ranking >> comes on top after sorting IIRC. >> >> We also have a SortedServiceTracker [2] that does that. >> >> -Bertrand >> >> [1] >> >> http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/ServiceReference.html >> [2] >> >> https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/SortingServiceTracker.java >>
