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 11:27:25 UTC

[jira] [Updated] (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:all-tabpanel ]

Konrad Windszus updated SLING-5665:
-----------------------------------
    Description: 
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.

  was:
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.


> 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)