Note that there are some explanatory texts on larger screens.

plurals
  1. POTerminate OSGi-Framework thats running in Tomcat
    text
    copied!<p>according to <a href="http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fua_help_war.htm" rel="nofollow">http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fua_help_war.htm</a> I set up a dedicated Tomcat server that runs several eclipse-help-plugins.</p> <p>The server and also the help is up and running well. But now I realized that stopping the server especially the OSGi-Framework seems to be a problem. I always have to kill the server process if the help-war is deployed and I believe that I have to shutdown the OSGi-Framework gracefully.</p> <p>After some investigation I came up with the following implementation of a ServletContextListener, that stops the system-bundle by calling bundleContext.getBundle(0).stop():</p> <pre><code>import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.FrameworkUtil; public class OsgiShutdownListener implements ServletContextListener { /** {@inheritDoc} */ @Override public void contextDestroyed(ServletContextEvent sce) { Bundle bundle = FrameworkUtil.getBundle(org.eclipse.core.runtime.adaptor.EclipseStarter.class); BundleContext bundleContext = bundle.getBundleContext(); try { bundleContext.getBundle(0).stop(); } catch (BundleException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** {@inheritDoc} */ @Override public void contextInitialized(ServletContextEvent sce) { System.out.println("starting"); } } </code></pre> <p>But FrameworkUtil.getBundle(org.eclipse.core.runtime.adaptor.EclipseStarter.class) always returns null, so I never get a reference to a BundleContext to stop the framework.</p> <p><strong>EDIT:</strong> I changed the code to sce.getServletContext().getAttribute("osgi-bundlecontext") in contextDestroyed() and contextInitialized() as well, but in both cases I get no reference to the bundle context. Bundle context is always null.</p> <pre><code>public class OsgiShutdownListener implements ServletContextListener { private BundleContext bundleContext; /** {@inheritDoc} */ @Override public void contextDestroyed(ServletContextEvent sce) { // Bundle bundle = // FrameworkUtil.getBundle(org.eclipse.core.runtime.adaptor.EclipseStarter.class); // this.bundleContext = bundle.getBundleContext(); ServletContext context = sce.getServletContext(); this.bundleContext = (BundleContext) context .getAttribute("osgi-bundlecontext"); try { this.bundleContext.getBundle(0).stop(); } catch (BundleException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** {@inheritDoc} */ @Override public void contextInitialized(ServletContextEvent sce) { ServletContext context = sce.getServletContext(); this.bundleContext = (BundleContext) context .getAttribute("osgi-bundlecontext"); } } </code></pre> <p>How do I get a bundleContext in this situation to stop the system bundle? Or how do I gracefully stop the OSGi-Framework when the server shuts down?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload