Which config is applied when number of matched run

2020-03-19 03:51发布

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?

标签: osgi aem sling
1条回答
乱世女痞
2楼-- · 2020-03-19 04:09

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.

查看更多
登录 后发表回答