在什么时候OSGi容器开始使用在运行时添加的更新版本捆绑包的导出?

时间:2014-11-04 20:39:11

标签: java osgi

假设我的OSGi容器中有以下包:

Bundle-Name: Bundle A
Import-Package: org.foo;version="[1.0.0,2)"

Bundle-Name: Bundle B1
Export-Package: org.foo;version="1.0.0"

然后不久,我添加了B2

Bundle-Name: Bundle B2
Export-Package: org.foo;version="1.1.0"

A何时开始使用B2的{​​{1}}中的课程?这是添加导出新增量版本的捆绑包的固有部分,还是必须手动完成以告诉OSGi寻找“升级”?

1 个答案:

答案 0 :(得分:3)

在B2解析后,您必须在捆绑A上调用刷新以重新连接包。 E.g:

Bundle systemBundle = bundleContext.getBundle(0);
FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
frameworkWiring.refreshBundles(Arrays.asList(bundleA.getBundleId()));

在未刷新捆绑包A之前,它将连接到捆绑包B1。即使您卸载捆绑包B1,捆绑包A也会继续连接到它。 Bundle B1将获得_pending_removal_状态,直到任何连接到它(直到所有bundle都刷新连接到它)。

有关详细信息,请参阅javadoc of FrameworkWiring functions