felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r979317 - in /websites/staging/felix/trunk/content: ./ documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html
Date Tue, 02 Feb 2016 21:54:41 GMT
Author: buildbot
Date: Tue Feb  2 21:54:40 2016
New Revision: 979317

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/guides/dm-lambda.html

Propchange: websites/staging/felix/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Tue Feb  2 21:54:40 2016
@@ -1 +1 @@
-1728179
+1728227

Modified: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html
==============================================================================
--- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html
(original)
+++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html
Tue Feb  2 21:54:40 2016
@@ -108,24 +108,24 @@ the DependencyManager class automaticall
 <p>There are two ways to use these builders:</p>
 <p>You can first instantiate builders using some of the convenient factory methods
available from the DependencyManagerActivator class, which is the new base class
 for dm-lambda activators:</p>
-<div class="codehilite"><pre><span class="kn">import</span> <span
class="nn">static</span> <span class="n">org</span><span class="o">.</span><span
class="na">apache</span><span class="o">.</span><span class="na">felix</span><span
class="o">.</span><span class="na">dm</span><span class="o">.</span><span
class="na">lambda</span><span class="o">.</span><span class="na">DependencyManagerActivator</span><span
class="o">.*;</span>
+<div class="codehilite"><pre><span class="kn">import</span> <span
class="nn">org.apache.felix.dm.lambda.DependencyManagerActivator</span><span class="o">;</span>
 
 <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="nd">@Override</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">ctx</span><span class="o">,</span> <span class="n">DependencyManager</span>
<span class="n">dm</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">Exception</span> <span class="o">{</span>
         <span class="n">Component</span> <span class="n">comp</span>
<span class="o">=</span> <span class="n">component</span><span
class="o">().</span><span class="na">impl</span><span class="o">(</span><span
class="n">Hello</span><span class="o">.</span><span class="na">class</span><span
class="o">).</span><span class="na">build</span><span class="o">();</span>
-        <span class="n">m_dm</span><span class="o">.</span><span
class="na">add</span><span class="o">(</span><span class="n">comp</span><span
class="o">);</span>
+        <span class="n">dm</span><span class="o">.</span><span
class="na">add</span><span class="o">(</span><span class="n">comp</span><span
class="o">);</span>
     <span class="o">}</span>
 <span class="o">}</span>
 </pre></div>
 
 
 <p>The <code>component()</code> method returns a <code>ComponentBuilder</code>
and the call to <code>build</code> at the end of the call chain returns the actual
DM Component object.</p>
-<p>Now, most of the time, in an Activator, you usually almost always create and immediately
add the component in the <code>dm</code> object.
-So, in order to reduce the "<code>code ceremony</code>", you can also use a special
overloaded factory method that accepts a lambda which takes as argument a
+<p>Now, most of the time, in an Activator, you usually almost always create and immediately
add the component to the <code>dm</code> object.
+So, in order to reduce the code size, you can also use a special overloaded factory method
that accepts a lambda which takes as argument a
 <code>Consumer&lt;ComponentBuilder&gt;</code> parameter.
 So, the lambda has just to invoke the chain of necessary methods from the builder, without
having to call <code>build</code> and add the returned Component to the <code>dm</code>
object.</p>
-<p>The following is the same as above, using a consumer<ComponentBuilder> lambda
expression:</p>
+<p>The following is the same as above, using a <code>consumer&lt;ComponentBuilder&gt;</code>
lambda expression:</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="nd">@Override</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">ctx</span><span class="o">,</span> <span class="n">DependencyManager</span>
<span class="n">dm</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">Exception</span> <span class="o">{</span>
@@ -147,11 +147,12 @@ So, the lambda has just to invoke the ch
 
 <h2 id="adding-service-dependencies">Adding service dependencies<a class="headerlink"
href="#adding-service-dependencies" title="Permanent link">&para;</a></h2>
 <p>Service Dependencies, unlike in the original DM API, are required by default, and
