[ 
https://issues.apache.org/jira/browse/SLING-5041?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15070964#comment-15070964
 ] 

Konrad Windszus commented on SLING-5041:
----------------------------------------

This is my proposal on how to fix this:
# Deprecate {{ServiceUtil.getComparableForServiceRankings()}} and instead add 
two methods {{ServiceUtil.getComparableForServiceRankingsHighestFirst()}} and 
{{ServiceUtil.getComparableForServiceRankingsLowestFirst()}}. The latter is 
also called by the deprecated method 
{{ServiceUtil.getComparableForServiceRankings()}}.
The javadoc of both methods should clarify, when to use which comparable. The 
former is useful for implementing an order similar to what is used by 
{{BundleContext.getServiceReference()}}, i.e. highest rank first. I am not 
quite sure for what purpose you would need the latter though but we need it to 
be backwards-compatible (lowest rank first).
# For {{RankedServices}} itself I would rather go for incrementing the package 
version to 3.0 and just fix the iterator order from ascending to descending 
(i.e. highest first) by internally relying on the new 
{{ServiceUtil.getComparableForServiceRankingsHighestFirst()}}. The way it is 
implemented right now is really not that useful and rather contradicts OSGi 
rules.

The alternative would be to deprecate {{RankedServices}} and introduce a new 
interface {{OSGiCompliantRankedServices}} which inverts the order.

[[email protected]][~cziegeler][[~bdelacretaz] WDYT? Which way would you 
prefer?

> Clarify the order of the iterator given by RankedServices
> ---------------------------------------------------------
>
>                 Key: SLING-5041
>                 URL: https://issues.apache.org/jira/browse/SLING-5041
>             Project: Sling
>          Issue Type: Improvement
>          Components: Commons
>    Affects Versions: Commons OSGi 2.3.0
>            Reporter: Konrad Windszus
>
> Currently the iterator in {{RankedServices}} returns the services in the 
> ascending order from lowest to highest ranking. This is a different order 
> then being used by OSGi internally [1]. Usually you are only interested in an 
> iterator which gives you the service with the highest ranking first (because 
> that would also be the one being returned by 
> {{BundleContext.getServiceReference(...)}}).
> If we don't change the iterator logic we should at least make it clearer in 
> the Javadoc that the iterator really gives the services in ascending order of 
> their service ranking property and we should probably add a more useful 
> iterator which gives back the services with the highest ranking first.
> The issue came up in the context of SLING-5035.
> [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)

Reply via email to