public interface FactoryPidAdapterBuilder extends ComponentBuilder<FactoryPidAdapterBuilder>
For each new Config Admin factory configuration matching a given factory pid,
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.
This builded supports type safe configuration types. For a given factory configuration, you can specify an interface of your choice,
and DM will implement it using a dynamic proxy that converts interface methods to lookups in the actual factory configuration dictionary.
For more information about configuration types, please refer to ConfigurationDependencyBuilder
.
Example that defines a factory configuration adapter service for the "foo.bar" factory pid. For each factory pid instance, an instance of the DictionaryImpl component will be created.
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
factoryPidAdapter(adapter -> adapter
.impl(DictionaryImpl.class)
.factoryPid("foo.bar")
.update(ServiceImpl::updated)
.propagate()
.withSvc(LogService.class, log -> log.optional()));
}
}
Example that defines a factory configuration adapter using a user defined configuration type (the pid is by default assumed to match the fqdn of the configuration type):
public interface DictionaryConfiguration {
public String getLanguage();
public List<String> getWords();
}
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
factoryPidAdapter(adapter -> adapter
.impl(DictionaryImpl.class)
.factoryPid("foo.bar")
.update(DictionaryConfiguration.class, ServiceImpl::updated)
.propagate()
.withSvc(LogService.class, log -> log.optional()));
}
}
Modifier and Type | Method and Description |
---|---|
FactoryPidAdapterBuilder |
factoryPid(java.lang.String pid)
Specifies the factory pid used by the adapter.
|
FactoryPidAdapterBuilder |
propagate()
Specifies if the public properties (not starting with a dot) should be propagated to the adapter service properties (false by default).
|
FactoryPidAdapterBuilder |
propagate(boolean propagate)
Specifies if the public properties (not starting with a dot) should be propagated to the adapter service properties (false by default).
|
<T> FactoryPidAdapterBuilder |
update(CbDictionary<T> callback)
Specifies a method reference that will be called on one of the component classes when the configuration is injected.
|
<T> FactoryPidAdapterBuilder |
update(CbDictionaryComponent<T> callback)
Specifies a method reference that will be called on one of the component classes when the configuration is injected
|
FactoryPidAdapterBuilder |
update(java.lang.Class<?> configType,
java.lang.Object callbackInstance,
java.lang.String updateMethod)
Specifies a callback instance method that will be called on a given object instance when the configuration is injected.
|
FactoryPidAdapterBuilder |
update(java.lang.Class<?> configType,
java.lang.String updateMethod)
Sets a callback method to call on the component implementation when the configuration is updated.
|
<T> FactoryPidAdapterBuilder |
update(java.lang.Class<T> configType,
InstanceCbConfiguration<T> callback)
Specifies a method reference that will be called on a given object instance when the configuration is injected.
|
<T> FactoryPidAdapterBuilder |
update(java.lang.Class<T> configType,
InstanceCbConfigurationComponent<T> callback)
Specifies a method reference that will be called on a given object instance when the configuration is injected.
|
<T,U> FactoryPidAdapterBuilder |
update(java.lang.Class<U> configType,
CbConfiguration<T,U> callback)
Specifies a method reference that will be called on one of the component classes when the configuration is injected.
|
<T,U> FactoryPidAdapterBuilder |
update(java.lang.Class<U> configType,
CbConfigurationComponent<T,U> callback)
Specifies a method reference that will be called on one of the component classes when the configuration is injected.
|
FactoryPidAdapterBuilder |
update(InstanceCbDictionary callback)
Specifies a method reference that will be called on a given object instance when the configuration is injected
|
FactoryPidAdapterBuilder |
update(InstanceCbDictionaryComponent callback)
Specifies a method reference that will be called on a given object instance when the configuration is injected.
|
FactoryPidAdapterBuilder |
update(java.lang.Object callbackInstance,
java.lang.String updateMethod)
Specifies a callback instance method that will be called on a given object instance when the configuration is injected.
|
FactoryPidAdapterBuilder |
update(java.lang.String updateMethod)
Specifies a callback method that will be called on the component implementation when the configuration is injected.
|
autoAdd, autoConfig, autoConfig, build, composition, composition, composition, debug, destroy, destroy, destroy, destroy, factory, factory, factory, factory, factory, impl, init, init, init, init, listener, properties, properties, properties, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, scope, start, start, start, start, stop, stop, stop, stop, withBundle, withCnf, withCnf, withCnf, withDep, withFuture, withSvc, withSvc, withSvc, withSvc, withSvc, withSvc
FactoryPidAdapterBuilder factoryPid(java.lang.String pid)
pid
- the factory pid.FactoryPidAdapterBuilder propagate()
FactoryPidAdapterBuilder propagate(boolean propagate)
propagate
- true if the public properties should be propagated to the adapter service properties (false by default).FactoryPidAdapterBuilder update(java.lang.String updateMethod)
updateMethod
- the method to call on the component implementation when the configuration is available ("updated" by default).
The following method signatures are supported:
FactoryPidAdapterBuilder update(java.lang.Class<?> configType, java.lang.String updateMethod)
The following callback signatures are supported and searched in the following order:
configType
- the type of a configuration that is passed as argument to the callbackupdateMethod
- the callback to call on the component implementation when the configuration is updated.FactoryPidAdapterBuilder update(java.lang.Object callbackInstance, java.lang.String updateMethod)
updateMethod
- the method to call on the given object instance when the configuration is available ("updated" by default).
The following method signatures are supported:
method(Dictionary properties)
method(Component component, Dictionary properties)
callbackInstance
- the Object instance on which the updated callback will be invoked.FactoryPidAdapterBuilder update(java.lang.Class<?> configType, java.lang.Object callbackInstance, java.lang.String updateMethod)
The following callback signatures are supported and searched in the following order:
configType
- the type of a configuration that is passed as argument to the callbackcallbackInstance
- the Object instance on which the updated callback will be invoked.updateMethod
- the method to call on the given object instance when the configuration is available. The callback is invoked
with a configuration type argument (matching the configType you have specified.<T> FactoryPidAdapterBuilder update(CbDictionary<T> callback)
T
- the type of the component implementation class on which the callback is invoked on.callback
- the method to call on one of the component classes when the configuration is available.<T,U> FactoryPidAdapterBuilder update(java.lang.Class<U> configType, CbConfiguration<T,U> callback)
T
- the type of the component implementation class on which the callback is invoked on.U
- the configuration type accepted by the callback method.configType
- the type of a configuration that is passed as argument to the callbackcallback
- the method to call on one of the component classes when the configuration is available.<T> FactoryPidAdapterBuilder update(CbDictionaryComponent<T> callback)
T
- the type of the component implementation class on which the callback is invoked on.callback
- the reference to a method on one of the component classes. The method may takes as arguments a Dictionary and a Component.<T,U> FactoryPidAdapterBuilder update(java.lang.Class<U> configType, CbConfigurationComponent<T,U> callback)
T
- the type of the component implementation class on which the callback is invoked on.U
- the configuration type accepted by the callback method.configType
- the type of a configuration that is passed as argument to the callbackcallback
- the reference to a method on one of the component classes. The method may takes as arguments a configuration type and a Component.FactoryPidAdapterBuilder update(InstanceCbDictionary callback)
callback
- the method to call on a given object instance when the configuration is available. The callback takes as argument a
a Dictionary parameter.<T> FactoryPidAdapterBuilder update(java.lang.Class<T> configType, InstanceCbConfiguration<T> callback)
T
- the configuration type accepted by the callback method.configType
- the type of a configuration that is passed as argument to the callbackcallback
- the method to call on a given object instance when the configuration is available. The callback takes as argument a
a configuration type parameter.FactoryPidAdapterBuilder update(InstanceCbDictionaryComponent callback)
callback
- the method to call on a given object instance when the configuration is available. The callback takes as argument a
Dictionary, and a Component parameter.<T> FactoryPidAdapterBuilder update(java.lang.Class<T> configType, InstanceCbConfigurationComponent<T> callback)
T
- the configuration type accepted by the callback method.configType
- the type of a configuration that is passed as argument to the callbackcallback
- the method to call on a given object instance when the configuration is available. The callback takes as arguments a
configuration type, and a Component parameter.