You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Konrad Windszus (JIRA)" <ji...@apache.org> on 2016/04/15 15:20:25 UTC

[jira] [Commented] (SLING-5665) SlingScriptHelper.getServices(Class, String) should return the highest matching service ranking first

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

Konrad Windszus commented on SLING-5665:
----------------------------------------

In contrast to {{BundleContext.getServiceReferences}}, whose return value can be easily sorted afterwards since the {{ServiceReference}} already implements a {{Comparable}} (although the order is vice-versa than described above), I see no solution of doing the sorting afterwards for {{SlingScriptHelper.getServices(...)}} (since there you don't have access to the service properties).

> SlingScriptHelper.getServices(Class, String) should return the highest matching service ranking first
> -----------------------------------------------------------------------------------------------------
>
>                 Key: SLING-5665
>                 URL: https://issues.apache.org/jira/browse/SLING-5665
>             Project: Sling
>          Issue Type: Improvement
>    Affects Versions: Scripting Core 2.0.36, API 2.11.0
>            Reporter: Konrad Windszus
>
> Unfortunately only the method {{BundleContext.getServiceReference(Class)}} considers the service ranking. The method {{BundleContext.getServiceReferences(Class, String)}} just returns a Collection in no specific order. Since the latter is used in https://github.com/apache/sling/blob/c9e59667d8f9cd698bc33a51f3e6a22e85d4a952/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java#L224 one cannot rely on the order of this (although some code even in Sling does that, e.g. SLING-5664).
> I think it makes sense to always consider the service ranking in the array order, as it is specified for {{BundleContext.getServiceReference}}. There it says:
> {quote}
>  If multiple such services exist, the service with the highest ranking (as specified in its Constants.SERVICE_RANKING property) is returned.
> If there is a tie in ranking, the service with the lowest service ID (as specified in its Constants.SERVICE_ID property); that is, the service that was registered first is returned. 
> {quote}
> This should be translated into,  
> {quote}
> The array is sorted by service ranking (i.e. the service with the highest ranking is returned first. If there is a tie in ranking, the service with the lowest service ID (as specified in its Constants.SERVICE_ID property); that is, the service that was registered first is returned first. 
> {quote}.
> Both the javadoc of the `SlingScriptHelper` as well as the implementation should be adjusted accordingly.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)