Configuration Admin is a service defined by OSGi that allows deployed bundles to be dynamically configured. The OSGi specification defines the ConfigurationAdmin service as follows:
"The Configuration Admin service is responsible for supplying configuration target bundles with their configuration information. It maintains a database with configuration information, keyed on the service.pid of configuration target services. These services receive their configuration dictionary or dictionaries when they are registered with the Framework. Configurations can be modified or extended using Configuration Plugin services before they reach the target bundle."
The Configuration Admin service is responsible for knowing the various configurations and for notifying target bundles of configuration changes. There are two flavors of target bundle, which are defined by the OSGi specification as follows:
The OSGi specification states that a Managed Service should be registered by a bundle when it create a singleton object that needs to be remotely configured.
ManagedService objects and the
ConfigurationAdmin service.
The OSGi specification defines the ManagedService
interface as follows:
public interface ManagedService {
void updated(Dictionary properties) throws ConfigurationException;
}
A bundle should implement this interface and register a
ManagedService with the OSGi framework. The service will be
notified by the ConfigurationAdmin bundle when the
configuration is created, updated and deleted.
updated(Dictionary) method is called whenever the
configuration is created, updated and deleted. The parameter is the
configuration's properties.
While creating a ManagedService is in principal simple,
consider the following problems that must be addressed:
When a bundle needs to create objects based on varying runtime configuration data, the OSGi specification states that a Managed Service Factory should be used.
ManagedServiceFactory objects and the
ConfigurationAdmin service.
OSGi defines the ManagedServiceFactory interface as
follows:
public interface ManagedServiceFactory {
String getName();
void updated(String pid, Dictionary properties) throws ConfigurationException;
void deleted(String pid);
}
A bundle should implement this interface and register the
ManagedServiceFactory object with the OSGi framework. The
service will be notified by the ConfigurationAdmin bundle
when a configuration is created, updated and deleted.
getName() method simply returns a descriptive name for
the factory.
updated(String, Dictionary) method is called whenever
a configuration is created and updated. The first parameter is
the persistent ID, often referred to as simply the pid,
for the configuration, and the second parameter is the configuration's
properties.
Map, with the persistent ID as the key and the
object created for the configuration as the value.
Map
then the configuration is clearly new, meaning that the factory must
create an object using the properties, and store it in the
Map.
Map then
the configuration is clearly not new, meaning that the factory must
update the associated object in the Map using the
properties. This might mean simply updating the object, or it
might mean creating a brand new object that replaces the existing
one.
deleted(String) method is called whenever one of the
factory's configurations is deleted by ConfigurationAdmin.
The parameter is the persistent ID for the deleted configuration.
Map.
Creating a ManagedServiceFactory as described above is only
really feasible for the simplest cases. In fact, even simple cases can be
complicated to implement. Consider the following problems that must be
addressed:
Implementing a bundle that registers a Managed Service or a Managed
Service Factory can be complicated and error prone. SAT provides support
to make it very easy for a bundle to register a Managed Service or a
Managed Service Factory. This support is provided via two abstract
subclasses of SAT's BaseBundleActivator class, one for
registering a ManagedService and another for registering a
ManagedServiceFactory. In this way, the bundle activator
is the managed service, or, is the managed service factory,
implying that a single bundle may register exactly one
ManagedService, or register exactly one
ManagedServiceFactory.
Rest assured that with a little more effort, SAT supports a single bundle
registering multiple instances of a ManagedService and
multiple instances of a ManagedServiceFactory.
Copyright © 2001, 2007 IBM Corporation and others. All Rights Reserved.