you can add a dependency using the <code>withSrv</code> methods available from
the ComponentBuilder interface.
-Such method accepts a Consumer<ServiceDependencyBuilder> lambda expression, which may
then configure the dependency using a chain of method calls (filter/callbacks,autoconfig,
etc ...):</p>
+Such method accepts a <code>Consumer&lt;ServiceDependencyBuilder&gt;</code>
lambda expression, which may then configure the dependency using a chain of method calls (filter/callbacks,autoconfig,
etc ...):</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="nd">@Override</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">ctx</span><span class="o">,</span> <span class="n">DependencyManager</span>
<span class="n">dm</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">component</span><span class="o">(</span><span
class="n">comp</span> <span class="o">-&gt;</span> <span class="n">comp</span><span
class="o">.</span><span class="na">impl</span><span class="o">(</span><span
class="n">Hello</span><span class="o">.</span><span class="na">class</span><span
class="o">).</span><span class="na">withSrv</span><span class="o">(</span><span
class="n">LogService</span><span class="o">.</span><span class="na">class</span><span
class="o">,</span> <span class="o">(</span><span class="n">ServiceDependencyBuilder</span>
<span class="n">srv</span><span class="o">)</span> <span class="o">-&gt;</span>
<span class="n">srv</span><span class="o">.</span><span class="na">filter</span><span
class="o">(</span><span class="s">&quot;(vendor=apache)&quot;</span><span
class="o">)));</span>
+        <span class="n">component</span><span class="o">(</span><span
class="n">comp</span> <span class="o">-&gt;</span> <span class="n">comp</span><span
class="o">.</span><span class="na">impl</span><span class="o">(</span><span
class="n">Hello</span><span class="o">.</span><span class="na">class</span><span
class="o">)</span>
+            <span class="o">.</span><span class="na">withSrv</span><span
class="o">(</span><span class="n">LogService</span><span class="o">.</span><span
class="na">class</span><span class="o">,</span> <span class="o">(</span><span
class="n">ServiceDependencyBuilder</span> <span class="n">srv</span><span
class="o">)</span> <span class="o">-&gt;</span> <span class="n">srv</span><span
class="o">.</span><span class="na">filter</span><span class="o">(</span><span
class="s">&quot;(vendor=apache)&quot;</span><span class="o">)));</span>
     <span class="o">}</span>
 <span class="o">}</span>
 </pre></div>
@@ -167,11 +168,11 @@ Such method accepts a Consumer<ServiceDe
 </pre></div>
 
 
-<p>If you depend on multiple required services (with no filters), you can declare the
services in one shot like this:</p>
+<p>If you depend on multiple required services (without filters), you can declare the
services in one shot like this:</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="nd">@Override</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">ctx</span><span class="o">,</span> <span class="n">DependencyManager</span>
<span class="n">dm</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">Exception</span> <span class="o">{</span>
-    <span class="c1">// using a varargs of service dependencies ...</span>
+        <span class="c1">// using a varargs of service dependencies ...</span>
         <span class="n">component</span><span class="o">(</span><span
class="n">comp</span> <span class="o">-&gt;</span> <span class="n">comp</span><span
class="o">.</span><span class="na">impl</span><span class="o">(</span><span
class="n">Hello</span><span class="o">.</span><span class="na">class</span><span
class="o">).</span><span class="na">withSrv</span><span class="o">(</span><span
class="n">LogService</span><span class="o">.</span><span class="na">class</span><span
class="o">,</span> <span class="n">EventAdmin</span><span class="o">.</span><span
class="na">class</span><span class="o">));</span> 
     <span class="o">}</span>
 <span class="o">}</span>
@@ -245,7 +246,7 @@ In this case, you can use the "<code>cbi
 <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="nd">@Override</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">ctx</span><span class="o">,</span> <span class="n">DependencyManager</span>
<span class="n">dm</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">Exception</span> <span class="o">{</span>
-    <span class="n">DependencyHandler</span> <span class="n">depHandler</span>
<span class="o">=</span> <span class="k">new</span> <span class="n">DependencyHandler</span><span
class="o">();</span>
+        <span class="n">DependencyHandler</span> <span class="n">depHandler</span>
<span class="o">=</span> <span class="k">new</span> <span class="n">DependencyHandler</span><span
class="o">();</span>
         <span class="n">component</span><span class="o">(</span><span
class="n">comp</span> <span class="o">-&gt;</span> <span class="n">comp</span><span
class="o">.</span><span class="na">impl</span><span class="o">(</span><span
class="n">Hello</span><span class="o">.</span><span class="na">class</span><span
class="o">).</span><span class="na">withSrv</span><span class="o">(</span><span
class="n">LogService</span><span class="o">.</span><span class="na">class</span><span
class="o">,</span> <span class="n">srv</span> <span class="o">-&gt;</span>
<span class="n">srv</span><span class="o">.</span><span class="na">cbi</span><span
class="o">(</span><span class="n">depHandler</span><span class="o">,</span>
<span class="s">&quot;setLog&quot;</span><span class="o">)));</span>
     <span class="o">}</span>
 <span class="o">}</span>
