public CMDisplayer(BundleContext bc) {
    super(bc, "CM", "Config Admin", true);
    bUseListeners = true;

    if (infoIcon == null) {
      infoIcon = new ImageIcon(getClass().getResource("/info16x16.png"));
    }
    cmTracker = new ServiceTracker(bc, ConfigurationAdmin.class.getName(), null);
    cmTracker.open();
  }
示例#2
0
  synchronized void open() {
    if (fwCtx.debug.hooks) {
      fwCtx.debug.println("opening hooks");
    }

    listenerHookTracker =
        new ServiceTracker(
            fwCtx.systemBundle.bundleContext,
            ListenerHook.class.getName(),
            new ServiceTrackerCustomizer() {
              public Object addingService(ServiceReference reference) {
                ListenerHook lh =
                    (ListenerHook) fwCtx.systemBundle.bundleContext.getService(reference);
                try {
                  lh.added(getServiceCollection());
                } catch (Exception e) {
                  fwCtx.debug.printStackTrace(
                      "Failed to call listener hook  #"
                          + reference.getProperty(Constants.SERVICE_ID),
                      e);
                }
                return lh;
              }

              public void modifiedService(ServiceReference reference, Object service) {
                // noop
              }

              public void removedService(ServiceReference reference, Object service) {
                fwCtx.systemBundle.bundleContext.ungetService(reference);
              }
            });

    listenerHookTracker.open();

    bOpen = true;
  }
  public void start() {
    if (reg == null) {

      slTracker = new ServiceTracker(Activator.bc, StartLevel.class.getName(), null);
      slTracker.open();

      pkgTracker = new ServiceTracker(Activator.bc, PackageAdmin.class.getName(), null);
      pkgTracker.open();

      Hashtable props = new Hashtable();

      props.put("SOAP.service.name", "OSGiFramework");

      reg = Activator.bc.registerService(RemoteFW.class.getName(), this, props);

      Activator.bc.addBundleListener(
          new BundleListener() {
            public void bundleChanged(BundleEvent event) {
              synchronized (bundleEvents) {
                bundleEvents.add(event);
              }
            }
          });
      Activator.bc.addServiceListener(
          new ServiceListener() {
            public void serviceChanged(ServiceEvent event) {
              synchronized (serviceEvents) {
                serviceEvents.add(event);
              }
            }
          });
      Activator.bc.addFrameworkListener(
          new FrameworkListener() {
            public void frameworkEvent(FrameworkEvent ev) {
              synchronized (frameworkEvents) {
                int type = ev.getType();
                Bundle b = ev.getBundle();
                if (b == null) {
                  Object obj = ev.getSource();
                  if (bDebug) {
                    System.out.println("obj=" + obj);
                    if (obj != null) {
                      System.out.println("source class=" + obj.getClass().getName());
                    }
                  }
                  if (obj != null && (obj instanceof Bundle)) {
                    b = (Bundle) obj;
                  }
                }
                if (bDebug) {

                  System.out.println(
                      "server: add fw event: " + ev + ", type=" + type + ", bundle=" + b);
                }
                if (b != null) {
                  frameworkEvents.add(new FrameworkEvent(type, b, null));
                }
              }
            }
          });

      reaper =
          new Thread() {
            public void run() {
              while (bReap) {
                try {
                  reapEvents();
                  Thread.sleep(reapDelay);
                } catch (Exception e) {

                }
              }
            }
          };

      bReap = true;
      reaper.start();
    }
  }