[ https://issues.apache.org/jira/browse/SLING-5035?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14803164#comment-14803164 ]
Felix Meschberger commented on SLING-5035: ------------------------------------------ Quoting the OSGi Core Specification R6 : {panel} *5.2.6 Service Ranking Order* When registering a service object, a bundle may optionally specify a SERVICE_RANKING service property of type Integer. This number specifies a ranking order between services. The highest num- ber has the highest ranking and the lowest number (including negative numbers) has the lowest ranking. If no service.ranking service property is specified or its type is not Integer then a ranking of 0 must be used. The ranking order is defined as follows: * Sorted on descending ranking number (highest first) * If the ranking numbers are equal, sorted on ascending service.id property (oldest first). This ordering is complete because service ids are never reused and handed out in order of their reg- istration time. That is, a service that is registered later will have a higher service id. Therefore, the ranking order is in descending service.ranking numeric order where ties give a preference to the ear- lier registrant. The ranking order is the reverse of the natural ordering of a ServiceReference object. The purpose of the ranking order is to allow: * Selection - When a single service must be chosen but multiple services qualify then the service with the highest ranking must be selected. * Ordering - When multiple services must be used in a specified order. {panel} So essentially the ranking is from high value to low value, the service reference order as per {{compareTo}} is from low value to high value. What you want here is the ranking order, that is checking the services with the higher ranking before the services with lower values. I think the implementation is wrong and needs to be fixed. At the same time, I suggest to negate the service.ranking values for the default injectors and third to update the documentation. Yes, that might give unexpected results for current implementations which expect the wrong behaviour -- if such implementations exist I would actually expect them to have stumbled upon this wrong behaviour and have broken service.ranking values to work around it. > Sling Models Injectors should be queried in the reverse order of their > service ranking value > -------------------------------------------------------------------------------------------- > > Key: SLING-5035 > URL: https://issues.apache.org/jira/browse/SLING-5035 > Project: Sling > Issue Type: Bug > Components: Extensions > Affects Versions: Sling Models Impl 1.2.2 > Reporter: Radu Cotescu > Fix For: Sling Models Impl 1.2.4 > > > The current version of the {{ModelAdaptorFactory}} \[0\] queries the > Injectors in the ascending order of their service ranking value. However they > should be queried in the descending order of the service ranking, to use the > same logic as the {{BundleContext#getServiceReference(String)}} method \[1\]. > \[0\] - > https://github.com/apache/sling/blob/f56b444b765beb1c31eed01b4c09fbda4013a580/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L411 > \[1\] - > https://osgi.org/javadoc/r4v42/org/osgi/framework/BundleContext.html#getServiceReference(java.lang.String) -- This message was sent by Atlassian JIRA (v6.3.4#6332)