Using Configuration Admin

 
Post new topic   Reply to topic    Bug Labs Forum Index -> BUG SDK
View previous topic :: View next topic  
Author Message
akravets



Joined: 25 Sep 2007
Posts: 25
Location: New York

PostPosted: Fri Feb 01, 2008 5:11 pm    Post subject: Using Configuration Admin Reply with quote

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:
Code:

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:
Code:
   
Configuration config = configAdmin.getConfiguration("com.buglabs.someService");


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



Update service with properties:
Code:

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.

Code:

config.update(properties);


Configuration's properties can also be cleared by executing
Code:
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.
_________________
Alex Kravets
Software Engineering, Bug Labs
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Bug Labs Forum Index -> BUG SDK All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

FAQ   |   Search   |   Memberlist   |   Usergroups   |   Register   |   Profile

Email forums administrator

Bannersmonster.Com © 2007
Powered by phpBB © 2001, 2002 phpBB Group
Designed by:linux hostingHotel