简体   繁体   English

OSGi框架可以同时启动捆绑包吗?

[英]Can OSGi frameworks start bundles concurrently?

We have two bundles, both embed a different version of the same 3rd party library and we have to use them with different configurations. 我们有两个捆绑软件,它们都嵌入了相同的第三方库的不同版本,我们必须将它们用于不同的配置。 Unfortunately the library is only configurable via system properties. 不幸的是,该库只能通过系统属性进行配置。

So, we try to do the following the Activator classes: 因此,我们尝试执行以下Activator类:

  1. setting the required system properties, 设置所需的系统属性,
  2. initializing the library, 初始化库,
  3. unsetting the former system properties. 取消设置以前的系统属性。

It won't work if an OSGi framework starts the two bundles concurrently. 如果OSGi框架同时启动两个捆绑包,则将不起作用。 Is it allowed for an OSGi framework implementation? 是否允许OSGi框架实现? Is this solution safe? 这个解决方案安全吗? Is there any other way to set the same system property to different values for different bundles? 还有其他方法可以将相同的系统属性针对不同的捆绑商品设置为不同的值吗?

(If it's possible we would like to avoid setting different start levels for these bundles.) (如果可能,我们希望避免为这些捆绑包设置不同的开始级别。)

An OSGi framework implementation is allowed to start bundles, within a given start level, concurrently. 允许OSGi框架实现在给定的启动级别内同时启动包。 So you can put the bundle's in different start levels to ensure one is started before the other. 因此,您可以将捆绑软件的启动级别设置为不同的级别,以确保其中一个先于另一个启动。

In Felix and Equinox, the bundle install/resolve/start/stop/uninstall actions all happen on a single thread. 在Felix和Equinox中,捆绑包的安装/解决/启动/停止/卸载操作均在单个线程上进行。 I can't recall for certain if the activators run on that same thread, but I think they do. 我无法确定激活器是否在同一线程上运行,但我认为它们确实在运行。

How about creating an OSGi service that wraps the library initialization. 如何创建包装库初始化的OSGi服务。 So you only have to do it once. 因此,您只需要做一次。 Alternatively the service could synchronize the initializations and so make sure it does not happen concurrently. 或者,服务可以同步初始化,因此请确保它不会同时发生。

Is it a strong requirement to have them in separate bundles? 将它们分开包装是否有强烈要求? What do you do with the libraries, do you export them as java packages or do you create services out of them? 您如何处理这些库,将它们导出为Java包还是使用它们创建服务? If you can put both libraries in one and the same bundle you have full control which is initialized first and which one second. 如果您可以将两个库放在一个同一个包中,则可以完全控制哪个先初始化,再初始化一秒。

Btw if you export them in the bundle manifest with Export-Package have in mind that exported packages can be used by other bundles even when the bundle is in the RESOLVED state, ie installed but not yet started. 顺便说一句,如果您使用Export-Package将其导出到软件包清单中,则请记住,即使软件包处于已解决状态(即已安装但尚未启动),其他软件包也可以使用导出的软件包。 So it could happen that somebody calls methods of the lib even before your Bundle Activator has been created and has taken care of the initialization.... 因此,有可能有人甚至在创建Bundle Activator并完成初始化工作之前就调用了lib的方法。

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

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