当匹配的 运行 模式数相同时应用哪个配置

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

我正在使用 OSGI 配置文件来定义不同环境的配置,如 OSGI Configuration 中所述。我在同一个存储库中保存了多个 运行 模式的配置。文档说明

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

如果同一 PID 的多个配置适用并且两个或多个配置 并列 匹配 运行 模式的最高数量,则机制是什么?应用了哪一个?

订单或 OSGi 配置由 Apache Sling 处理。 Sling 有一个系统可以确定 Installable Resources 的优先级,其中包括 OSGi 配置。

开箱即用,计算优先级的最强大组件是根文件夹 - /apps/libs。参见JcrInstaller and its configuration in your localhost at http://localhost:4502/system/console/configMgr/org.apache.sling.installer.provider.jcr.impl.JcrInstaller/libs/apps "points" 之间的差异很大,为 100 ({"/libs:100", "/apps:200"})。

root优先级确定后,Sling 运行模式相加。参见 org.apache.sling.installer.provider.jcr.impl.FolderNameFilter#getPriority。无论顺序如何,每个 运行 模式的值为 1 "point"。例如,此时如果您有 运行 模式 alphabravoconfig.alpha.bravo 等于 config.bravo.alpha

Priority 然后查看某些事情,例如资源状态和资源是否已安装以及资源是否是 SNAPSHOT 版本,这可能更多地应用于项目中的捆绑包而不是配置。最终,OSGi 配置的比较将归结为 URL 的字典字符串比较。回到我们的例子,在这一点上,config.alpha.bravoconfig.bravo.alpha.

具有更高的优先级

如果 OSGi 配置在字典序上相等,则最终比较是摘要的 MD5 散列。参见 org.apache.sling.installer.provider.jcr.impl.ConfigNodeconverter#computeDigest

org.apache.sling.installer.core.impl.RegisteredResourceImpl#compare 查看完整的比较功能。