Apache
Home » Documentation » Apache Felix Subproject Documentation » Apache Felix Dependency Manager

Dependency Manager - Factory Configuration Adapter Service

A factory configuration adapter service creates an adapter for each matching configuration in Configuration Admin. For each new factory configuration matching the factoryPid, an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface and with the specified adapter service properties. Depending on the propagate parameter, every public factory configuration properties (which don't start with ".") will be propagated along with the adapter service properties. It will also inherit all dependencies.

To define an adapter component, you need to create an FactoryComponent component using the DependencyActivatorBase.createFactoryComponent() or the DependencyManager.createFactoryComponent() method. The FactoryComponent interface extends the Component interface in order to add extra setters methods needed to define a factory configuration adapter service component.

Example usage:

Here is a sample showing a "MyComponent" component, which can be instantiated multiple times using a factory configuration:

public interface MyConfig {
    int getPort();
    String getAddress();
}

public class MyComponent implements MyService {
    void updated(MyConfig cnf) {
        int port = cnf.getPort();
        String addr = cnf.getAddress();
        ...
    }
}

public class Activator extends DependencyActivatorBase {
    &Override
    public void init(BundleContext context, DependencyManager dm) throws Exception {
        Component factoryComponent = createFactoryComponent()
            .setFactoryPid("my.factory.pid")
            .setInterface(MySevice.class.getName(), null)
            .setImplementation(MyComponent.class)
            .setConfigType(MyConfig.class);
        dm.add(factoryComponent);
    }
}
Rev. 1843265 by pderop on Tue, 9 Oct 2018 13:33:43 +0000
Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.