Which config is applied when number of matched run modes is the same
Asked Answered
S

1

7

I am using OSGI config files to define configuration for different environments, as specified in OSGI Configuration. I have configurations for multiple run modes saved in the same repository. The documentation states

"If multiple configurations for the same PID are applicable, the configuration with the highest number of matching run modes is applied."

What is the mechanism if multiple configurations for the same PID are applicable and two or more configurations are tied for the highest number of matching run modes? Which one gets applied?

Sander answered 20/6, 2016 at 21:36 Comment(1)
Good question. I wonder also if it makes a difference whether /apps/[your-site]/config is a sling:Folder or a sling:OrderedFolder.Khania
M
14

The order or OSGi configs is handled by Apache Sling. Sling has a system that determines priority for Installable Resources which includes OSGi configurations.

Out of the box, the most powerful component of calculating the priority is the root folder - /apps vs /libs. See the JcrInstaller and its configuration in your localhost at http://localhost:4502/system/console/configMgr/org.apache.sling.installer.provider.jcr.impl.JcrInstaller. The difference between the /libs and /apps "points" is large at 100 ({"/libs:100", "/apps:200"}).

After the root priority is determined, the Sling run modes are added up. See org.apache.sling.installer.provider.jcr.impl.FolderNameFilter#getPriority. Each run mode is valued at 1 "point" regardless of order. For example, at this point if you have run modes alpha and bravo, config.alpha.bravo is equal to config.bravo.alpha.

Priority then looks at certain things such as the Resource State and whether the resource is installed or not and whether the resource is a SNAPSHOT version which probably will apply more to bundles than configurations in your project. Ultimately, the comparison of the OSGi configs will come down to a lexicographically string comparison of the URLs. Going back to our example, at this point, config.alpha.bravo has a higher priority than config.bravo.alpha.

Should the OSGi configs be lexicographically equal, the final comparison is an MD5 hash of the Digest. See org.apache.sling.installer.provider.jcr.impl.ConfigNodeconverter#computeDigest.

See the full comparison function at org.apache.sling.installer.core.impl.RegisteredResourceImpl#compare.

Michaella answered 21/6, 2016 at 19:5 Comment(1)
Thanks for the comprehensive answer with links!Sander

© 2022 - 2024 — McMap. All rights reserved.