OSGi 功能卸载有效,但捆绑包仍然安装
编辑:用最新信息更新了这个问题...
我在运行依赖功能的连续“features:uninstall”命令时遇到问题。 OSGi 回复“状态更改正在进行中...”,但是通过接受其他请求,我们遇到了问题。
奇怪的是,这会导致功能卸载成功,但捆绑包卸载失败。我们正在通过尝试适当地排序卸载请求并在步骤之间添加延迟来解决此问题,但我希望有一个更强大的解决方案。
正如建议的那样,我还尝试在步骤之间添加“osgi:refresh”......相同的行为。是否有另一种方法可以检测“刷新包”仍在运行以延迟后续请求等?
这是详细信息...
karaf@root> features:uninstall PolicyUtil
karaf@root> features:uninstall Policy1
karaf@root> features:uninstall Policy2
State change in progress for bundle "file:/policy2.jar" by thread "Refresh Packages".
karaf@root> features:uninstall Policy3
State change in progress for bundle "file:/policy3.jar" by thread "Refresh Packages".
karaf@root> features:uninstall Policy4
karaf@root> features:uninstall Enabler1
State change in progress for bundle "file:/enabler1.jar" by thread "Refresh Packages".
karaf@root> features:uninstall Enabler2
State change in progress for bundle "file:/enabler2.jar" by thread "Refresh Packages".
afterwards...we end up with features uninstalled (correct), but some bundles still installed (incorrect)
osgi:list
[ 277] [Installed ] [ ] [ ] [ 60] Policy2
[ 278] [Installed ] [ ] [ ] [ 60] Policy3
[ 280] [Installed ] [ ] [ ] [ 60] Enabler1
[ 281] [Installed ] [ ] [ ] [ 60] Enabler2
features:list
[uninstalled] [1.0 ] PolicyUtil repo-0
[uninstalled] [1.0 ] Policy1 repo-0
[uninstalled] [1.0 ] Policy2 repo-0
[uninstalled] [1.0 ] Policy3 repo-0
[uninstalled] [1.0 ] Enabler1 repo-0
[uninstalled] [1.0 ] Enabler2 repo-0
EDIT: updated this question with latest information...
I'm having issues running back-to-back "features:uninstall" commands for dependent features. OSGi responds back with "State change in progress...", but by accepting other requests, we run into issues.
Strangely, this results in successful feature uninstalls, but unsuccessful bundle uninstalls. We are addressing this by trying to order uninstall requests appropriately and adding a delay between steps, but I'm hoping for a more robust solution.
As suggested, I also tried adding "osgi:refresh" in between steps...same behavior. Is there another way to detect that "Refresh Packages" is still running to delay subsequent requests, etc?
Here are the details...
karaf@root> features:uninstall PolicyUtil
karaf@root> features:uninstall Policy1
karaf@root> features:uninstall Policy2
State change in progress for bundle "file:/policy2.jar" by thread "Refresh Packages".
karaf@root> features:uninstall Policy3
State change in progress for bundle "file:/policy3.jar" by thread "Refresh Packages".
karaf@root> features:uninstall Policy4
karaf@root> features:uninstall Enabler1
State change in progress for bundle "file:/enabler1.jar" by thread "Refresh Packages".
karaf@root> features:uninstall Enabler2
State change in progress for bundle "file:/enabler2.jar" by thread "Refresh Packages".
afterwards...we end up with features uninstalled (correct), but some bundles still installed (incorrect)
osgi:list
[ 277] [Installed ] [ ] [ ] [ 60] Policy2
[ 278] [Installed ] [ ] [ ] [ 60] Policy3
[ 280] [Installed ] [ ] [ ] [ 60] Enabler1
[ 281] [Installed ] [ ] [ ] [ 60] Enabler2
features:list
[uninstalled] [1.0 ] PolicyUtil repo-0
[uninstalled] [1.0 ] Policy1 repo-0
[uninstalled] [1.0 ] Policy2 repo-0
[uninstalled] [1.0 ] Policy3 repo-0
[uninstalled] [1.0 ] Enabler1 repo-0
[uninstalled] [1.0 ] Enabler2 repo-0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不确定你会得到什么样的异常,但你应该知道一件事:当你使用 shell 命令(如
osgi:uninstall
)卸载捆绑包时,你实际上调用了Bundle.uninstall()
< /a>.正如您可以在 Javadoc 中读到的那样,这并不是故事的全部。该框架倾向于对框架其余部分影响最小的操作,因此它可以卸载捆绑包,而无需删除所有相关包。如果您确实想删除所有这些,您应该使用
osgi:refresh
命令。有关详细信息,请参阅 菲利克斯常见问题解答。我能给出的最好建议是不要发出多个可能相互交叉的
卸载
请求。如果您想删除一组捆绑包,我会触发非交叉uninstall()
请求,后跟单个refreshPackages()
。另外,我不会在单个系统中混合使用“常规”控制台和 Karaf 进行捆绑管理。您还可以考虑使用外部管理器来安装和删除捆绑包。如果您想要远程管理,您可以选择 Apache ACE (声明:我是 Apache ACE 提交者)。
I'm not sure what kind of exception you will get, but you should be aware of one thing: when you uninstall a bundle using a shell command like
osgi:uninstall
, you effectively callBundle.uninstall()
. As you can read in the Javadoc there, this is not the entire story.The framework favors operations that have minimal impact on the rest of the framework, so it can uninstall a bundle without removing all related packages. If you really want to remove all of them, you should use a
osgi:refresh
command. For more information on this, see the Felix FAQ.The best advice I can give is to not issue multiple
uninstall
requests that can cross each other. If you want to remove a set of bundles, I would fire off non-crossinguninstall()
requests, followed by a singlerefreshPackages()
. Also, I would not mix bundle management using the 'regular' console and Karaf in a single system.You could also consider using an external manager for installing and removing bundles. If you want remote management, you could go for Apache ACE (disclosure: I'm an Apache ACE committer).
或者...您可以使用以下命令简单地卸载您的应用程序:
karaf 2.2.x:
osgi:uninstall --force yourapp-feature/0.0.1.SNAPSHOT
Oor ... you can simple uninstall your app with this command:
karaf 2.2.x:
osgi:uninstall --force yourapp-feature/0.0.1.SNAPSHOT
好吧,我一直在研究这个问题,我想我理解这个问题和选项......感谢您的回复。
当执行“features:uninstall [name]”时,它会为功能中的每个包调用bundle.uninstall(),然后调用refreshPackages()。然后,在卸载所有捆绑包后,它会为所有捆绑包调用refreshPackages()。问题是,refreshPackages() 是异步的(根据 OSGi 规范)并将包留在解决状态。后续卸载解析功能/捆绑包的请求无法按预期完成。
如果卸载之间有足够的延迟,或者如果稍后执行卸载(在refreshPackages()完成之后)...一切都会按预期进行。
选项...
Alright, I've been digging into this and I think I understand the issue and the options...thanks for the responses.
When "features:uninstall [name]" is executed, it calls bundle.uninstall(), then refreshPackages() for each bundle in the features. Then, after all bundles are uninstalled, it calls refreshPackages() for all bundles. The issue is that refreshPackages() is asynchronous (per the OSGi spec) and leaves bundles in a resolving state. Subsequent requests to uninstall resolving features/bundles fail to complete as expected.
If there is sufficient delay in between uninstalls or if a later uninstall is executed (after the refreshPackages() has completed)...everything works as expected.
Options...
根据我的经验,当一个包的资源仍然被另一个包引用或使用时,就会发生这种情况。在这种情况下,框架无法删除捆绑包,并且整个 jar 文件仍由 VM 处理。
查看并确保所有引用均已删除。一个常见的错误是仍在捆绑中实例化的对象之一中运行线程。这也算作仍在使用的资源广告,无法删除。
In my experience this happens when a resource of a bundle is still referenced or used by another bundle. In this case the framework is not able to remove the bundle and the whole jar file is still processed by the VM.
Have a look and be sure that all references are removed. A common mistake is also still running thread in one of the objects instantiated in the bundle. This also counts as a resource still in use ad which cannot be removed.
就我而言,我已经卸载了该功能并注意到悬挂的捆绑包编号,然后关闭了 karaf (3.x)。然后我删除了文件夹 [karaf-install]/data/cache/[hanging-bundle-number] 的子文件夹。
现在我重新启动 karaf 并且捆绑包战争未显示在捆绑包:列表中。
In my case i have uninstalled the feature and noticed the hanging bundle numbers and then shutdown karaf (3.x). Then i have removed the subfolders of folder [karaf-install]/data/cache/[hanging-bundle-number].
Now i restart karaf and the bundle wars not shown in the bundle:list.