--- import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.util.tracker.ServiceTracker; import org.osgi.framework.ServiceReference; public class MyBundleActivator implements BundleActivator { private ServiceTracker<MyServiceInterface, MyServiceInterface> tracker; public void start(BundleContext context) { tracker = new ServiceTracker<MyServiceInterface, MyServiceInterface>(context, MyServiceInterface.class, null) { public MyServiceInterface addingService(ServiceReference<MyServiceInterface> ref) { MyServiceInterface service = (MyServiceInterface) context.getService(ref); return service; } public void removedService(ServiceReference<MyServiceInterface> ref, MyServiceInterface service) { context.ungetService(ref); } }; tracker.open(); } public void stop(BundleContext context) { tracker.close(); } } import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; public class ConfigurationHandler { private ConfigurationAdmin configAdmin; public void updateTrackerConfiguration(String serviceFilter) throws IOException { Configuration config = configAdmin.getConfiguration("my.tracker.config"); Dictionary<String, Object> properties = config.getProperties(); properties.put("service.filter", serviceFilter); config.update(properties); } }


上一篇:
下一篇:
切换中文