Java Code Examples for org.osgi.framework.Bundle#stop()

The following examples show how to use org.osgi.framework.Bundle#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractLoadBundleTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the loading of the 1.2 Compatibility API bundle, its classes should be loadable from the Core bundle, 
 * and the class loader should be the same between a class from core and a class from compat
 */
@Test
public void testLog4J12Fragement() throws BundleException, ReflectiveOperationException {

    final Bundle api = getApiBundle();
    final Bundle plugins = getPluginsBundle();
    final Bundle core = getCoreBundle();
    final Bundle compat = get12ApiBundle();

    api.start();
    plugins.start();
    core.start();
    
    final Class<?> coreClassFromCore = core.loadClass("org.apache.logging.log4j.core.Core");
    final Class<?> levelClassFrom12API = core.loadClass("org.apache.log4j.Level");
    final Class<?> levelClassFromAPI = core.loadClass("org.apache.logging.log4j.Level");

    Assert.assertEquals("expected 1.2 API Level to have the same class loader as Core", levelClassFrom12API.getClassLoader(), coreClassFromCore.getClassLoader());
    Assert.assertNotEquals("expected 1.2 API Level NOT to have the same class loader as API Level", levelClassFrom12API.getClassLoader(), levelClassFromAPI.getClassLoader());

    core.stop();
    api.stop();

    uninstall(api, plugins, core, compat);
}
 
Example 2
Source File: HttpWhiteboardCoexistenceTest.java    From aries-jax-rs-whiteboard with Apache License 2.0 6 votes vote down vote up
private void restartHttpServiceWhiteboard() throws Exception {
    BundleWiring runtimeWiring = _runtimeServiceReference.getBundle().adapt(BundleWiring.class);
    
    Bundle httpService = runtimeWiring.getRequiredWires("osgi.implementation").stream()
        .filter(bw -> "osgi.http".equals(bw.getCapability().getAttributes().get("osgi.implementation")))
        .map(bw -> bw.getProvider().getBundle())
        .findFirst().get();
    
    try {
        httpService.stop();
    } finally {
        httpService.start();
    }
    
    _runtime = _runtimeTracker.waitForService(5000);
    _runtimeServiceReference = _runtimeTracker.getServiceReference();
}
 
Example 3
Source File: AutomationIntegrationTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertThatARuleSwitchesFromIDLEtoUNINITIALIZEDifAModuleHandlerDisappearsAndBackToIDLEifItAppearsAgain()
        throws BundleException {
    logger.info(
            "assert that a rule switches from IDLE to UNINITIALIZED if a moduleHanlder disappears and back to IDLE if it appears again");
    Rule rule = createSimpleRule();
    ruleRegistry.add(rule);
    assertThat(ruleEngine.getStatusInfo(rule.getUID()).getStatus(), is(RuleStatus.IDLE));

    Bundle moduleBundle = FrameworkUtil.getBundle(GenericEventTriggerHandler.class);
    moduleBundle.stop();
    waitForAssert(() -> {
        logger.info("RuleStatus: {}", ruleEngine.getStatusInfo(rule.getUID()).getStatus());
        assertThat(ruleEngine.getStatusInfo(rule.getUID()).getStatus(), is(RuleStatus.UNINITIALIZED));
    }, 3000, 100);

    moduleBundle.start();
    ruleEngine.setEnabled(rule.getUID(), true);
    waitForAssert(() -> {
        logger.info("RuleStatus: {}", ruleEngine.getStatusInfo(rule.getUID()));
        assertThat(ruleEngine.getStatusInfo(rule.getUID()).getStatus(), is(RuleStatus.IDLE));
    }, 3000, 100);
}
 
Example 4
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void stopFramework0()
{

  final Object[] options = { Strings.get("yes"), Strings.get("cancel") };

  final int n =
    JOptionPane.showOptionDialog(frame, Strings.get("q_stopframework"),
                                 Strings.get("msg_stopframework"),
                                 JOptionPane.YES_NO_OPTION,
                                 JOptionPane.QUESTION_MESSAGE, null, options,
                                 options[1]);
  if (n == 0) {
    try {
      final Bundle sysBundle = Activator.getBC().getBundle(0);
      sysBundle.stop();
    } catch (final Exception e) {
      showErr("Failed to stop bundle.", e);
    }
  }
}
 
