English 中文(简体)
Best way to shutdown an OSGi Container (specifically equinox)
原标题:

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

最佳回答

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).

Shutdown can be initiated by stopping the system bundle, [...] or calling the stop method on the framework object.

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 system bundle resembles the framework object when a framework is launched, but implementations are not required to use the same object for the framework object and the system bundle. However, both objects must have bundle id 0, same location, and bundle symbolic name.

The OSGi spec is available for free at the OSGi Alliance s website (http://www.osgi.org/Specifications/HomePage).

问题回答

i usually terminate the framework like this:

bundlecontext.getBundle(0).stop();

The bundle with id = 0 is the system-bundle

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.

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





相关问题
How can I get the Windows last reboot reason

I d like to know what is the Windows API function (if any exists) that provides information about the last Windows reboot source. There are three main possible causes: The computer crashed on a blue ...

Applescript to run at shut down

I am trying to make an application using AppleScript which can remind to check my mails, if I forget to check, at shutdown. I took help from this link: http://discussions.apple.com/thread.jspa?...

Shutdown a computer from AIR/Flex

I need to figure out how to shut down the computer from an Adobe AIR application. I have been trying to figure out how to do this, and without success.

The OS doesn t shutdown, but my application does

I have an application which when I close the Windows, it exits gracefully and quickly (checked also in Task Manager and Process Explorer - the process isn t there anymore) but the OS doesn t. It seems ...

How to bring a system out of standby programatically?

Is there a way to do it in c# or vb.net? I have to bring a system out of standby and play a notification sound if it is in standby mode, at specific time intervals. Is this possible?

How to Safely Force Shutdown of Mac

What I want I m developing a little app to force me to only work at certain times of day - I need something to force me to stop working in the evenings so I can be more effective in the day. The ...

热门标签