本文介绍了以编程方式开始/停止片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在OSGI中实现一个功能切换,这意味着我想以编程方式启动和停止软件包。

I want to implement a feature toggle in OSGI, which means I want to start and stop bundles programmatically.

对于非常容易的插件:

Bundle plugin = //...
plugin.start();
plugin.stop();

对于片段,这不是那么容易。停止不起作用,如果我使用 uninstall()片段已经不好了,我无法再安装,因为我不知道正确的位置 BundleContext#installBundle(...)(并查看 Bundle#getLocation()这个片段本身)。

For fragments it's not so easy. Stopping does not work at all, and if I use uninstall() the fragment is gone for good, and I'm not able to install it again, since I don't know the correct location for BundleContext#installBundle(...) (and looking at Bundle#getLocation(), neither does the fragment itself).

我面临的问题是有一个片段有助于一些Eclipse扩展点。只是停止主机插件不会删除这些服务(无论什么原因)。所以我需要手动停止该片段(或者可能会清楚那个保持螺丝拧紧应用程序的愚蠢Eclipse缓存?)。

The problem I'm facing is I have a fragment contributing to some Eclipse extension points. Just stopping the host plug-in will not remove these services (for whatever reason). So I need to stop the fragment manually (or maybe clear that stupid Eclipse cache that keeps screwing applications up?).

那么如何在运行时安装碎片? p>

So how can I install fragments at runtime?

推荐答案

片段没有自己的生命周期。它们是主机捆绑的生命周期的一部分。这意味着没有办法独立于主机启动/停止它们。

Fragments do not have their own life cycle. They are part of the life cycle of their host bundle. That means there is no way to start/stop them independently of the host.

如果您需要更多关于捆绑,碎片和生命周期的背景知识,我建议您阅读OSGi规范,可从网站下载。

If you need more background about bundles, fragments and life cycles, I advise you to read the OSGi specification, which can be downloaded from the http://osgi.org/ website.

这篇关于以编程方式开始/停止片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:38