Java Reference
In-Depth Information
throw new ConfigurationException(null, "Property missing");
}
int port;
try {
port = Integer.parseInt(portString);
} catch (NumberFormatException ex) {
throw new ConfigurationException(null,"Not a valid port number");
}
try {
server = new EchoServer(port);
server.start();
m_servers.put(pid, server);
} catch (IOException e) {
e.printStackTrace();
}
}
}
...
}
This example isn't significantly different from the last one. You now implement the
ManagedServiceFactory interface. Because you're going to manage a number of serv-
ers, you introduce a map to hold them. The factory interface defines two new meth-
ods, deleted() and getName() . The latter is a descriptive name for the factory, and
the former notifies your factory that a previously updated configuration has gone
away, which results in you stopping the corresponding server. Notice that the
updated() method has a different signature from the ManagedService interface B . It
now accepts a PID , which is necessary because your managed service factory needs to
know the PID for the supplied configuration; it correlates the PID with a specific echo
server. For each one, you need a PID and a configuration. The rest is similar to what
you did for a single server in the ManagedService example. The only exception is that
now you must add the resulting server instance to your list of servers C .
This covers the basics of what you need to do to make your bundles configurable.
Now we need to look into how you configure bundles by creating configurations.
C
Adds server instance
to server list
CREATING CONFIGURATIONS
It's one thing to make your bundles configurable, but you need some way to specify
and set the property values you want to use to configure them. You need to learn how
to create and manage configurations; you use the Configuration Admin Service for
this. It provides methods to maintain configuration data by means of Configuration
objects associated with specific configuration targets that can be created, listed, modi-
fied, and deleted. The ConfigurationAdmin service interface is defined as follows:
public interface ConfigurationAdmin{
public Configuration createFactoryConfiguration(String factoryPid)
throws IOException;
public Configuration createFactoryConfiguration(String factoryPid,
String location) throws IOException;
public Configuration getConfiguration(String pid, String location)
throws IOException;
Search WWH ::




Custom Search