Hi Craig,
Sorry you could not find anything... this is still on our todo lists,
which tend to be overcrowded with tasks ....
But here is a very short howto. Consider you have requirement for some
configuration, say the line length of a pretty printer. You want to have
this configurable through configuration admin.
You need the following parts:
* A service PID identifying the configuration
* A ManagedService to receive the configuration
* Name(s) for the configuration property/ies
The PID is just a string, which must be globally unique. Assuming a
simple case where your PrettyPrinter configurator receives the
configuration has a unique class name, you may well use that name. So
lets assume, our ManagedService is called
org.sample.PrettyPrinterConfigurator and that name is also used as the PID.
The class would be:
package org.sample;
class PrettyPrinterConfigurator implements ManagedService {
public void update(Dictionary props)
throws ConfigurationException {
if (props == null) {
// no configuration from configuration admin
// or old configuration has been deleted
} else {
// apply configuration from config admin
}
}
}
Now, in your bundle activator's start() method you register the
PrettyPrinterConfigurator as a ManagedService:
public void start(BundleContext context) {
Dictionary props = new Hashtable();
props.put("service.pid", org.sample.PrettyPrinterConfigurator);
context.registerService(ManagedService.class.getName(),
new PrettyPrinterConfigurator(), props);
}
That's it ... And so you get the configuration
Hope this helps.
Regards
Felix
Craig Phillips schrieb:
Hi, Good Morning,
I fretted about making such a post until I had somewhat exhausted the
possible ways on my own to grab educational material of some form...
I am looking for exemplary code and/or tutorial based material on how to
use the config admin service and, basically, do configuration of [my]
bundle the proper OSGi prescribed way...
I do have the R4 compendium spec up and it's decent (I really feel like
the folks did a great job on the spec... I have been trying to read
through these, page by page, and they are very well done, IMO); But, the
spec isn't quite a tutorial/hello-world... there was a snippet in there
about the ManagedServiceFactory, but I am looking just to implement a
very simple ManagedService;
I downloaded the felix config admin source code, hoping to find
"trunk/examples" but it only had a few junit-test constructs...
I also googled around a bit for a few hours... I did try out the
'net.luminis.cmc-0.2.1.jar' and it looks quite useful; However, I'm
still trying to put a full thread together with a sample bundle, from a
sample MyBundleConfig.xml and one or two config properties to having the
service load this up and pass it through to my bundle...
Yeah, I could probably just look for a jvm property (e.g.,
-Dmy.config.item="someConfigValue"), but I'd rather try to do it by way
of the prescribed OSGi configuration paradigm a la configAdmin
service...
If someone has a sample code snippet or two, or maybe a little cheat
sheet or something, I'd be greatly appreciative (as always, this is a
great felix and osgi resource here, and the people are very helpful)...
Sincerely, Craig Phillips, Praxis