mr.shutdown(); mr = null;
public void stop(BundleContext context) throws Exception { // When OSGi framework shuts down, it shuts down all started bundles, but the order is unspecified. // So, since we are going to shutdown the registry, it's better that we stop startup service just incase it is still running. // Similarly, we can release the habitat. // Execute code in reverse order w.r.t. start() for (HabitatInfo habitatInfo : habitatInfos.values()) { ModuleStartup startupService = habitatInfo.habitat.getComponent(ModuleStartup.class, habitatInfo.habitat.DEFAULT_NAME); if (startupService != null) { try { logger.info("Stopping " + startupService); startupService.stop(); } catch (Exception e) { logger.log(Level.WARNING, "HK2Main:stop():Exception while stopping ModuleStartup service.", e); } } destroyHabitat(habitatInfo.habitat); } ModulesRegistry mr = (ModulesRegistry) ctx.getService(mrReg.getReference()); if (mr != null) { mr.shutdown(); mr = null; } // ctx.removeBundleListener(this); // used for debugging only. see start method }