关闭 OSGi 容器的最佳方法(特别是春分)
我正在寻找关闭 OSGi 容器的最佳实践。
目前我们正在使用一个小型启动器应用程序,它调用 EclipseStarter.startup() 并安装一些核心包。之后启动器终止。
当测试 GUI(作为捆绑包运行)关闭时,它会调用 System.exit(0) 来关闭容器,但必须有比这更优雅的解决方案。
谢谢
I'm looking for a best practice on shutting down an OSGi container.
Currently we are using a small launcher app which calls EclipseStarter.startup() and installs some core bundles. After that the launcher terminates.
When the test GUI (running as a bundle) is closed it calls a System.exit(0) to shutdown the container, but there must be a more elegant solution than this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请不要使用 System.exit(0) 来关闭 OSGi 框架。您应该通过停止 ID 为 0 的捆绑包(系统捆绑包)来实现此目的。这样,您就可以为所有捆绑包提供有序关闭的机会(例如释放资源等)。
OSGi 规范定义了以下内容(核心规范、R4.x、4.2.6 停止框架)。
该章详细描述了框架关闭时会发生什么。
系统捆绑包分别。还定义了框架对象(第 4.6 章“系统捆绑包”):
OSGi 规范可在 OSGi 联盟网站 (http://www.osgi.org/Specifications/主页)。
Please, don't use System.exit(0) to shut down an OSGi framework. You should to it by stopping the bundle with the ID 0, the System bundle. This way, you give all bundles a chance to shut down in an orderly manner (e.g. to free resources etc).
The OSGi specification defines the following (Core Specification, R4.x, 4.2.6 Stopping a Framework).
In that chapter a detailed description is given what happens when a framework is shut down.
The system bundle resp. the framework object is also defined (chapter 4.6 The System Bundle):
The OSGi spec is available for free at the OSGi Alliance's website (http://www.osgi.org/Specifications/HomePage).
我通常这样终止框架:
bundlecontext.getBundle(0).stop();
id = 0 的包是系统包
i usually terminate the framework like this:
bundlecontext.getBundle(0).stop();
The bundle with id = 0 is the system-bundle
我还在应用程序嵌入式上下文中使用 Equinox,并在系统捆绑包上调用 stop(),然后使用 EclipseStarter.shutdown()。您可能必须停止所有捆绑包。
我从来没有真正关心过我的应用程序中的捆绑包关闭,因为没有保留状态。
I also use Equinox in an application embedded context and I call stop() on the System Bundle and follow that up with EclipseStarter.shutdown(). You may have to stop all of your bundles.
I've never really been concerned about the bundle shutdown in my application since there is no retained state.
目前还没有标准方法可以做到这一点。 OSGI 将在下一个版本中将这部分纳入其标准 API,但我猜测所有 OSGI 容器都需要一段时间才能实现这一点。现在使用容器特定的代码,但远离 System.exit()。
问候,
林·托伦
There is no standard way of doing this yet. OSGI will make this part of their standard api in the next release, but I gues that it will take a while before all OSGI containers implement this. Use container specific code for now, but stay away from System.exit().
Regards,
Leen Toelen