[ 
https://issues.apache.org/jira/browse/FELIX-4777?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pierre De Rop resolved FELIX-4777.
----------------------------------
    Resolution: Fixed

I committed in rv 1661577 a fix for the support of {{name}} attribute for the 
ConfigurationDependency annotation, which is now consistent with other kind of 
dependencies. 

You can now dynamically define the {{pid}} and {{propagate}} flag from the init 
method. However, in the DependencyManager API (the dm runtime depends on it), 
the Configuration Dependency can only be required for now, so it's not 
currently possible to control the {{required}} flag.

Here is an example of a component which first declare an initial Configuration 
Dependency. This configuration is then used to gather another pid (and also the 
associated propagate flag) in order to define another configuration dependency 
on a global/shared configuration:

{code}
  /**
    * A Component that dynamically defines an extra dynamic configuration 
    * dependency from its init method. 
    */
  @Component
  class MyComponent implements MyService {
      private Dictionary cnf; // initial config
      
      // Inject initial Configuration (injected before any other required 
dependencies)
      @ConfigurationDependency
      void componentConfiguration(Dictionary cnf) {
           // you must throw an exception if the configuration is not valid
           this.cnf = cnf;
      }
      
      /**
       * All unnamed dependencies are injected: we can now configure our 
dynamic configuration whose dependency name is "global".
       */
      @Init
      Map init() {
          Map map = new HashMap();
           map.put("global.pid", cnf.get("globalConfig.pid"));
           map.put("global.propagate", cnf.get("globalConfig.propagate"));
           return map;
      } 
 
      // Injected after init, and dynamically configured by the init method.
      @ConfigurationDependency(name="global")
      void globalConfiguration(Dictionary globalConfig) {
           // you must throw an exception if the configuration is not valid
      }
 
      /**
       * All dependencies are injected and our service is now ready to be 
published.
       */
      @Start
      void start() {
      }
  }
{code}



> Dynamic initialization time configuration of @ConfigurationDependency 
> ----------------------------------------------------------------------
>
>                 Key: FELIX-4777
>                 URL: https://issues.apache.org/jira/browse/FELIX-4777
>             Project: Felix
>          Issue Type: Improvement
>          Components: Dependency Manager
>         Environment: 3.2.0
>            Reporter: Tuomas Kiviaho
>            Assignee: Pierre De Rop
>             Fix For: dependencymanager.annotations-4.0.0, 
> dependencymanager.runtime-4.0.0
>
>
> {{@ConfigurationDependency}} annotation is missing the {{name}} method whitch 
> would allow to postpone the callback methods after initialization. 
> I stumbled upon this problem when I needed JTA at {{updated}} method but the 
> manager (via service dependency) was not yet available.
> As a bonus one could then add support for metadata customization and have an 
> impact on {{required}} based on information gathered from 
> dependencies/injections that have already arrived at this point (BTW: 
> currently it's just hardcoded as {{true}} although the metadata - already as 
> it is - would be useful even in {{false}} mode). 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to