Configuration Admin

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:

Managed Service

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.

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.

While creating a ManagedService is in principal simple, consider the following problems that must be addressed:

Managed Service Factory

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.

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.

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:

How Does SAT Help?

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.