Example 5
Source File: Main.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int doStopBundle(final String[] args, int i, final int options)
{
  assertFramework();
  if (i+1 < args.length) {
    final long id = getBundleID(framework, args[i+1]);
    final Bundle b = framework.getBundleContext().getBundle(id);
    try {
      b.stop(options);
      println("Stopped: ", b);
    } catch (final Exception e) {
      error("Failed to stop", e);
    }
    i++;
  } else {
    error("No ID for stop command");
  }
  return i;
}
 
Example 6
Source File: AbstractLoadBundleTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Tests LOG4J2-1637.
 */
@Test
public void testClassNotFoundErrorLogger() throws BundleException {

    final Bundle api = getApiBundle();
    final Bundle plugins = getPluginsBundle();
    final Bundle core = getCoreBundle();

    api.start();
    plugins.start();
    // fails if LOG4J2-1637 is not fixed
    try {
        core.start();
    }
    catch (final BundleException ex) {
        boolean shouldRethrow = true;
        final Throwable t = ex.getCause();
        if (t != null) {
            final Throwable t2 = t.getCause();
            if (t2 != null) {
                final String cause = t2.toString();
                final boolean result = cause.equals("java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger") // Equinox
                              || cause.equals("java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger not found by org.apache.logging.log4j.core [2]"); // Felix
                Assert.assertFalse("org.apache.logging.log4j package is not properly imported in org.apache.logging.log4j.core bundle, check that the package is exported from api and is not split between api and core", result);
                shouldRethrow = !result;
            }
        }
        if (shouldRethrow) {
            throw ex; // rethrow if the cause of the exception is something else
        }
    }

    core.stop();
    plugins.stop();
    api.stop();
    
    core.uninstall();
    plugins.uninstall();
    api.uninstall();
}
 
Example 7
Source File: InternationalizationServiceSingletonIT.java    From wisdom with Apache License 2.0 5 votes vote down vote up
@Test
public void testManagementOfABundleContainingInternationalizationFiles() throws FileNotFoundException, BundleException {
    Bundle bundle = osgi.installAndStart("local:/i18n",
            bundle()
            .add("i18n/app.properties", new FileInputStream("src/test/resources/integration/app.properties"))
            .add("i18n/app_fr.properties", new FileInputStream("src/test/resources/integration/app_fr.properties"))
            .build());
    bundles.add(bundle);

    Map<String, String> messages = service.getAllMessages(Locale.FRENCH);
    assertThat(messages).contains(
            MapEntry.entry("app.name", "mon application")
    );

    messages = service.getAllMessages(Locale.CHINA);
    assertThat(messages).contains(
            MapEntry.entry("app.name", "my application")
    );

    messages = service.getAllMessages(Locale.ENGLISH);
    assertThat(messages).contains(
            MapEntry.entry("app.name", "my application")
    );

    messages = service.getAllMessages(Locale.GERMAN);
    assertThat(messages).contains(
            MapEntry.entry("app.name", "my application")
    );

    bundle.stop();

    messages = service.getAllMessages(Locale.FRENCH);
    assertThat(messages).doesNotContainKey("app.name");
    messages = service.getAllMessages(Locale.GERMAN);
    assertThat(messages).doesNotContainKey("app.name");
}
 
Example 8
Source File: OSGiEventBridgeIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
private void stopEventingBundle() throws BundleException {
  for (Bundle bundle : bundleContext.getBundles()) {
    if (bundle.getSymbolicName().equals(BUNDLE_SYMBOLIC_NAME)) {
      bundle.stop();
      break;
    }
  }
}
 
Example 9
Source File: FrameworkInformationController.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
@RequestMapping ( value = "/bundles/{id}/stop", method = RequestMethod.POST )
public ModelAndView stopBundle ( @PathVariable ( "id" ) final long bundleId ) throws BundleException
{
    final Bundle bundle = this.context.getBundle ( bundleId );
    if ( bundle != null )
    {
        bundle.stop ();
    }
    return new ModelAndView ( "redirect:/system/info/framework/bundles" );
}
 
