Java Reference
In-Depth Information
The remove-factory-cfg subcommand allows you to remove a factory configura-
tion. It's implemented as follows:
private void removeFactoryConfiguration(String pid) {
Configuration[] configurations = admin.listConfigurations(
"(service.pid=" + pid + ")");
configurations[0].delete();
}
The subcommand accepts a PID that you use to find the associated configuration using
listConfigurations() with a filter. When you have it, you call delete() on it as before.
To experiment with this new command, go into the chapter09/combined-example/
directory of the companion code. Type ant to build the example and java
-jar launcher.jar bundles to execute it. To interact with the shell, use telnet local-
host 7070 . This example uses the Apache Felix Configuration Admin implementation
( http://felix.apache.org/site/apache-felix-configuration-admin-service.html ) . Here's
a session using the cm command:
-> cm add-cfg org.foo.managed.service port=6251
-> cm add-factory-cfg org.foo.managed.factory port=6252
-> cm list
service.pid=org.foo.managed.service
port=6251
service.pid=org.foo.managed.factory.89706c08-3902-4f4d-87f5-7da5a504cb94
port=6252
service.factoryPid=org.foo.managed.factory
-> cm remove-cfg org.foo.managed.service
-> cm remove-factory-cfg
[CA]org.foo.managed.factory.89706c08-3902-4f4d-87f5-7da5a504cb94
-> cm list
->
This session creates configurations for your managed service and managed service fac-
tory. As you should be aware now, the result of these two commands is subtly different.
The first directly configures the service associated with the PID , whereas the latter
causes a service to be created from the managed service factory. For the combined
example, if you go to another operating system shell after performing the first two
steps, you can telnet into your configured echo servers using the specified port num-
bers. Finally, you remove the configurations.
That finishes our quick tour of the Configuration Admin Service. You should now
be able to use Configuration Admin to create externally configurable bundles, instan-
tiate services using configurations, and manage configurations. But wait, how do you
know what kind of data your configurable bundles accept? All we've said so far is that
managed services are configured with simple name-value pairs. Sometimes that may
suffice, but often you may want to tell other bundles or entities, such as a user, about
the structure of your bundle's configuration data. The Metatype Service, which we'll
introduce next, allows you to define your own metatypes and associate them with your
bundles and services.
 
Search WWH ::




Custom Search