【发布时间】:2014-04-13 05:58:49
【问题描述】:
是否有推荐的方法在运行时修补 OSGi 应用程序?我正在使用 OSGi 的 Equinox 实现。
如果我停止某个特定的捆绑包并安装修补过的捆绑包。它将如何在运行时影响其他捆绑包?..
我看到了这个OSGi Application Patching Strategy 并没有给出明确的答案。
谢谢。
【问题讨论】:
标签: java osgi osgi-bundle
是否有推荐的方法在运行时修补 OSGi 应用程序?我正在使用 OSGi 的 Equinox 实现。
如果我停止某个特定的捆绑包并安装修补过的捆绑包。它将如何在运行时影响其他捆绑包?..
我看到了这个OSGi Application Patching Strategy 并没有给出明确的答案。
谢谢。
【问题讨论】:
标签: java osgi osgi-bundle
我想这取决于捆绑包的好坏。
在“OSGi in Action”一书中有一个很好的例子,第 73 页。
自己尝试一下:
osgi-in-action/chapter03/build.xml) 构建“chapter03”示例,chapter03/paint-example/bundles/*-3.0.jar 文件复制到例如chapter03/shell-example/1,为了使示例正常工作(请参阅issue),您需要这样做:
org.apache.felix.main.distribution-4.2.1.zip文件,felix-framework-4.2.1/bin/felix.jar文件,default.properties 文件复制到OSGi 示例的chapter03/shell-example/launcher.jar。现在你已经准备好了:
// In console window #1:
$ cd chapter03/shell-example/
$ java -jar launcher.jar bundles
// In console window #2:
$ telnet localhost 7070
-> install file:1/paint-3.0.jar
-> install file:1/shape-3.0.jar
-> start 2
-> install file:1/circle-3.0.jar
-> install file:1/square-3.0.jar
-> start 4
-> start 5
-> install file:1/triangle-3.0.jar
-> start 6
// You can now draw all three shapes.
// Simulate upgrade/patch of "circle" bundle:
-> stop 4
// A "work in progress" sign is in place of the circles.
// You can still move them.
// Start the "circle" bundle again and they're back in the UI:
-> start 4
您可以查看示例源代码以了解他们是如何做到的。 我希望这能回答你的问题。
【讨论】:
这部分取决于捆绑在一起是使用服务还是导入/导出的包。服务更加动态。
如果修补的类作为导出包使用,则其使用者将具有对原始类的引用。要强制移动到新的,必须在控制台中或直接在“FrameworkWiring”实例上调用refresh packages。 (现在称为“refreshBundles”,但原理类似。)
在一个密切相关的问题How does OSGi bundle update work?中有完整的讨论。
【讨论】: