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 2018/10/09 13:36:40 UTC

svn commit: r1036194 [1/2] - in /websites/staging/felix/trunk/content: ./ documentation/subprojects/apache-felix-dependency-manager/reference/dependency-service.html documentation/subprojects/apache-felix-dependency-manager/reference/dm-annotations.html

Author: buildbot
Date: Tue Oct  9 13:36:40 2018
New Revision: 1036194

Log:
Staging update by buildbot for felix

Added:
    websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/dm-annotations.html
Modified:
    websites/staging/felix/trunk/content/   (props changed)
    websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/dependency-service.html

Propchange: websites/staging/felix/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Tue Oct  9 13:36:40 2018
@@ -1 +1 @@
-1843272
+1843274

Modified: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/dependency-service.html
==============================================================================
--- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/dependency-service.html (original)
+++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/dependency-service.html Tue Oct  9 13:36:40 2018
@@ -88,77 +88,36 @@ h2:hover > .headerlink, h3:hover > .head
   visibility: hidden;
 }
 h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
-<p>A service dependency allows you to depend on a service, either by type or by using an additional filter condition. You can even depend on an existing service directly by providing a reference to it.</p>
-<h2 id="servicedependency">@ServiceDependency<a class="headerlink" href="#servicedependency" title="Permanent link">&para;</a></h2>
-<p>Annotates a method or a field for injecting a Service Dependency on it. When applied on a class field, optional unavailable dependencies are injected with a NullObject.</p>
-<p>Annotation attributes:</p>
-<ul>
-<li><em>added</em>: The callback method to be invoked when the service is available. This attribute is only meaningful when the annotation is applied on a class field.</li>
-<li><em>changed</em>: The callback method to be invoked when the service properties have changed.</li>
-<li><em>removed</em>: The callback method to invoke when the service is lost.</li>
-<li><em>timeout</em>: The max time in millis to wait for when the dependency is temporarily unavailable. Specifying a positive number allow to block the caller thread between service updates. Only useful for required stateless dependencies that can be replaced transparently. A Dynamic Proxy is used to wrap the actual service dependency (which must be an interface). When the dependency goes away, an attempt is made to replace it with another one which satisfies the service dependency criteria. If no service replacement is available, then any method invocation (through the dynamic proxy) will block during a configurable timeout. On timeout, an unchecked IllegalStateException exception is raised (but the service is not deactivated).
-Notice that the changed/removed callbacks are not used when the timeout parameter is &gt; -1.
--1 means no timeout at all (default). 0 means that invocation on a missing service will fail immediately. A positive number represents the max timeout in millis to wait for the service availability.</li>
-<li><em>name</em>: The name used when dynamically configuring this dependency from the init method. Specifying this attribute allows to dynamically configure the dependency filter and required flag from the Service's init method. All unnamed dependencies will be injected before the init() method; so from the init() method, you can then pick up whatever information needed from already injected (unnamed) dependencies, and configure dynamically your named dependencies, which will then be calculated once the init() method returns. Please refer to <a href="">Here</a> for more informations about named dependencies.</li>
-<li><em>propagate</em>: Returns true if the dependency service properties must be published along with the service. Any additional service properties specified directly are merged with these.</li>
-</ul>
-<h2 id="usage-example">Usage Example:<a class="headerlink" href="#usage-example" title="Permanent link">&para;</a></h2>
-<p>Here, the MyComponent component is injected with a dependency over a "MyDependency" service.</p>
-<div class="codehilite"><pre><span class="nd">@Component</span>
-<span class="kd">class</span> <span class="nc">MyComponent</span> <span class="o">{</span>
-     <span class="nd">@ServiceDependency</span><span class="o">(</span><span class="n">timeout</span><span class="o">=</span><span class="mi">15000</span><span class="o">)</span>
-     <span class="n">MyDependency</span> <span class="n">dependency</span><span class="o">;</span>
-     <span class="c1">// ...</span>
+<p>A service dependency allows you to depend on a service, either by type or by using an additional filter 
+condition. You can even depend on an existing service directly by providing a reference to it.</p>
+<p>To define a service dependency, you need to use the <a href="http://felix.apache.org/apidocs/dependencymanager.annotations/r12/org/apache/felix/dm/ServiceDependency.html">ServiceDependecy</a> interface.
+This interface can be created using DependencyActivatorBase.createServiceDependency() or DependencyManager.createServiceDependency() methods;</p>
+<p>Service dependencies can be injected on fields or using callbacks, can be required or optional, and NullObject pattern is supported for optional dependencies applied on class fields.</p>
+<p>Example:</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Activator</span> <span class="kd">extends</span> <span class="n">DependencyActivatorBase</span> <span class="o">{</span>
+    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">init</span><span class="o">(</span><span class="n">BundleContext</span> <span class="n">context</span><span class="o">,</span> <span class="n">DependencyManager</span> <span class="n">manager</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+        <span class="n">manager</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">createComponent</span><span class="o">()</span>
+            <span class="o">.</span><span class="na">setImplementation</span><span class="o">(</span><span class="n">DataGenerator</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
+            <span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">createServiceDependency</span><span class="o">()</span>
+                <span class="o">.</span><span class="na">setService</span><span class="o">(</span><span class="n">Store</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
+                <span class="o">.</span><span class="na">setRequired</span><span class="o">(</span><span class="kc">true</span><span class="o">)</span>
+            <span class="o">)</span>
+        <span class="o">);</span>
+    <span class="o">}</span>
 <span class="o">}</span>
-</pre></div>
-
-
-<p>Usage example of a Service whose dependency filter is configured from ConfigAdmin, using a "named" dependency
-(please check <a href="">Here</a> for more informations about "named" dependencies):</p>
-<div class="codehilite"><pre><span class="cm">/**</span>
-<span class="cm">  * A Service whose service dependency &quot;otherService&quot; filter is configured from ConfigAdmin</span>
-<span class="cm">  */</span>
-<span class="nd">@Service</span>
-<span class="kd">class</span> <span class="nc">X</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="cm">/**</span>
-<span class="cm">       * Initialize our service from config ... and store the config for later usage (from our init method)</span>
-<span class="cm">       */</span>
-     <span class="nd">@ConfigurationDependency</span><span class="o">(</span><span class="n">pid</span><span class="o">=</span><span class="s">&quot;MyPid&quot;</span><span class="o">)</span>
-     <span class="kt">void</span> <span class="nf">configure</span><span class="o">(</span><span class="n">Dictionary</span> <span class="n">conf</span><span class="o">)</span> <span class="o">{</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="kd">public</span> <span class="kd">class</span> <span class="nc">DataGenerator</span> <span class="o">{</span>
+    <span class="kd">private</span> <span class="kd">volatile</span> <span class="n">Store</span> <span class="n">m_store</span><span class="o">;</span>
 
-     <span class="cm">/**</span>
-<span class="cm">      * All unnamed dependencies are injected: we can now configure other named</span>
-<span class="cm">      * dependencies, using the already injected configuration.</span>
-<span class="cm">      * The returned Map will be used to configure our &quot;otherService&quot; Dependency.</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="cm">/**</span>
-<span class="cm">      * This named dependency filter/required flag will be configured by our init method (see above).</span>
-<span class="cm">      */</span>
-     <span class="nd">@ServiceDependency</span><span class="o">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;otherService&quot;</span><span class="o">)</span>
-         <span class="kt">void</span> <span class="nf">bindOtherService</span><span class="o">(</span><span class="n">OtherService</span> <span class="n">other</span><span class="o">)</span> <span class="o">{</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">      * Notice that you can also use the publisher service attribute if you need</span>
-<span class="cm">      * to take control on service exposition.</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>
- <span class="o">}</span>
+    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">generate</span><span class="o">()</span> <span class="o">{</span>
+        <span class="k">for</span> <span class="o">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">10</span><span class="o">;</span> <span class="n">i</span><span class="o">++)</span> <span class="o">{</span>
+            <span class="n">m_store</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;#&quot;</span> <span class="o">+</span> <span class="n">i</span><span class="o">,</span> <span class="s">&quot;value_&quot;</span> <span class="o">+</span> <span class="n">i</span><span class="o">);</span>
+        <span class="o">}</span>
+    <span class="o">}</span>
+<span class="o">}</span>
 </pre></div>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1665812 by marrs on Wed, 11 Mar 2015 09:02:04 +0000
+        Rev. 1843273 by pderop on Tue, 9 Oct 2018 13:36:14 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project