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(); } }
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(); } }