Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Shutting down the OSGi framework
Shutting down the OSGi framework [message #895816] Mon, 16 July 2012 07:49 Go to next message
Kris Slowinski is currently offline Kris SlowinskiFriend
Messages: 18
Registered: August 2011
Junior Member
I was looking for some time and could not find any concrete solution for how to terminate the OSGi framework in the clean way. I experimented a bit and came up with the following solution:

final BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
if ( bundleContext != null ) {
  bundleContext.getBundle(0).stop();
}


Is that a good way of handling the OSGi shutdown or does anyone know a better approach?
Re: Shutting down the OSGi framework [message #896503 is a reply to message #895816] Wed, 18 July 2012 15:00 Go to previous messageGo to next message
Libor Jelinek is currently offline Libor JelinekFriend
Messages: 143
Registered: January 2012
Location: Prague, Czech Rep.
Senior Member

Hello Kris,
your approach should be definitively correct and it gives all bundles a
change to shutdown gracefully.

See
http://stackoverflow.com/questions/1916432/best-way-to-shutdown-an-osgi-container-specifically-equinox
for broader discussion.

Libor

On 07/16/2012 09:49 AM, Kris Mising name wrote:
> I was looking for some time and could not find any concrete solution for
> how to terminate the OSGi framework in the clean way. I experimented a
> bit and came up with the following solution:
>
>
> final BundleContext bundleContext =
> FrameworkUtil.getBundle(this.getClass()).getBundleContext();
> if ( bundleContext != null ) {
> bundleContext.getBundle(0).stop();
> }
>
>
> Is that a good way of handling the OSGi shutdown or does anyone know a
> better approach?
Re: Shutting down the OSGi framework [message #921044 is a reply to message #896503] Sun, 23 September 2012 19:23 Go to previous messageGo to next message
Karl Weber is currently offline Karl WeberFriend
Messages: 63
Registered: September 2010
Member
Libor Jelinek wrote on Wed, 18 July 2012 17:00
Hello Kris,
your approach should be definitively correct and it gives all bundles a
change to shutdown gracefully.

See
http://stackoverflow.com/questions/1916432/best-way-to-shutdown-an-osgi-container-specifically-equinox
for broader discussion.


Well, I am having a problem with this approach. I am using an E4 RCP application, based on the 4.2 platform. Equinox is started with the VM arguments
-Declipse.application.launchDefault=false -Declipse.allowAppRelaunch=true
An OSGi Service is launching and relaunching various IApplications using the OSGi application admin.

After the last IApplication has stopped, I call
fComponentContext.getBundleContext().getBundle(0).stop();
EclipseStarter.shutdown();

Unfortunately, the JVM itself does not terminate but keeps on running...waiting for godot. So should I call
System.exit(0)
after stopping the framework and shutting down the EclipseStarter? Or what else may be wrong here?

P.S. Shutting down the EclipseStarter was something I tried because it doesn't work without it -- but it doesn't work with it either. In fact, it does not seem to make any difference at all.
Re: Shutting down the OSGi framework [message #935780 is a reply to message #895816] Sun, 07 October 2012 10:01 Go to previous message
Karl Weber is currently offline Karl WeberFriend
Messages: 63
Registered: September 2010
Member
O.k. I think I understand my problem a little bit better, but I don't have a solution.

I start the framework with the options
-Declipse.application.launchDefault=false -Declipse.allowAppRelaunch=true

The first option ensures, that no application is started automatically. This works, the main thread is indeed waiting and I have to launch my application manually.

The second option ensures, that Quote:
the main thread will continue to wait for another application descriptor to be launched after the currently running application has quit. Stopping the system.bundle (i.e. the bundle with a bundle ID equel to zero) will force the main thread to stop waiting for another application to launch


This, however, does not work. The main thread keeps on waiting forever after the first application stopped and I called
bundleContext.getBundle(0).stop();


The only proof I have is that once I set this option to false, everything works, i.e. the main thread stops after the first application quit, and the framework stops after calling
bundleContext.getBundle(0).stop();


Unfortunately this will prevent me from launching another application after my first application quit.

My current understanding is, that this is a bug, or am I missing something else?
Previous Topic:BridgeServlet problem
Next Topic:Provisioning exception
Goto Forum:
  


Current Time: Fri Apr 19 05:04:16 GMT 2024

Powered by FUDForum. Page generated in 0.03267 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top