예제 #1
0
 public void refreshPackages(long[] bids) {
   if (bids.length == 0) {
     ((PackageAdmin) pkgTracker.getService()).refreshPackages(null);
     bids = null;
   } else {
     Bundle[] bl = new Bundle[bids.length];
     for (int i = 0; i < bids.length; i++) {
       bl[i] = Activator.bc.getBundle(bids[i]);
     }
     ((PackageAdmin) pkgTracker.getService()).refreshPackages(bl);
   }
 }
예제 #2
0
  void handleServiceListenerUnreg(Collection /* <ServiceListenerEntry> */ set) {
    if (!isOpen() || listenerHookTracker.size() == 0) {
      return;
    }
    ServiceReference[] srl = listenerHookTracker.getServiceReferences();

    for (int i = 0; srl != null && i < srl.length; i++) {
      ListenerHook lh = (ListenerHook) listenerHookTracker.getService(srl[i]);
      try {
        lh.removed(set);
      } catch (Exception e) {
        fwCtx.debug.printStackTrace(
            "Failed to call listener hook #" + srl[i].getProperty(Constants.SERVICE_ID), e);
      }
    }
  }
예제 #3
0
  public Map getExportedPackage(String name) {
    Map map = new HashMap();
    ExportedPackage pkg = ((PackageAdmin) pkgTracker.getService()).getExportedPackage(name);

    putExportPackage(map, pkg);
    return map;
  }
  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();
  }
예제 #5
0
  public Map[] getExportedPackages(long bid) {
    Bundle b = -1 == bid ? null : Activator.bc.getBundle(bid);
    ExportedPackage[] pkgs = ((PackageAdmin) pkgTracker.getService()).getExportedPackages(b);

    if (pkgs == null) {
      return new Map[0];
    }

    Map[] maps = new Map[pkgs.length];
    for (int i = 0; i < pkgs.length; i++) {
      maps[i] = new HashMap();
      putExportPackage(maps[i], pkgs[i]);
    }
    return maps;
  }
예제 #6
0
  public void stop() {
    if (reaper != null) {
      bReap = false;
      try {
        reaper.wait(1000);
      } catch (Exception ignored) {
      }
      reaper = null;
    }
    if (reg != null) {
      reg.unregister();
      reg = null;

      slTracker.close();
    }
  }
예제 #7
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;
  }
예제 #8
0
  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();
    }
  }
예제 #9
0
 public int getStartLevel() {
   return ((StartLevel) slTracker.getService()).getStartLevel();
 }
예제 #10
0
 public boolean isBundlePersistentlyStarted(long bid) {
   Bundle b = Activator.bc.getBundle(bid);
   return ((StartLevel) slTracker.getService()).isBundlePersistentlyStarted(b);
 }
예제 #11
0
 public int getInitialBundleStartLevel() {
   return ((StartLevel) slTracker.getService()).getInitialBundleStartLevel();
 }
예제 #12
0
 public void setInitialBundleStartLevel(int level) {
   ((StartLevel) slTracker.getService()).setInitialBundleStartLevel(level);
 }
예제 #13
0
 public int getBundleStartLevel(long bid) {
   Bundle b = Activator.bc.getBundle(bid);
   return ((StartLevel) slTracker.getService()).getBundleStartLevel(b);
 }
예제 #14
0
 public void setBundleStartLevel(long bid, int level) {
   Bundle b = Activator.bc.getBundle(bid);
   ((StartLevel) slTracker.getService()).setBundleStartLevel(b, level);
 }
예제 #15
0
 public void setStartLevel(int level) {
   ((StartLevel) slTracker.getService()).setStartLevel(level);
 }
예제 #16
0
  synchronized void close() {
    listenerHookTracker.close();
    listenerHookTracker = null;

    bOpen = false;
  }
예제 #17
0
 public boolean isBundleActivationPolicyUsed(long bid) {
   Bundle b = Activator.bc.getBundle(bid);
   return ((StartLevel) slTracker.getService()).isBundleActivationPolicyUsed(b);
 }