You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Craig Phillips <lc...@praxiseng.com> on 2008/07/10 14:33:08 UTC

ConfigAdmin - examples / tutorials

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

 

 


RE: ConfigAdmin - examples / tutorials

Posted by Craig Phillips <lc...@praxiseng.com>.
Hi,

I'm about to grab and peruse the source for the Pax logging and see what
I can find... I sort of attempted from scratch to set up a bundle that
implements cm.ManagedService... The updated() method is being invoked
twice with a null argument for Dictionary...

One thing I forgot to mention - I prefer to use
SCR/DeclarativeServices... I think the invocation of the updated()
method being done twice has something to do with DeclarativeServices
setting up my bundle to already provide ManagedService in some manner to
be determined... 

I tried using the 'net.luminis.cmc-0.2.1.jar' shell to play around, but
to no avail, in that it kept giving me some kind of ERROR message about
configuration being "already delivered" and, hence, my updated() method
was never subsequently invoked, unless I manually deleted the service
(go figure)...

So, sigh... I guess it's on to figuring out how pax does it...  thanks
for the tip, Craig

-----Original Message-----
From: Alin Dreghiciu [mailto:adreghiciu@gmail.com] 
Sent: Thursday, July 10, 2008 8:48 AM
To: dev@felix.apache.org
Subject: Re: ConfigAdmin - examples / tutorials

If you want some examples you can check out code from OPS4j Pax such
as Pax Logging for example and search for ManagedService. Pretty much
all Pax stuff can be configured via Configuration admin so you can
find more examples in pax runner / web / ...
For an example of ManagedServiceFactory you can look into code of Pax
Coin (FileSystemResourceScannerFactory).



Re: ConfigAdmin - examples / tutorials

Posted by Alin Dreghiciu <ad...@gmail.com>.
If you want some examples you can check out code from OPS4j Pax such
as Pax Logging for example and search for ManagedService. Pretty much
all Pax stuff can be configured via Configuration admin so you can
find more examples in pax runner / web / ...
For an example of ManagedServiceFactory you can look into code of Pax
Coin (FileSystemResourceScannerFactory).

On Thu, Jul 10, 2008 at 2:33 PM, Craig Phillips
<lc...@praxiseng.com> wrote:
> 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
>
>
>
>
>
>



-- 
Alin Dreghiciu
http://www.ops4j.org         - New Energy for OSS Communities - Open
Participation Software.
http://www.qi4j.org            - New Energy for Java - Domain Driven
Development.
http://malaysia.jayway.net - New Energy for Projects - Great People
working on Great Projects at Great Places

Re: ConfigAdmin - examples / tutorials

Posted by Pedro Pedruzzi <pp...@v2com.mobi>.
Hi Craig, good morning.

I don't know it this is what you're expecting.

Felix's Web Console registers a simple ManagedService:

org.apache.felix.webconsole.internal.servlet.ConfigurationListener

Regards,

-- 
Pedro Pedruzzi | V2COM


On Thu, Jul 10, 2008 at 9:33 AM, Craig Phillips
<lc...@praxiseng.com> wrote:
> 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
>
>
>
>
>
>

Re: ConfigAdmin - examples / tutorials

Posted by Felix Meschberger <fm...@gmail.com>.
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
> 
>  
> 
>  
> 
>