l e m m s t e r . d e
  • Home
  • impressum
  • talks
  • Categories
  • Tags
  • Archives

Programatically push configuration into OSGi ConfigurationAdmin

Yesterday I lost half an hour when I struggled to push a configuration into OSGi ConfigurationAdmin. The org.osgi.service.cm.ManagedService was in fact called, but the Dictionary of properties was always null. It turns out, I forgot that one has to lookup the org.osgi.service.cm.Configuration not just by service PID, but also by (bundle) location. And since the location was not matching, the configuration was not a valid config for the bundle that implements the ManagedService. Below is how one correctly configures the ManagedService registered with PID “my.ManagedService.Service.Pid” (service.pid). Notice the “?” location wildcard!

String servicePID = "my.ManagedService.Service.Pid";
Configuration configuration = 
    cm.getConfiguration(servicePID, <strong><span style="color: #ff0000;">"?"</span></strong>);
Dictionary<String, Object> properties = 
    configuration.getProperties();
if (properties == null) {
    properties = new Hashtable<String, Object>();
}
properties.put("someKey", "someValue");
configuration.update(properties);

Published

Oct 23, 2013

Category

eclipse

Contact

  • Powered by Pelican. Theme: Elegant