Example 10
Source File: ClassPatcherWrappers.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void systemExitWrapper(int code, long bid, Object context) {
  Activator.println("CP.systemExit code=" + code + ", bid=" + bid + ", context=" + context);
  try {
    // NYI, we only handle framework start via Main.
    Bundle b = getBundle(bid);
    Activator.println("stopping " + b);
    b.stop();
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example 11
Source File: Netigso.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void reload(Module m) throws IOException {
    try {
        Bundle b = findBundle(m.getCodeNameBase());
        b.stop();
        fakeOneModule(m, b);
    } catch (BundleException ex) {
        throw new IOException(ex);
    }
}
 
Example 12
Source File: Test1.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public boolean runTest() {

    try {
      Bundle bundle = Util.installBundle(bc, "bundleEnd1_test-1.0.0.jar");
      bundle.start();
      bundle.stop();
      bundle.uninstall();
    } catch (BundleException e) {
      e.printStackTrace();
      return false;
    }
        
    return true;
  }
 
Example 13
Source File: FrameworkTrayIcon.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void shutdown()
{
  try {
    final Bundle systemBundle = Activator.bc.getBundle(0);
    systemBundle.stop();
  } catch (final Exception e) {
    Activator.log.error("Failed to shutdown", e);
  }
}
 
Example 14
Source File: BundleStateResource.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Representation put(final Representation value,
		final Variant variant) {
	try {
		final Bundle bundle = getBundleFromKeys(RestService.BUNDLE_ID_KEY);
		if (bundle == null) {
			setStatus(Status.CLIENT_ERROR_NOT_FOUND);
			return null;
		}

		final BundleStatePojo targetState = fromRepresentation(value,
				value.getMediaType());

		if (bundle.getState() == Bundle.UNINSTALLED) {
			return ERROR(Status.CLIENT_ERROR_PRECONDITION_FAILED, "target state "
					+ targetState.getState() + " not reachable from the current state");
		} else if (targetState.getState() == Bundle.ACTIVE) {
			bundle.start(targetState.getOptions());
			return getRepresentation(
					new BundleStatePojo(bundle.getState()), variant);
		} else if (targetState.getState() == Bundle.RESOLVED) {
			bundle.stop(targetState.getOptions());
			return getRepresentation(
					new BundleStatePojo(bundle.getState()), variant);
		} else {
			return ERROR(Status.CLIENT_ERROR_BAD_REQUEST, "target state "
					+ targetState.getState() + " not supported");
		}
	} catch (final Exception e) {
		return ERROR(e, variant);
	}
}
 
Example 15
Source File: FrameworkNodeImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
public void stopBundle(long id, int options) throws BundleException {
	Bundle b = context.getBundle(id);
	if(b == null)
		return;
	
	b.stop(options);
}
 
Example 16
Source File: FrameworkNodeImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
public void stopBundle(long id) throws BundleException {
	Bundle b = context.getBundle(id);
	if(b == null)
		return;
	
	b.stop();
}
 
Example 17
Source File: AbstractLoadBundleTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
/**
 * Tests starting, then stopping, then restarting, then stopping, and finally uninstalling the API and Core bundles
 */
@Test
public void testApiCoreStartStopStartStop() throws BundleException {

    final Bundle api = getApiBundle();
    final Bundle plugins = getPluginsBundle();
    final Bundle core = getCoreBundle();
    
    Assert.assertEquals("api is not in INSTALLED state", Bundle.INSTALLED, api.getState());
    Assert.assertEquals("plugins is not in INSTALLED state", Bundle.INSTALLED, plugins.getState());
    Assert.assertEquals("core is not in INSTALLED state", Bundle.INSTALLED, core.getState());

    api.start();
    plugins.start();
    core.start();
    
    Assert.assertEquals("api is not in ACTIVE state", Bundle.ACTIVE, api.getState());
    Assert.assertEquals("plugins is not in ACTIVE state", Bundle.ACTIVE, plugins.getState());
    Assert.assertEquals("core is not in ACTIVE state", Bundle.ACTIVE, core.getState());        
    
    core.stop();
    plugins.stop();
    api.stop();
    
    Assert.assertEquals("api is not in RESOLVED state", Bundle.RESOLVED, api.getState());
    Assert.assertEquals("plugins is not in RESOLVED state", Bundle.RESOLVED, plugins.getState());
    Assert.assertEquals("core is not in RESOLVED state", Bundle.RESOLVED, core.getState());

    api.start();
    plugins.start();
    core.start();

    Assert.assertEquals("api is not in ACTIVE state", Bundle.ACTIVE, api.getState());
    Assert.assertEquals("plugins is not in ACTIVE state", Bundle.ACTIVE, plugins.getState());
    Assert.assertEquals("core is not in ACTIVE state", Bundle.ACTIVE, core.getState());

    core.stop();
    plugins.stop();
    api.stop();

    Assert.assertEquals("api is not in RESOLVED state", Bundle.RESOLVED, api.getState());
    Assert.assertEquals("plugins is not in RESOLVED state", Bundle.RESOLVED, plugins.getState());
    Assert.assertEquals("core is not in RESOLVED state", Bundle.RESOLVED, core.getState());
    
    core.uninstall();
    plugins.uninstall();
    api.uninstall();
    
    Assert.assertEquals("api is not in UNINSTALLED state", Bundle.UNINSTALLED, api.getState());
    Assert.assertEquals("plugins is not in UNINSTALLED state", Bundle.UNINSTALLED, plugins.getState());
    Assert.assertEquals("core is not in UNINSTALLED state", Bundle.UNINSTALLED, core.getState());
}
 
Example 18
Source File: InternationalizationServiceSingletonIT.java    From wisdom with Apache License 2.0 4 votes vote down vote up
/**
 * In this test, a first bundle provides the default and french resources, while another one provides the german
 * version.
 */
@Test
public void testWithTwoBundles() throws FileNotFoundException, BundleException {
    Bundle bundle1 = osgi.installAndStart("local:/i18n",
            bundle()
                    .add("i18n/app.properties", new FileInputStream("src/test/resources/integration/app.properties"))
                    .add("i18n/app_fr.properties", new FileInputStream("src/test/resources/integration/app_fr.properties"))
                    .build());
    bundles.add(bundle1);

    Bundle bundle2 = osgi.installAndStart("local:/i18n_de", bundle()
            .add("i18n/app_de.properties", new FileInputStream("src/test/resources/integration/app_de.properties"))
            .build());
    bundles.add(bundle2);

    Map<String, String> messages = service.getAllMessages(Locale.FRENCH);
    assertThat(messages).contains(
            MapEntry.entry("app.name", "mon application")
    );

    messages = service.getAllMessages(Locale.CHINA);
    assertThat(messages).contains(
            MapEntry.entry("app.name", "my application")
    );

    messages = service.getAllMessages(Locale.ENGLISH);
    assertThat(messages).contains(
            MapEntry.entry("app.name", "my application")
    );

    messages = service.getAllMessages(Locale.GERMAN);
    assertThat(messages).contains(
            MapEntry.entry("app.name", "Meine Software")
    );

    bundle1.stop();

    messages = service.getAllMessages(Locale.FRENCH);
    assertThat(messages).doesNotContainKey("app.name");
    messages = service.getAllMessages(Locale.GERMAN);
    assertThat(messages).containsEntry("app.name", "Meine Software");

    bundle2.stop();
    messages = service.getAllMessages(Locale.GERMAN);
    assertThat(messages).doesNotContainEntry("app.name", "Meine Software");
}
 
Example 19
Source File: AbstractLoadBundleTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
private void stop(final Bundle api, final Bundle plugins, final Bundle core, final Bundle dummy) throws BundleException {
    dummy.stop();
    core.stop();
    plugins.stop();
    api.stop();
}
 
Example 20
Source File: UndeployJob.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Undeploys a bundle.
 *
 * @param managedBundle
 *          the bundle to be undeployed.
 * @throws BundleException
 *           bundle exception.
 */
public static void undeployBundle(final Bundle managedBundle) throws BundleException {
  managedBundle.stop(Bundle.STOP_TRANSIENT);
  managedBundle.uninstall();
}