Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
Scripting Core 2.0.36, API 2.11.0
-
None
-
None
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:
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.
This should be translated into,
.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.
Both the javadoc of the SlingScriptHelper as well as the implementation in ScriptHelper should be adjusted accordingly.
Attachments
Attachments
Issue Links
- relates to
-
SLING-5664 Models: OSGiServiceInjector does not consider service.ranking
- Closed
-
SLING-5834 Update Sling API to 2.12.0
- Closed