protected void startPluginModules(List<Module> pluginModules) { for (Module module : pluginModules) { try { module.start(); } catch (ModuleException ex) { LOGGER.error("Cannot start plugin: " + module, ex); } } }
/** * Installs/starts the webapp as a module. */ @Override public void contextInitialized(ServletContextEvent event) { Runtime runtime = RuntimeLocator.getRequiredRuntime(); ServletContext servletContext = event.getServletContext(); Module module = runtime.getModule(servletContext.getClassLoader()); // Install the module if (module == null) { module = installWebappModule(servletContext); } // Start the module if (module != null) { servletContext.setAttribute(Module.class.getName(), module); try { module.start(); } catch (ModuleException ex) { throw new IllegalStateException(ex); } // HttpService integration BundleContext bundleContext = module.adapt(Bundle.class).getBundleContext(); servletContext.setAttribute(BundleContext.class.getName(), bundleContext); } }
/** * Installs/starts the webapp as a module. */ @Override public void contextInitialized(ServletContextEvent event) { Runtime runtime = RuntimeLocator.getRequiredRuntime(); ServletContext servletContext = event.getServletContext(); Module module = runtime.getModule(servletContext.getClassLoader()); // Install the module if (module == null) { module = installWebappModule(servletContext); } // Start the module if (module != null) { servletContext.setAttribute(Module.class.getName(), module); try { module.start(); } catch (ModuleException ex) { throw new IllegalStateException(ex); } // HttpService integration BundleContext bundleContext = module.adapt(Bundle.class).getBundleContext(); servletContext.setAttribute(BundleContext.class.getName(), bundleContext); } }
@Test public void testModuleLifecycle() throws Exception { Runtime runtime = RuntimeLocator.getRequiredRuntime(); Module modA = runtime.getModule(getClass().getClassLoader()); Assert.assertEquals(Module.State.ACTIVE, modA.getState()); String symbolicName = modA.getHeaders().get("Bundle-SymbolicName"); Assert.assertEquals("simple-bundle", symbolicName); ModuleContext context = modA.getModuleContext(); Module sysmodule = runtime.getModule(0); symbolicName = sysmodule.getHeaders().get("Bundle-SymbolicName"); Assert.assertNotNull("System bundle symbolic name not null", symbolicName); ServiceReference<String> sref = context.getServiceReference(String.class); String service = context.getService(sref); Assert.assertEquals("Hello", service); modA.stop(); Assert.assertEquals(Module.State.INSTALLED, modA.getState()); modA.uninstall(); Assert.assertEquals(Module.State.UNINSTALLED, modA.getState()); try { modA.start(); Assert.fail("IllegalStateException expected"); } catch (IllegalStateException ex) { // expected } }
@Test public void testModuleLifecycle() throws Exception { // Verify that the Runtime service is registered Runtime runtime = ServiceLocator.getRequiredService(Runtime.class); Module modA = runtime.getModule(getClass().getClassLoader()); Assert.assertEquals(Module.State.ACTIVE, modA.getState()); String symbolicName = modA.getHeaders().get("Bundle-SymbolicName"); Assert.assertEquals("simple-module", symbolicName); ModuleContext context = modA.getModuleContext(); Module sysmodule = runtime.getModule(0); symbolicName = sysmodule.getHeaders().get("Bundle-SymbolicName"); Assert.assertNotNull("System bundle symbolic name not null", symbolicName); ServiceReference<String> sref = context.getServiceReference(String.class); String service = context.getService(sref); Assert.assertEquals("Hello", service); modA.stop(); Assert.assertEquals(Module.State.INSTALLED, modA.getState()); modA.uninstall(); Assert.assertEquals(Module.State.UNINSTALLED, modA.getState()); try { modA.start(); Assert.fail("IllegalStateException expected"); } catch (IllegalStateException ex) { // expected } }