felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r979318 - /websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html
Date Tue, 02 Feb 2016 22:06:52 GMT
Author: buildbot
Date: Tue Feb  2 22:06:52 2016
New Revision: 979318

Log:
Staging update by buildbot for felix

Modified:
    websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html

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 22:06:52 2016
@@ -277,7 +277,7 @@ In this case, you can use the "<code>cbi
 
 <h2 id="providing-a-service">Providing a service<a class="headerlink" href="#providing-a-service"
title="Permanent link">&para;</a></h2>
 <p>When a component provides a service with some properties, so far it was necessary
to create a Dictionary and pass it to the <code>Component.setInterface()</code>
method.</p>
-<p>Now you can now pass properties as varargs of properties (a suite of key-value properties):</p>
+<p>Now you can pass properties directly to the <code>provides</code> method
as varargs of properties (a suite of key-value properties):</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>
@@ -287,8 +287,8 @@ In this case, you can use the "<code>cbi
 </pre></div>
 
 
-<p>or if you build your program using the <code>-parameter</code> option,
you can also use the "FluentProperty" lambda that allows to declare
-service properties as a suite of FlientProperty lambdas:</p>
+<p>or if you build your program using the <code>-parameters</code> option,
you can also use the "<code>FluentProperty</code>" lambda that allows to declare
+service properties as a suite of "<code>key -&gt; value</code>" lambdas,
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>
@@ -313,20 +313,19 @@ service properties as a suite of FlientP
 
 <p>Here, we define a Configuration dependency with a "pojo.pid" configuration pid.
So, now, the Pojo will then for example be able to parse an xml from the configuration, and
depending on
 what it has parsed, it will possibly add more dependencies, like this:</p>
-<div class="codehilite"><pre><span class="n">import</span> <span
class="n">static</span> <span class="n">org</span><span class="p">.</span><span
class="n">apache</span><span class="p">.</span><span class="n">felix</span><span
class="p">.</span><span class="n">dm</span><span class="p">.</span><span
class="n">lambda</span><span class="p">.</span><span class="n">DependencyManagerActivator</span><span
class="o">.*</span><span class="p">;</span>
+<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>
 
-<span class="p">:::</span><span class="n">java</span>
-<span class="n">public</span> <span class="n">class</span> <span
class="n">Pojo</span> <span class="p">{</span>
-    <span class="n">void</span> <span class="n">updated</span><span
class="p">(</span><span class="n">Dictionary</span> <span class="n">conf</span><span
class="p">)</span> <span class="n">throws</span> <span class="n">Exception</span>
<span class="p">{</span>
-        <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="kd">public</span> <span class="kd">class</span> <span
class="nc">Pojo</span> <span class="o">{</span>
+    <span class="kt">void</span> <span class="nf">updated</span><span
class="o">(</span><span class="n">Dictionary</span> <span class="n">conf</span><span
class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span>
<span class="o">{</span>
+        <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="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="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">component</span><span class="o">(</span><span
class="n">c</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">withSrv</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>
+<span class="o">}</span>
 </pre></div>
 
 
@@ -337,12 +336,12 @@ what it has parsed, it will possibly add
     <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="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>
-    <span class="n">dm</span><span class="o">.</span><span class="na">add</span><span
class="o">(</span><span class="n">dep</span><span class="o">);</span>
-     <span class="o">}</span>
-<span class="o">}</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>
+            <span class="n">dm</span><span class="o">.</span><span
class="na">add</span><span class="o">(</span><span class="n">dep</span><span
class="o">);</span>
+        <span class="o">}</span>
+    <span class="o">}</span>
 <span class="o">}</span>
 </pre></div>
 
@@ -356,22 +355,22 @@ Now, you want to use for example Vertx.i
 <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>
-   <span class="n">component</span><span class="o">(</span><span
class="n">c</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">withFuture</span><span class="o">(</span><span
class="n">futureService</span><span class="o">,</span> <span class="n">future</span>
<span class="o">-&gt;</span> <span class="n">future</span><span
class="o">.</span><span class="na">cbi</span><span class="o">(</span><span
class="k">this</span><span class="o">::</span><span class="n">serverReady</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="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>
+    <span class="n">component</span><span class="o">(</span><span
class="n">c</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">withFuture</span><span class="o">(</span><span
class="n">futureService</span><span class="o">,</span> <span class="n">future</span>
<span class="o">-&gt;</span> <span class="n">future</span><span
class="o">.</span><span class="na">cbi</span><span class="o">(</span><span
class="k">this</span><span class="o">::</span><span class="n">serverReady</span><span
class="o">)));</span>
+    <span class="o">}</span>
 
-<span class="c1">// Inject our HttpServer that is listening</span>
-<span class="kt">void</span> <span class="nf">serverReady</span><span
class="o">(</span><span class="n">HttpServer</span> <span class="n">server</span><span
class="o">)</span> <span class="o">{</span> <span class="o">...</span>
<span class="o">}</span>
+    <span class="c1">// Inject our HttpServer that is listening</span>
+    <span class="kt">void</span> <span class="nf">serverReady</span><span
class="o">(</span><span class="n">HttpServer</span> <span class="n">server</span><span
class="o">)</span> <span class="o">{</span> <span class="o">...</span>
<span class="o">}</span>
 
-<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="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>
 </pre></div>
 
 
-<p>and your HttpService will be registered only once the server is listening.</p>
+<p>and your HttpService will be call in <code>start</code> and registered
only once the server is listening.</p>
 <h2 id="comparing-two-activators-using-old-and-new-api">Comparing two activators using
old and new API:<a class="headerlink" href="#comparing-two-activators-using-old-and-new-api"
title="Permanent link">&para;</a></h2>
 <p>Assume we have a <code>ServiceConsumer</code> which depends on the following
services:</p>
 <ul>
@@ -494,7 +493,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. 1728227 by pderop on Tue, 2 Feb 2016 21:54:19 +0000
+        Rev. 1728229 by pderop on Tue, 2 Feb 2016 22:06:27 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project



Mime
View raw message