BUG Community

Welcome! Log In

Forums BUG SDK Using Configuration Admin

Subscribe to Using Configuration Admin  1 post, 1 voice

  • Voices:
  • akravets

Log in to reply to this topic
 
Feb 1, 2008 5:11pm
Img_missing_medium akravets 25 posts

Sometimes there is a need to persist state of BUG between launches, this can be achieved using OSGi's Configuration Admin (CM). There is an implementation of CM provided by com.buglabs.osgi.cm that can be obtained from CVS and is available in SDK. Also test cases are available in com.buglabs.osgi.cm.tests

Bellow is short how-to on how to use CM:

Configuration Admin HOW-TO:

Upon unregistering a bundle from the OSGi Framework all configuration data that might have been set to define its state is gone. To relieve user of pains of reconfiguring the bundle
once its active, Configuration Admin can be used to persist configuration data so that upon the bundle's being active again its states can be set to those when they were before bundle was
unregistered.


Get Configuration Admin Service:

ServiceReference serviceReference = context.getServiceReference(ConfigurationAdmin.class.getName());
ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getService(serviceReference);


or use a ServiceTracker in order to know when service will be available.


Get the Configuration:
Each Configuration contains a Dictionary that holds properties for service of interest, to initiate a new store or retrieve an existing one:

Configuration config = configAdmin.getConfiguration("com.buglabs.someService");


Retrieve properties for the service:
Dictionary properties = config.getProperties();


Update service with properties:

Dictionary prop = new Hashtable();
prop.put("enabled", new Boolean(true));


Refer to section 10.4.2 of OSGi R3 specifications for valid types that can be used in Dictionary.


config.update(properties);


Configuration's properties can also be cleared by executing config.update(null); This will clear all properties for this Configuration but leave Constants.SERVICE_PID intact since it identified id for this Configuration.


Complete specifications for OSGi including CM can be downloaded from http://www2.osgi.org/Specifications/HomePage.
Log in to reply to this topic