Java Reference
In-Depth Information
Configuration Admin
Bundle developer
writes a bundle
Configuration date
port=?
secure=?
port=4711
secure=true
Bundle is deployed
Figure 9.4
An administrator configures a bundle in the framework by interacting with the
Configuration Admin Service. This approach decouples the administrator from having to
know the internal workings of the bundle using the configuration data.
How does this work? The Configuration Admin Service maintains a database of
Con-
figuration
objects, each of which has an associated set of name-value pair properties.
The Configuration Admin Service follows the whiteboard pattern and monitors the
service registry for two different managed services:
ManagedService
and
Managed-
ServiceFactory
. If you have a bundle that needs configuration data, it must register
one of these two services defined in the Configuration Admin specification. The dif-
ference between these two is that a
ManagedService
accepts one configuration to con-
figure a single service, whereas a
ManagedServiceFactory
accepts any number of
configurations and configures a different service instance for each configuration; fig-
ure 9.5 illustrates this difference.
When you're registering one of these managed services, you need to attach a
service.pid
(service persistent identity) service property to it. Each managed
Config-
uration
object also has a
service.pid
associated with it, which the Configuration
Admin Service uses as a key to match configuration data to the bundle needing it.
You may have noticed you're dealing with two conceptually different layers when
using the Configuration Admin Service. On one layer, you have a published
Managed-
Service
or
ManagedServiceFactory
service. On the other layer, you have a bundle and
the services it provides that you want to configure. The Configuration Admin Service
What is a PID?
In a nutshell, you can associate a persistent identity, or PID, with each registered ser-
vice by specifying it in the service property dictionary when you register its managed
service. If you specify a
service.pid
property, it must be unique for each service.
Its purpose is to uniquely and persistently identify a given service, which allows the
Configuration Admin Service to use it as a primary key for bundles needing configu-
ration data. This means the Configuration Admin Service requires the use of a PID
with
ManagedService
and
ManagedServiceFactory
service registrations. As a con-
vention, PIDs starting with a bundle identifier and a dot are reserved for the bundle
associated with that identifier. For example, the PID
42.4711
belongs to the bundle
associated with bundle identifier 42. You're free to use other schemes for your PIDs;
just make sure they're unique and persistent across bundle activations.