@@ -256,7 +257,7 @@ In this case, you can use the "<code>cbi
 <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="nd">@Override</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">ctx</span><span class="o">,</span> <span class="n">DependencyManager</span>
<span class="n">dm</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">Exception</span> <span class="o">{</span>
-    <span class="n">DependencyHandler</span> <span class="n">depHandler</span>
<span class="o">=</span> <span class="k">new</span> <span class="n">DependencyHandler</span><span
class="o">();</span>
+        <span class="n">DependencyHandler</span> <span class="n">depHandler</span>
<span class="o">=</span> <span class="k">new</span> <span class="n">DependencyHandler</span><span
class="o">();</span>
         <span class="n">component</span><span class="o">(</span><span
class="n">comp</span> <span class="o">-&gt;</span> <span class="n">comp</span><span
class="o">.</span><span class="na">impl</span><span class="o">(</span><span
class="n">Hello</span><span class="o">.</span><span class="na">class</span><span
class="o">).</span><span class="na">withSrv</span><span class="o">(</span><span
class="n">LogService</span><span class="o">.</span><span class="na">class</span><span
class="o">,</span> <span class="n">srv</span> <span class="o">-&gt;</span>
<span class="n">srv</span><span class="o">.</span><span class="na">cbi</span><span
class="o">(</span><span class="nl">depHandler:</span><span class="o">:</span><span
class="n">setLog</span><span class="o">)));</span>
     <span class="o">}</span>
 <span class="o">}</span>
@@ -267,7 +268,7 @@ In this case, you can use the "<code>cbi
 <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="nd">@Override</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">ctx</span><span class="o">,</span> <span class="n">DependencyManager</span>
<span class="n">dm</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">Exception</span> <span class="o">{</span>
-    <span class="n">DependencyHandler</span> <span class="n">depHandler</span>
<span class="o">=</span> <span class="k">new</span> <span class="n">DependencyHandler</span><span
class="o">();</span>
+        <span class="n">DependencyHandler</span> <span class="n">depHandler</span>
<span class="o">=</span> <span class="k">new</span> <span class="n">DependencyHandler</span><span
class="o">();</span>
         <span class="n">component</span><span class="o">(</span><span
class="n">comp</span> <span class="o">-&gt;</span> <span class="n">comp</span><span
class="o">.</span><span class="na">impl</span><span class="o">(</span><span
class="n">Hello</span><span class="o">.</span><span class="na">class</span><span
class="o">).</span><span class="na">withSrv</span><span class="o">(</span><span
class="n">LogService</span><span class="o">.</span><span class="na">class</span><span
class="o">,</span> <span class="n">srv</span> <span class="o">-&gt;</span>
<span class="n">srv</span><span class="o">.</span><span class="na">cb</span><span
class="o">(</span><span class="nl">Hello:</span><span class="o">:</span><span
class="n">setLog</span><span class="o">).</span><span class="na">cbi</span><span
class="o">(</span><span class="nl">depHandler:</span><span class="o">:</span><span
class="n">setLog</span><span class="o">)));</span>
     <span class="o">}</span>
 <span class="o">}</span>
@@ -320,11 +321,11 @@ what it has parsed, it will possibly add
         <span class="n">parseXml</span><span class="p">(</span><span
class="n">conf</span><span class="p">.</span><span class="n">get</span><span
class="p">(</span>&quot;<span class="n">some</span><span class="p">.</span><span
class="n">xml</span><span class="p">.</span><span class="n">configuration</span>&quot;<span
class="p">));</span>
     <span class="p">}</span>
 
-<span class="n">void</span> <span class="n">init</span><span class="p">(</span><span
class="n">Component</span> <span class="n">c</span><span class="p">)</span>
<span class="p">{</span> <span class="o">//</span> <span class="n">lifecycle</span>
<span class="n">dm</span> <span class="n">callback</span> <span
class="n">that</span> <span class="n">allow</span> <span class="n">you</span>
<span class="n">to</span> <span class="n">add</span> <span class="n">more</span>
<span class="n">dependencies</span>
-     <span class="k">if</span> <span class="p">(</span><span class="n">xmlConfigurationRequiresEventAdmin</span><span
class="p">)</span> <span class="p">{</span>
+    <span class="n">void</span> <span class="n">init</span><span
class="p">(</span><span class="n">Component</span> <span class="n">c</span><span
class="p">)</span> <span class="p">{</span> <span class="o">//</span>
<span class="n">lifecycle</span> <span class="n">dm</span> <span
class="n">callback</span> <span class="n">that</span> <span class="n">allow</span>
<span class="n">you</span> <span class="n">to</span> <span class="n">add</span>
<span class="n">more</span> <span class="n">dependencies</span>
+    <span class="k">if</span> <span class="p">(</span><span class="n">xmlConfigurationRequiresEventAdmin</span><span
class="p">)</span> <span class="p">{</span>
         <span class="n">component</span><span class="p">(</span><span
class="n">c</span><span class="p">,</span> <span class="n">comp</span>
<span class="o">-&gt;</span> <span class="n">comp</span><span
class="p">.</span><span class="n">withSrv</span><span class="p">(</span><span
class="n">EventAdmin</span><span class="p">.</span><span class="n">class</span><span
class="p">));</span>
-     <span class="p">}</span>
-<span class="p">}</span>
+    <span class="p">}</span>
+    <span class="p">}</span>
 <span class="p">}</span>
 </pre></div>
 
