【发布时间】:2012-07-19 10:10:54
【问题描述】:
我在 2.2.8 版本的 Karaf 上遇到了问题(很可能在早期版本上也是如此)。
我将使用 Karaf 来托管具有动态部署包的系统。捆绑包是由用户部署的,我事先无法知道它们是什么。
我希望 BundleActivator.start() 的顺序完全对应于包之间的包依赖关系(导入/导出包的依赖关系),并计划期望可以安全地假设 bundle0 将在 bundle1 开始之前完全初始化开始。但事实并非如此 - 似乎 BundleActivator.start() 是以“随机”顺序调用的,并且忽略了包之间的包依赖关系。
示例用例,我有 3 个库
test-lib0 - defines testlib0.ITestRoot, exports testlib0 package
test-lib1 - defines testlib1.TestRoot implements ITestRoot, exports testlib1 package
test-lib2 - uses both libs, ITestRoot and TestRoot
当 Karaf 启动时,我在控制台中看到以下示例输出
karaf@root> TestLib1Activator.start()
TestLib2Activator.start()
ITestRoot: interface com.testorg.testlib0.ITestRoot - 16634462
TestRoot: class com.testorg.testlib1.TestRoot - 21576551
TestLib0Activator.start()
但我希望它应该总是按这个顺序
TestLib0Activator.start()
TestLib1Activator.start()
TestLib2Activator.start()
ITestRoot: interface com.testorg.testlib0.ITestRoot - 16634462
TestRoot: class com.testorg.testlib1.TestRoot - 21576551
我正在附加示例项目以进行测试。测试用例:在“mvn install”之后,只需将 jar 从 ./deploy 文件夹移动到 Karaf 的同一个文件夹,跟踪消息应该会出现在控制台中。 (注意:它可能从第一次尝试就可以正常工作,然后再试一次:))
示例测试项目 http://karaf.922171.n3.nabble.com/file/n4025256/KarafTest.zip
注意:这是来自http://karaf.922171.n3.nabble.com/What-is-the-natural-start-order-for-dependent-bundle-td4025256.html的交叉帖子
【问题讨论】:
-
您说:“我希望 BundleActivator.start() 的顺序与包之间的包依赖关系完全对应”。为什么会有这样的期待?这是不正确的,所以我很想知道它是从哪里来的。
-
假设这种期望来自“我的头顶”。我在想它应该以这种方式工作。在查看 OSGI 规范后,这似乎是错误的期望。
标签: osgi apache-karaf