which filter is run first, lower or higher order/priority/ranking number? | Community
Skip to main content
Level 8
August 18, 2022
Solved

which filter is run first, lower or higher order/priority/ranking number?

  • August 18, 2022
  • 3 replies
  • 1367 views

you can specify the "ranking", "prioritisation" or "order" (called different things in different places) using this:

@ServiceRanking(-200)

 

The give the following situation:

 

600 : class com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet (id: 2255, property: service.ranking=600); called: 23; time: 97ms; time/call: 4217µs
0 : class com.adobe.aem.graphql.sites.ui.admin.impl.FeatureToggleFilter (id: 1373, property: none); called: 0; time: 122ms; time/call: -1µs

 

which is run first, the filter with 600, or the one with zero as the raking order?

 

so does 

 

a) FormsHandlingServlet fitler call FeatureToggleFilter

  or

b) FeatureToggleFilter call FormsHandlingServlet

 

 

The documentation says:

 

Filter ordering is defined by the filter.order property whose default value is Integer.MAX_VALUE where smaller values have higher priority over higher values.

 

This would imply  b), but most people think its a).

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by TB3dock

Due to conflicting documentation, I added debug statements to see what was happening.  the answer is in fact a), so it appears that @santoshsai could be wrong, and @arunpatidar could be right, at least for the current AEM cloud local dev environment.

3 replies

SantoshSai
Community Advisor
Community Advisor
August 19, 2022

Hi @tb3dock ,

They invoked in order of their service ranking, that is lowest to highest. service ranking status can be found here: https://sling.apache.org/documentation/bundles/models.html#available-injectors 

Hope that helps!

Regards,

Santosh

Santosh Sai
TB3dockAuthor
Level 8
August 19, 2022

Unfortunately, this is opposite to what @arunpatidar  is saying?

arunpatidar
Community Advisor
Community Advisor
August 19, 2022

Please check

service.ranking Integer 0 Any Integer value Indication of where to place the filter in the filter chain. The higher the number the earlier in the filter chain. This value may span the whole range of integer values. Two filters with equal service.ranking property value (explicitly set or default value of zero) will be ordered according to their service.id service property as described in section 5.2.5, Service Properties, of the OSGi Core Specification R 4.2.

 

Please note that the ordering is actually depending on the used Apache Sling Engine bundle version. Version older than 2.3.4 of that bundle are sorting the filters in the wrong reverse order. Make sure to run a newer version of the Sling engine to get the correct ordering (see also SLING-2920).

Arun Patidar
TB3dockAuthor
Level 8
August 19, 2022

Unfortunately, this is opposite to what @santoshsai is saying?

TB3dockAuthorAccepted solution
Level 8
August 20, 2022

Due to conflicting documentation, I added debug statements to see what was happening.  the answer is in fact a), so it appears that @santoshsai could be wrong, and @arunpatidar could be right, at least for the current AEM cloud local dev environment.