【问题标题】:OSGi Application Patching mechanismOSGi 应用程序修补机制
【发布时间】:2014-04-13 05:58:49
【问题描述】:

是否有推荐的方法在运行时修补 OSGi 应用程序?我正在使用 OSGi 的 Equinox 实现。

如果我停止某个特定的捆绑包并安装修补过的捆绑包。它将如何在运行时影响其他捆绑包?..

我看到了这个OSGi Application Patching Strategy 并没有给出明确的答案。

谢谢。

【问题讨论】:

    标签: java osgi osgi-bundle


    【解决方案1】:

    我想这取决于捆绑包的好坏。

    在“OSGi in Action”一书中有一个很好的例子,第 73 页。

    自己尝试一下:

    1. 下载examples
    2. 解压文件并使用 Ant (osgi-in-action/chapter03/build.xml) 构建“chapter03”示例,
    3. chapter03/paint-example/bundles/*-3.0.jar 文件复制到例如chapter03/shell-example/1,

    为了使示例正常工作(请参阅issue),您需要这样做:

    1. this page 下载最新的 Apache Felix Framework 发行版,目前是 4.2.1,
    2. 解压org.apache.felix.main.distribution-4.2.1.zip文件,
    3. 解压felix-framework-4.2.1/bin/felix.jar文件,
    4. 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
    

    您可以查看示例源代码以了解他们是如何做到的。 我希望这能回答你的问题。

    【讨论】:

      【解决方案2】:

      这部分取决于捆绑在一起是使用服务还是导入/导出的包。服务更加动态。

      如果修补的类作为导出包使用,则其使用者将具有对原始类的引用。要强制移动到新的,必须在控制台中或直接在“FrameworkWiring”实例上调用refresh packages。 (现在称为“refreshBundles”,但原理类似。)

      在一个密切相关的问题How does OSGi bundle update work?中有完整的讨论。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-11
        • 1970-01-01
        • 2012-06-17
        • 1970-01-01
        • 1970-01-01
        • 2015-01-29
        相关资源
        最近更新 更多