Interface FactoryPidAdapterBuilder

All Superinterfaces:
ComponentBuilder<FactoryPidAdapterBuilder>

public interface FactoryPidAdapterBuilder extends ComponentBuilder<FactoryPidAdapterBuilder>
Builds a Dependency Manager Factory Configuration Adapter Component.

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()));
    }
 }
 
  • Method Details

    • factoryPid

      Specifies the factory pid used by the adapter.
      Parameters:
      pid - the factory pid.
      Returns:
      this builder
    • propagate

      Specifies if the public properties (not starting with a dot) should be propagated to the adapter service properties (false by default).
      Returns:
      this builder.
    • propagate

      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).
      Parameters:
      propagate - true if the public properties should be propagated to the adapter service properties (false by default).
      Returns:
      this builder.
    • update

      FactoryPidAdapterBuilder update(String updateMethod)
      Specifies a callback method that will be called on the component implementation when the configuration is injected.
      Parameters:
      updateMethod - the method to call on the component implementation when the configuration is available ("updated" by default).

      The following method signatures are supported:

      1. method(Dictionary properties)
      2. method(Component component, Dictionary properties)
      Returns:
      this builder
    • update

      FactoryPidAdapterBuilder update(Class<?> configType, String updateMethod)
      Sets a callback method to call on the component implementation when the configuration is updated. The callback is invoked with a configuration type argument.

      The following callback signatures are supported and searched in the following order:

      1. method(Dictionary)
      2. method(Component, Dictionary)
      3. method(Configuration) // same type as the one specified in the "configType" argument
      4. method(Component, Configuration) // Configuration has the same type as the one specified in the "configType" argument
      Parameters:
      configType - the type of a configuration that is passed as argument to the callback
      updateMethod - the callback to call on the component implementation when the configuration is updated.
      Returns:
      this builder
    • update

      FactoryPidAdapterBuilder update(Object callbackInstance, String updateMethod)
      Specifies a callback instance method that will be called on a given object instance when the configuration is injected.
      Parameters:
      callbackInstance - 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 ("updated" by default). The following method signatures are supported:
       
          method(Dictionary properties)
          method(Component component, Dictionary properties)
       
      Returns:
      this builder
    • update

      FactoryPidAdapterBuilder update(Class<?> configType, Object callbackInstance, String updateMethod)
      Specifies a callback instance method that will be called on a given object instance when the configuration is injected. The callback is invoked with a configuration type argument.

      The following callback signatures are supported and searched in the following order:

      1. method(Dictionary)
      2. method(Component, Dictionary)
      3. method(Configuration) // same type as the one specified in the "configType" argument
      4. method(Component, Configuration) // Configuration has the same type as the one specified in the "configType" argument
      Parameters:
      configType - the type of a configuration that is passed as argument to the callback
      callbackInstance - 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.
      Returns:
      this builder
    • update

      <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. The callback is invoked with a Dictionary argument.
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked on.
      Parameters:
      callback - the method to call on one of the component classes when the configuration is available.
      Returns:
      this builder
    • update

      <T, U> FactoryPidAdapterBuilder update(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. The callback is invoked with a configuration type argument.
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked on.
      U - the configuration type accepted by the callback method.
      Parameters:
      configType - the type of a configuration that is passed as argument to the callback
      callback - the method to call on one of the component classes when the configuration is available.
      Returns:
      this builder
    • update

      Specifies a method reference that will be called on one of the component classes when the configuration is injected
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked on.
      Parameters:
      callback - the reference to a method on one of the component classes. The method may takes as arguments a Dictionary and a Component.
      Returns:
      this builder
    • update

      <T, U> FactoryPidAdapterBuilder update(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. The callback is invoked with the following arguments: a configuration type, and a Component object.
      Type Parameters:
      T - the type of the component implementation class on which the callback is invoked on.
      U - the configuration type accepted by the callback method.
      Parameters:
      configType - the type of a configuration that is passed as argument to the callback
      callback - the reference to a method on one of the component classes. The method may takes as arguments a configuration type and a Component.
      Returns:
      this builder
    • update

      Specifies a method reference that will be called on a given object instance when the configuration is injected
      Parameters:
      callback - the method to call on a given object instance when the configuration is available. The callback takes as argument a a Dictionary parameter.
      Returns:
      this builder
    • update

      <T> FactoryPidAdapterBuilder update(Class<T> configType, InstanceCbConfiguration<T> callback)
      Specifies a method reference that will be called on a given object instance when the configuration is injected. The callback is invoked with a type-safe configuration type argument.
      Type Parameters:
      T - the configuration type accepted by the callback method.
      Parameters:
      configType - the type of a configuration that is passed as argument to the callback
      callback - the method to call on a given object instance when the configuration is available. The callback takes as argument a a configuration type parameter.
      Returns:
      this builder
    • update

      Specifies a method reference that will be called on a given object instance when the configuration is injected.
      Parameters:
      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.
      Returns:
      this builder
    • update

      <T> FactoryPidAdapterBuilder update(Class<T> configType, InstanceCbConfigurationComponent<T> callback)
      Specifies a method reference that will be called on a given object instance when the configuration is injected.
      Type Parameters:
      T - the configuration type accepted by the callback method.
      Parameters:
      configType - the type of a configuration that is passed as argument to the callback
      callback - 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.
      Returns:
      this builder