@Override public int getState() { switch (module.getState()) { case INSTALLED: return Bundle.RESOLVED; case STARTING: return Bundle.STARTING; case ACTIVE: return Bundle.ACTIVE; case STOPPING: return Bundle.STOPPING; case UNINSTALLED: return Bundle.UNINSTALLED; } return Bundle.UNINSTALLED; }
/** * Uninstalls the webapp's module. */ @Override public void contextDestroyed(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); Module module = (Module) servletContext.getAttribute(Module.class.getName()); if (module != null && module.getState() != Module.State.UNINSTALLED) { module.uninstall(); } }
/** * Uninstalls the webapp's module. */ @Override public void contextDestroyed(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); Module module = (Module) servletContext.getAttribute(Module.class.getName()); if (module != null && module.getState() != Module.State.UNINSTALLED) { module.uninstall(); } }
@Override public String getModuleState() { return context.getModule().getState().toString(); } };
@Override public String getModuleState() { return context.getModule().getState().toString(); } };
return true; if (module.getState() == Module.State.UNINSTALLED) return false;
while (itmods.hasNext()) { Module module = itmods.next(); State state = module.getState(); if (!states.contains(state)) { itmods.remove();
@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 } }
ServiceListenerRegistration listenerReg = info.getRegistration(); Module owner = info.getModuleContext().getModule(); if (owner.getState() == Module.State.UNINSTALLED) { continue;
ResourceIdentity identity = handle.getResource().getIdentity(); Assert.assertSame(handle.getModule(), runtime.getModule(identity)); Assert.assertEquals("ACTIVE " + identity, State.ACTIVE, handle.getModule().getState());
/** * Provision a resource from an input stream. * * The client controlls the resource identity * The installed resource is self sufficient - no additional dependency mapping needed. */ @Test public void testProvisionStreamResource() throws Exception { Provisioner provisioner = ServiceLocator.getRequiredService(Provisioner.class); ResourceIdentity identityA = ResourceIdentity.fromString(RESOURCE_A); ResourceBuilder builderA = provisioner.getContentResourceBuilder(identityA, deployer.getDeployment(RESOURCE_A)); ResourceHandle handle = provisioner.installResource(builderA.getResource()); try { // Verify that the module got installed Runtime runtime = RuntimeLocator.getRequiredRuntime(); Module module = runtime.getModule(identityA); Assert.assertNotNull("Module not null", module); Assert.assertEquals("ACTIVE " + module, State.ACTIVE, module.getState()); // Verify that the module activator was called MBeanServer server = ServiceLocator.getRequiredService(MBeanServer.class); Assert.assertTrue("MBean registered", server.isRegistered(getObjectName(module))); Assert.assertEquals("ACTIVE", server.getAttribute(getObjectName(module), "ModuleState")); } finally { handle.uninstall(); } }
ResourceIdentity identity = handle.getResource().getIdentity(); Assert.assertSame(handle.getModule(), runtime.getModule(identity)); Assert.assertEquals("ACTIVE " + identity, State.ACTIVE, handle.getModule().getState());
/** * Provision a resource from maven coordinates. * * The client controlls the resource identity * The installed resource is self sufficient - no additional dependency mapping needed. */ @Test public void testMavenResource() throws Exception { Provisioner provisioner = ServiceLocator.getRequiredService(Provisioner.class); Runtime runtime = RuntimeLocator.getRequiredRuntime(); // Tomcat does not support jar deployments Assume.assumeFalse(RuntimeType.TOMCAT == RuntimeType.getRuntimeType()); ResourceIdentity identityA = ResourceIdentity.fromString("camel.core.unshared"); MavenCoordinates mavenid = MavenCoordinates.parse("org.apache.camel:camel-core:jar:2.11.0"); ResourceBuilder builderA = provisioner.getMavenResourceBuilder(identityA, mavenid); ResourceHandle handleA = provisioner.installResource(builderA.getResource()); try { Assert.assertSame(handleA.getModule(), runtime.getModule(identityA)); Assert.assertEquals("ACTIVE " + identityA, State.ACTIVE, handleA.getModule().getState()); } finally { handleA.uninstall(); } }
try { Assert.assertSame(handleA.getModule(), runtime.getModule(identityA)); Assert.assertEquals("ACTIVE " + identityA, State.ACTIVE, handleA.getModule().getState());