You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by bu...@apache.org on 2015/03/08 00:15:36 UTC

svn commit: r942800 - in /websites/staging/felix/trunk/content: ./ documentation/subprojects/apache-felix-dependency-manager-4/reference/dependency-configuration.html

Author: buildbot
Date: Sat Mar  7 23:15:35 2015
New Revision: 942800

Log:
Staging update by buildbot for felix

Modified:
    websites/staging/felix/trunk/content/   (props changed)
    websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager-4/reference/dependency-configuration.html

Propchange: websites/staging/felix/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Sat Mar  7 23:15:35 2015
@@ -1 +1 @@
-1664928
+1664929

Modified: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager-4/reference/dependency-configuration.html
==============================================================================
--- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager-4/reference/dependency-configuration.html (original)
+++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager-4/reference/dependency-configuration.html Sat Mar  7 23:15:35 2015
@@ -77,9 +77,11 @@
 <li><em>pid</em>: Returns the pid for a given service (by default, the pid is the service class name).</li>
 <li><em>pidClass</em>: Will the the name of the specified class as the the pid for a given service (by default, the pid is the service class name).</li>
 <li><em>propagate</em>: Returns true if the configuration properties must be published along with the service. Any additional service properties specified directly are merged with these.</li>
-<li><em>heading</em>: The label used to display the tab name (or section) where the properties are displayed. Example: "Printer Service".</li>
-<li><em>description</em>: A human readable description of the PID this annotation is associated with. Example: "Configuration for the PrinterService bundle".</li>
-<li><em>metadata</em>: an array of PropertyMetadaData[]() annotation describing property types (see the FactoryConfigurationAdapterService section in the "Writing Components" section.</li>
+<li><em>name</em>: The name for this configuration dependency. When you give a name a dependency, it won't be evaluated immediately, but after the component's init method has been called, 
+and from the init method, you can then return a map in order to dynamically configure the 
+configuration dependency (the map has to contain a "pid" and/or "propagate" flag, prefixed 
+with the dependency name). Then the dependency will be evaluated after the component init 
+method, and will be injected before the start method. </li>
 </ul>
 <p>Usage Examples</p>
 <p>In the following example, the "Printer" component depends on a configuration whose PID name is "org.apache.felix.sample.Printer". This service will initialize its ip/port number from the provided configuration:</p>
@@ -133,8 +135,53 @@ configurations data, some descriptions,
      <span class="p">}</span>
  <span class="p">}</span>
 </pre></div>
+
+
+<p>Finally, the last example shows how to dynamically configure a configuration dependency pid from the init method.
+The following component first depends on a "sample.MyComponent" configuration pid. Then the init method gets from that configuration 
+another pid for a second "global" configuration:</p>
+<div class="codehilite"><pre><span class="kn">package</span> <span class="n">sample</span><span class="o">;</span>
+
+<span class="cm">/**</span>
+<span class="cm">  * A Service that dynamically defines an extra dynamic configuration dependency from its init method. </span>
+<span class="cm">  */</span>
+<span class="nd">@Component</span>
+<span class="kd">class</span> <span class="nc">MyComponent</span> <span class="o">{</span>
+  <span class="kd">private</span> <span class="n">Dictionary</span> <span class="n">m_config</span><span class="o">;</span>
+
+  <span class="c1">// Inject initial Configuration (injected before any other required dependencies)</span>
+  <span class="nd">@ConfigurationDependency</span>
+  <span class="kt">void</span> <span class="nf">componentConfiguration</span><span class="o">(</span><span class="n">Dictionary</span> <span class="n">config</span><span class="o">)</span> <span class="o">{</span>
+       <span class="c1">// you must throw an exception if the configuration is not valid</span>
+       <span class="n">m_config</span> <span class="o">=</span> <span class="n">config</span><span class="o">;</span>
+  <span class="o">}</span>
+
+  <span class="cm">/**</span>
+<span class="cm">   * All unnamed dependencies are injected: we can now configure our dynamic configuration whose dependency name is &quot;global&quot;.</span>
+<span class="cm">   */</span>
+  <span class="nd">@Init</span>
+  <span class="n">Map</span> <span class="nf">init</span><span class="o">()</span> <span class="o">{</span>
+      <span class="k">return</span> <span class="k">new</span> <span class="nf">HashMap</span><span class="o">()</span> <span class="o">;</span>
+  <span class="o">}</span>
+
+  <span class="c1">// Injected after init, and dynamically configured by the init method.</span>
+  <span class="nd">@ConfigurationDependency</span><span class="o">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;global&quot;</span><span class="o">)</span>
+  <span class="kt">void</span> <span class="nf">globalConfiguration</span><span class="o">(</span><span class="n">Dictionary</span> <span class="n">globalConfig</span><span class="o">)</span> <span class="o">{</span>
+       <span class="c1">// you must throw an exception if the configuration is not valid</span>
+  <span class="o">}</span>
+
+  <span class="cm">/**</span>
+<span class="cm">   * All dependencies are injected and our service is now ready to be published.</span>
+<span class="cm">   */</span>
+  <span class="nd">@Start</span>
+  <span class="kt">void</span> <span class="nf">start</span><span class="o">()</span> <span class="o">{</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p>}</p>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1664926 by pderop on Sat, 7 Mar 2015 21:57:27 +0000
+        Rev. 1664929 by pderop on Sat, 7 Mar 2015 23:15:21 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project