@@ -335,7 +336,7 @@ what it has parsed, it will possibly add
         <span class="n">parseXml</span><span class="o">(</span><span
class="n">conf</span><span class="o">.</span><span class="na">get</span><span
class="o">(</span><span class="s">&quot;some.xml.configuration&quot;</span><span
class="o">));</span>
     <span class="o">}</span>
 
-<span class="kt">void</span> <span class="nf">init</span><span
class="o">(</span><span class="n">Component</span> <span class="n">c</span><span
class="o">)</span> <span class="o">{</span> <span class="c1">//
lifecycle dm callback that allow you to add more dependencies</span>
+    <span class="kt">void</span> <span class="nf">init</span><span
class="o">(</span><span class="n">Component</span> <span class="n">c</span><span
class="o">)</span> <span class="o">{</span> <span class="c1">//
lifecycle dm callback that allow you to add more dependencies</span>
      <span class="k">if</span> <span class="o">(</span><span class="n">xmlConfigurationRequiresEventAdmin</span><span
class="o">)</span> <span class="o">{</span>
     <span class="n">DependencyManager</span> <span class="n">dm</span>
<span class="o">=</span> <span class="n">c</span><span class="o">.</span><span
class="na">getDependencyManager</span><span class="o">();</span>
         <span class="n">ServiceDependency</span> <span class="n">dep</span>
<span class="o">=</span> <span class="n">serviceDependency</span><span
class="o">(</span><span class="n">c</span><span class="o">,</span>
<span class="n">EventAdmin</span><span class="o">.</span><span
class="na">class</span><span class="o">).</span><span class="na">filter</span><span
class="o">(</span><span class="s">&quot;(vendor=felix)&quot;</span><span
class="o">).</span><span class="na">build</span><span class="o">();</span>
@@ -354,7 +355,6 @@ like if they were service dependencies.<
 Now, you want to use for example Vertx.io which allows to build reactive applications on
the JVM. This library wraps asynchronous events behind a CompletableFuture.</p>
 <p>So, naturally, you can write from your init() method something like this:</p>
 <div class="codehilite"><pre><span class="kd">public</span> <span
class="kd">class</span> <span class="nc">HttpServiceImpl</span> <span
class="kd">implements</span> <span class="n">HttpService</span> <span
class="o">{</span>
-
     <span class="c1">// lifecycle dm callback that allow you to add more dependencies</span>
 <span class="kt">void</span> <span class="nf">init</span><span
class="o">(</span><span class="n">Component</span> <span class="n">c</span><span
class="o">)</span> <span class="o">{</span> 
    <span class="n">CompletableFuture</span><span class="o">&lt;</span><span
class="n">HttpServer</span><span class="o">&gt;</span> <span class="n">futureServer</span>
<span class="o">=</span> <span class="n">createServer</span><span
class="o">().</span><span class="na">listenFuture</span><span class="o">();</span>
@@ -366,8 +366,7 @@ Now, you want to use for example Vertx.i
 
 <span class="kt">void</span> <span class="nf">start</span><span
class="o">()</span> <span class="o">{</span>
    <span class="c1">// at this point we are fully started</span>
-<span class="o">}</span>
-
+<span class="o">}</span>   
 <span class="o">}</span>
 </pre></div>
 
@@ -495,7 +494,7 @@ and the service is registered.</p>
 <p>Caution: if you are using a corporate http proxy, you have to fix the Activator
in order to configure the ip addr and port number of your
 http proxy.</p>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1728179 by pderop on Tue, 2 Feb 2016 19:32:17 +0000
+        Rev. 1728227 by pderop on Tue, 2 Feb 2016 21:54:19 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project



Mime
View raw message