简体   繁体   English

从代码解析OSGi捆绑包

[英]Resolve OSGi bundle from code

I have to programmatically ensure a specific start order of several OSGi bundles because the activation procedure has some dependencies to other bundles. 我必须以编程方式确保多个OSGi捆绑包的特定启动顺序,因为激活过程与其他捆绑包有一些依赖性。 I manage the bundle's life cycle from Java code where I try to determine the bundle's wiring to calculate the correct start order. 我从Java代码管理捆绑软件的生命周期,在Java代码中,我尝试确定捆绑软件的接线以计算正确的启动顺序。 All bundles are installed correctly. 所有捆绑软件均已正确安装。

Because the bundle wiring seams to be initialised in the resolved state, I am looking for a way to programmatically resolve a bundle. 由于将束线接缝初始化为已解决状态,因此我正在寻找一种以编程方式解决束的方法。 I only found bundle.start() which resolves but also starts the bundle. 我只找到bundle.start()可以解析但也可以启动bundle。 Is there a way to only resolve without start? 有没有办法解决而不开始? If I use the OSGi shell manually I can achieve this by resolve <bundle-id> . 如果我手动使用OSGi Shell,则可以通过resolve <bundle-id>

There is no way you can do this in a reliable and robust way. 您无法以可靠且可靠的方式执行此操作。 OSGi has no start ordering. OSGi没有开始订购。 period. 期。 out. 出。 get over it. 克服它。

The reason is simple, a bundle could be stopped and that throws of any ingenious ordering you invented at startup. 原因很简单,捆绑包可能会停止,并且引发您在启动时发明的任何巧妙命令。

The only ordering that works is service dependencies. 唯一有效的顺序是服务依赖性。 Each component should specify what services it depends on and not start before the services it needs are registered. 每个组件应指定其依赖的服务,而不是在注册所需的服务之前启动。 That is the ONLY reliably way to get ordering. 这是唯一可靠的订购方式。

This is of course trivial to do when you can use DS. 当您可以使用DS时,这当然很简单。

You can resolve a set of bundles with FrameworkWiring.resolveBundles . 您可以使用FrameworkWiring.resolveBundles解析一组捆绑软件。 But resolving a bundle is just a necessary precursor to starting a bundle but has nothing to do with ordering. 但是解决捆绑包只是启动捆绑包的必要先决条件,但与订购无关。 You can resolve all the bundles at once and then start the bundles in a random order. 您可以一次解决所有捆绑软件,然后以随机顺序启动捆绑软件。

As Peter says, if you need to start the bundles in some specific order, something is wrong with your system. 如Peter所说,如果您需要按特定顺序启动捆绑软件,则系统出了点问题。 How will it handle updating a bundle? 它将如何处理更新包?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM