void removeInitListeners() { BundleContext context = createBundleContext(false); for (FrameworkListener initListener : initListeners) { context.removeFrameworkListener(initListener); } initListeners.clear(); }
@Test public void testFrameworkListener() throws Exception { Bundle bundle = installBundle(getBundleArchiveA()); try { bundle.start(); BundleContext bundleContext = bundle.getBundleContext(); assertNotNull(bundleContext); try { bundleContext.addFrameworkListener(null); fail("Should not be here!"); } catch (IllegalArgumentException t) { // expected } try { bundleContext.removeFrameworkListener(null); fail("Should not be here!"); } catch (IllegalArgumentException t) { // expected } // todo test events } finally { bundle.uninstall(); } }
/** @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext bundleContext) { // shut down the trackers. m_eventAdmin.destroy(); // Clean up the listeners. bundleContext.removeBundleListener(m_frameworkHandler); bundleContext.removeFrameworkListener(m_frameworkHandler); bundleContext.removeServiceListener(m_frameworkHandler); // Remove the global handler for all JDK Logging (java.util.logging). if (m_JdkHandler != null) { Logger rootLogger = LogManager.getLogManager().getLogger(""); rootLogger.removeHandler(m_JdkHandler); m_JdkHandler.flush(); m_JdkHandler.close(); m_JdkHandler = null; } m_RegistrationPaxLogging.unregister(); m_RegistrationPaxLogging = null; m_registrationLogReaderService.unregister(); m_registrationLogReaderService = null; m_paxLogging.stop(); m_paxLogging = null; }
@Override public void frameworkEvent(FrameworkEvent frameworkEvent) { if (frameworkEvent.getType() != FrameworkEvent.PACKAGES_REFRESHED) { return; } for (Bundle bundle : _startBundles) { try { startBundle(bundle, 0, false); } catch (Exception e) { _log.error(e, e); } } for (Bundle bundle : _lazyActivationBundles) { try { startBundle(bundle, Bundle.START_ACTIVATION_POLICY, false); } catch (Exception e) { _log.error(e, e); } } try { Bundle bundle = frameworkEvent.getBundle(); BundleContext bundleContext = bundle.getBundleContext(); bundleContext.removeFrameworkListener(this); } catch (Exception e) { _log.error(e, e); } }
@Override protected void doStop() { bundleContext.removeFrameworkListener(this); try { super.doStop(); } finally { context.destroy(); } }
@Override protected void doStop() throws Exception { bundleContext.removeFrameworkListener(this); super.doStop(); context.destroy(); }
/** * Refreshes all exported packages of the given bundles. This must be called after installing the * bundle. * * @param bundles Bundles which exported packages are to be refreshed. */ @SuppressWarnings("restriction") void refreshPackages(Bundle[] bundles) { BundleContext context = AcceleoCommonPlugin.getDefault().getContext(); ServiceReference packageAdminReference = context.getServiceReference(PackageAdmin.class.getName()); PackageAdmin packageAdmin = null; if (packageAdminReference != null) { packageAdmin = (PackageAdmin) context.getService(packageAdminReference); } if (packageAdmin != null) { final boolean[] flag = new boolean[] { false, }; FrameworkListener listener = new FrameworkListener() { public void frameworkEvent(FrameworkEvent event) { if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) { synchronized (flag) { flag[0] = true; flag.notifyAll(); } } } }; /* * Hack-ish : Make sure the contributions from this bundle won't be parsed. When installing a * bundle, the EclipseBundleListener will _always_ parse the plugin.xml and notify the extension * registry (and its listeners) of the new contributions. Problem is : some bundles listen to new * contributions, but ignore the event of contribution removals (when we uninstall the bundle). We * would thus end with "invalid registry object" exceptions thrown ... with no way to prevent or * fix them whatsoever. Equinox does not provide us with an API to disable the contributions from * the bundle we're installing, temporarily disable the extension listeners... or any other way to * workaround this registry issue. We'll then make use of the fact that the EclipseBundleListener * does not add contributions from a contributor which has already been added: we'll add the * contributor beforehand with an empty plugin.xml, disabling all potential contributions this * bundle would have made otherwise. */ if (bundles != null && Platform.getExtensionRegistry() instanceof IDynamicExtensionRegistry) { IExtensionRegistry registry = Platform.getExtensionRegistry(); for (Bundle bundle : bundles) { IContributor contributor = ContributorFactoryOSGi.createContributor(bundle); if (!((IDynamicExtensionRegistry) registry).hasContributor(contributor)) { registry.addContribution( new ByteArrayInputStream(EMPTY_PLUGIN_XML.getBytes()), contributor, false, null, null, ((ExtensionRegistry) registry).getTemporaryUserToken()); } } } context.addFrameworkListener(listener); packageAdmin.refreshPackages(bundles); synchronized (flag) { while (!flag[0]) { try { flag.wait(OSGI_TIMEOUT); } catch (InterruptedException e) { // discard break; } } } context.removeFrameworkListener(listener); if (packageAdminReference != null) { context.ungetService(packageAdminReference); } } }
public void stop(BundleContext context) { context.removeFrameworkListener(this); }
public void removeFrameworkListener(FrameworkListener listener) { delegate.removeFrameworkListener(listener); }