Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-5665

SlingScriptHelper.getServices(Class, String) should return the highest matching service ranking first

    XMLWordPrintableJSON

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

        1. SLING-5665-test.patch
          4 kB
          Bertrand Delacretaz
        2. SLING-5665-v01.patch
          2 kB
          Konrad Windszus

        Issue Links

          Activity

            People

              kwin Konrad Windszus
              kwin Konrad Windszus
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: