Each of these service instances is represented, in the persistent
storage of the Configuration Admin service, by a factory
Configuration
object that has a PID. When such a
Configuration
is updated, the Configuration Admin service calls the
ManagedServiceFactory
updated method with the new properties. When
updated
is called with a new PID, the Managed Service Factory should
create a new factory instance based on these configuration properties. When
called with a PID that it has seen before, it should update that existing
service instance with the new configuration information.
In general it is expected that the implementation of this interface will
maintain a data structure that maps PIDs to the factory instances that it has
created. The semantics of a factory instance are defined by the Managed
Service Factory. However, if the factory instance is registered as a service
object with the service registry, its PID should match the PID of the
corresponding Configuration
object (but it should not be
registered as a Managed Service!).
An example that demonstrates the use of a factory. It will create serial ports under command of the Configuration Admin service.
class SerialPortFactory implements ManagedServiceFactory { ServiceRegistration registration; Hashtable ports; void start(BundleContext context) { Hashtable properties = new Hashtable(); properties.put( Constants.SERVICE_PID, "com.acme.serialportfactory" ); registration = context.registerService( ManagedServiceFactory.class.getName(), this, properties ); } public void updated( String pid, Dictionary properties ) { String portName = (String) properties.get("port"); SerialPortService port = (SerialPort) ports.get( pid ); if ( port == null ) { port = new SerialPortService(); ports.put( pid, port ); port.open(); } if ( port.getPortName().equals(portName) ) return; port.setPortName( portName ); } public void deleted( String pid ) { SerialPortService port = (SerialPort) ports.get( pid ); port.close(); ports.remove( pid ); } ... }
If a ManagedServiceFactory
is registered without the service.pid
property, it will be ignored.
Modifier and Type | Method and Description |
---|---|
public void | |
public String | Returns: the name for the factory, which might be localizedReturn a descriptive name of this factory. |
public void | updated(String
The PID for this configuration. pid, Dictionary<String, ?> A copy of the configuration properties. This argument
must not contain the service.bundleLocation" property. The value
of this property may be obtained from the
properties)Configuration.getBundleLocation method.Create a new instance, or update the configuration of an existing instance. |
deleted | back to summary |
---|---|
public void deleted(String pid) Remove a factory instance.
Remove the factory instance associated with the PID. If the instance was
registered with the service registry, it should be unregistered. The
Configuration Admin must call deleted for each instance it received in
If this method throws any The Configuration Admin service must call this method asynchronously.
|
getName | back to summary |
---|---|
public String getName() Return a descriptive name of this factory.
|
updated | back to summary |
---|---|
public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException Create a new instance, or update the configuration of an existing
instance.
If the PID of the
If the factory instance is registered with the Framework, then the
configuration
If this method throws any
When the implementation of updated detects any kind of error in the
configuration properties, it should create a new
The Configuration Admin service must call this method asynchronously.
This implies that implementors of the If the security allows multiple managed service factories to be called back for a single configuration then the callbacks must occur in service ranking order.
It is valid to create multiple factory instances that are bound to
different locations. Managed Service Factory services must only be
updated with configurations that are bound to their location or that
start with the
|