/** @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;
  }
  public void stop(BundleContext bundleContext) throws Exception {
    runnablePrinterClient.stop();
    if (serviceReference != null) {
      bundleContext.ungetService(serviceReference);
    }

    bundleContext.removeServiceListener(this);
  }
  @Override
  public void stop(final BundleContext context) throws Exception {
    jndiManager.unExport(KILLBILL_OSGI_JDBC_JNDI_NAME);

    this.context = null;
    context.removeServiceListener(this);
    observable.unregister();
    registrar.unregisterAll();
  }
  /**
   * Removes a service listener from the given bundle context. This method simply takes care of any
   * exceptions that might be thrown (in case the context is invalid).
   *
   * @param context bundle context to unregister the listener from
   * @param listener service listener to unregister
   * @return true if the listener unregistration has succeeded, false otherwise (for example if the
   *     bundle context is invalid)
   */
  public static boolean removeServiceListener(BundleContext context, ServiceListener listener) {
    if (context == null || listener == null) return false;

    try {
      context.removeServiceListener(listener);
      return true;
    } catch (IllegalStateException e) {
      // Bundle context is no longer valid
    }

    return false;
  }
Esempio n. 5
0
  public void close() {
    if (open.compareAndSet(true, false)) {
      ctx.removeServiceListener(listener);

      List<ServiceReference> oldRefs;
      synchronized (refs) {
        oldRefs = new ArrayList<ServiceReference>(refs.keySet());
        refs.clear();
      }
      for (ServiceReference ref : oldRefs) {
        ctx.ungetService(ref);
      }
    }
  }
  @Test
  public void testServiceListener() throws Exception {
    Bundle bundle = installBundle(getBundleArchiveA());
    try {
      bundle.start();
      BundleContext bundleContext = bundle.getBundleContext();
      assertNotNull(bundleContext);

      try {
        bundleContext.addServiceListener(null);
        fail("Should not be here!");
      } catch (IllegalArgumentException t) {
        // expected
      }

      try {
        bundleContext.addServiceListener(null, "(a=b)");
        fail("Should not be here!");
      } catch (IllegalArgumentException t) {
        // expected
      }

      try {
        bundleContext.removeServiceListener(null);
        fail("Should not be here!");
      } catch (IllegalArgumentException t) {
        // expected
      }

      bundleContext.addServiceListener(this);
      bundleContext = assertServiceLifecycle(bundle, true);
      bundleContext.removeServiceListener(this);

      bundleContext.addServiceListener(this);
      bundleContext.removeServiceListener(this);
      bundleContext = assertServiceLifecycle(bundle, false);

      bundleContext.addServiceListener(this);
      bundleContext.addServiceListener(this);
      bundleContext = assertServiceLifecycle(bundle, true);
      bundleContext.removeServiceListener(this);

      bundleContext.addServiceListener(this, null);
      bundleContext = assertServiceLifecycle(bundle, true);
      bundleContext.removeServiceListener(this);

      bundleContext.addServiceListener(this, null);
      bundleContext.removeServiceListener(this);
      bundleContext = assertServiceLifecycle(bundle, false);

      bundleContext.addServiceListener(this, null);
      bundleContext.addServiceListener(this, null);
      bundleContext = assertServiceLifecycle(bundle, true);
      bundleContext.removeServiceListener(this);

      Dictionary<String, Object> properties = new Hashtable<String, Object>();
      properties.put("a", "b");

      bundleContext.addServiceListener(this, ("(a=b)"));
      bundleContext = assertServiceLifecycle(bundle, properties, true);
      bundleContext.removeServiceListener(this);

      bundleContext.addServiceListener(this, ("(c=d)"));
      bundleContext = assertServiceLifecycle(bundle, properties, false);
      bundleContext.removeServiceListener(this);

      bundleContext.addServiceListener(this, "(a=b)");
      bundleContext.removeServiceListener(this);
      bundleContext = assertServiceLifecycle(bundle, properties, false);

      bundleContext.addServiceListener(this, "(c=d)");
      bundleContext.addServiceListener(this, "(a=b)");
      bundleContext = assertServiceLifecycle(bundle, properties, true);
      bundleContext.removeServiceListener(this);
    } finally {
      bundle.uninstall();
    }
  }
Esempio n. 7
0
 @Override
 public void stop(BundleContext context) {
   context.removeServiceListener(this);
   System.out.println("Stopped listening for service events.");
 }
Esempio n. 8
0
 @Override
 public void stop(BundleContext context) throws Exception {
   context.removeServiceListener(listener);
 }
Esempio n. 9
0
 public void stop(BundleContext context) {
   context.removeServiceListener(this);
 }
 public void removeServiceListener(ServiceListener listener) {
   delegate.removeServiceListener(listener);
 }
 public void destroy() {
   context.removeServiceListener(this);
   eventListeners.removeAllElements();
 }