felix-commits mailing list archives

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

Log:
Staging update by buildbot for felix

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

Propchange: websites/staging/felix/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Tue Feb  2 19:32:55 2016
@@ -1 +1 @@
-1726988
+1728179

Modified: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager.html
==============================================================================
--- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager.html (original)
+++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager.html Tue Feb  2 19:32:55 2016
@@ -118,6 +118,7 @@ h2:hover > .headerlink, h3:hover > .head
 <li><a href="apache-felix-dependency-manager/guides/performance-tuning.html">Performance Tuning</a></li>
 <li><a href="apache-felix-dependency-manager/guides/development.html">Development</a></li>
 <li><a href="apache-felix-dependency-manager/guides/design-patterns.html">Design Patterns</a></li>
+<li>[Dependency Manager Lambda]((apache-felix-dependency-manager/guides/dm-lambda.html)</li>
 <li><a href="apache-felix-dependency-manager/guides/resources.html">Resource Adapters</a></li>
 <li><a href="apache-felix-dependency-manager/guides/javadocs.html">Javadocs</a></li>
 </ul>
@@ -143,7 +144,7 @@ h2:hover > .headerlink, h3:hover > .head
 <li><a href="apache-felix-dependency-manager/reference/external-links.html">External Links and Articles</a></li>
 </ul>
       <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. 1728179 by pderop on Tue, 2 Feb 2016 19:32:17 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project

Added: 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 (added)
+++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/guides/dm-lambda.html Tue Feb  2 19:32:55 2016
@@ -0,0 +1,507 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE- 2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+  <head>
+    <title>Apache Felix - Dependency Manager Lambda</title>
+    <link rel="icon" href="/res/favicon.ico">
+    <link rel="stylesheet" href="/res/site.css" type="text/css" media="all">
+    <link rel="stylesheet" href="/res/codehilite.css" type="text/css" media="all">
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+  </head>
+  <body>
+    <div class="title">
+      <div class="logo">
+        <a href="http://felix.apache.org/">
+          <img border="0" alt="Apache Felix" src="/res/logo.png">
+        </a>
+      </div>
+      <div class="header">
+        <a href="http://www.apache.org/">
+          <img border="0" alt="Apache" src="/res/apache.png">
+        </a>
+      </div>
+    </div>
+    
+    <div class="menu"> 
+      <style type="text/css">
+/* The following code is added by mdx_elementid.py
+   It was originally lifted from http://subversion.apache.org/style/site.css */
+/*
+ * Hide class="elementid-permalink", except when an enclosing heading
+ * has the :hover property.
+ */
+.headerlink, .elementid-permalink {
+  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 href="/news.html">News</a>  <br />
+<a href="/license.html">License</a>  <br />
+<a href="/downloads.cgi">Downloads</a>  <br />
+<a href="/documentation.html">Documentation</a>  <br />
+<a href="/mailinglists.html">Mailing Lists</a>  <br />
+<a href="/documentation/community/contributing.html">Contributing</a>  <br />
+<a href="/sitemap.html">Site Map</a>  <br />
+<a href="http://www.apache.org/">ASF</a>  <br />
+<a href="http://www.apache.org/security/">Security</a>  <br />
+<a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a>  <br />
+<a href="http://www.apache.org/foundation/thanks.html">Sponsors</a>    </p>
+<iframe
+    src="http://www.apache.org/ads/button.html"
+    style="border-width:0; float: left"
+    frameborder="0"
+    scrolling="no"
+    width="135"
+    height="135">
+</iframe>
+    </div>
+    
+    <div class="main">
+      <div class="breadcrump" style="font-size: 80%;">
+        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>&nbsp;&raquo&nbsp;<a href="/documentation/subprojects.html">Apache Felix Subproject Documentation</a>&nbsp;&raquo&nbsp;<a href="/documentation/subprojects/apache-felix-dependency-manager.html">Apache Felix Dependency Manager</a>
+      </div>
+
+      <h1>Dependency Manager Lambda</h1>
+      <style type="text/css">
+/* The following code is added by mdx_elementid.py
+   It was originally lifted from http://subversion.apache.org/style/site.css */
+/*
+ * Hide class="elementid-permalink", except when an enclosing heading
+ * has the :hover property.
+ */
+.headerlink, .elementid-permalink {
+  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>Since the R7 version, a new dm-lambda library has been introduced in the DM distribution. This new library allows to programmatically declare OSGi components
+using a bit more fluent, concise and type-safe API that is based on Java8 Lambda expressions and other goodies like method references.</p>
+<h2 id="principle">Principle<a class="headerlink" href="#principle" title="Permanent link">&para;</a></h2>
+<p>The new library is based on the <code>builder</code> design pattern applied to java8 lambdas. Basically, you call a chain of methods from a fluent <code>builder</code>, and at the end of the chain, you call
+<code>build()</code> which returns the actual DM objects that you already know from the original DM API. We'll see later that using lambdas you can then build the objects and add them to
+the DependencyManager class automatically.</p>
+<p>The new API is provided by the <code>org.apache.felix.dependencymanager.lambda.jar</code> bundle. the following builders are currently supported:</p>
+<ul>
+<li>ComponentBuilder: it is used to build some instances of the org.apache.felix.dm.Component interface.</li>
+<li>ServiceDependencyBuilder: builds some instances of org.apache.felix.dm.ServiceDependency.</li>
+<li>ConfigurationDependencyBuiler: builds some instances of org.apache.felix.dm.ConfigurationDependency.</li>
+<li>BundleAdapterBuilder: builds some DM bundle adapters.</li>
+<li>ServiceAdapterBuilder.java: builds some instances of DM service adapters.</li>
+<li>FactoryPidAdapterBuilder: builds some instances of DM factory pid adapters.</li>
+<li>FutureDependencyBuilder: it's a new feature, allowing to "wait for" an asynchronous event represented by a standard jdk8 <code>CompletableFuture</code> object.</li>
+</ul>
+<p>(There is currently no builders for DM ResourceDependency and ResourceAdapter objects, but they will be supported soon).</p>
+<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>
+
+<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="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
+<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>
+<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">ComponentBuilder</span> <span class="n">comp</span><span class="o">)</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="o">}</span>
+</pre></div>
+
+
+<p>And here is a more concise version where the type of the lambda parameter is not declared:</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="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<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>
+<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="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>The above example adds a service dependency on a LogService with a service filter. Here is a more concise version where the type of the <code>srv</code> lambda parameter is not declared:</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="n">srv</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>
+
+
+<p>If you depend on multiple required services (with no 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="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>
+</pre></div>
+
+
+<h2 id="defining-service-dependency-components-callbacks">Defining Service Dependency Component's callbacks<a class="headerlink" href="#defining-service-dependency-components-callbacks" title="Permanent link">&para;</a></h2>
+<p>By default, service dependencies are auto injected in class fields (you can configure the name of the class field where the dependency should be injected).
+But like in the current DM API, you can specify callbacks on the component implementation class using the "<code>cb</code>" <code>ServiceDependencyBuilder</code> method:</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="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="s">&quot;setLog&quot;</span><span class="o">)));</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>The <code>cb</code> method accepts a varargs of strings (up to 4 method names):</p>
+<ol>
+<li>when using one argument, the first argument is used as the <code>add</code> callback.</li>
+<li>when using two argument, the first argument is used as the <code>add</code> callback, and the second one as the <code>remove</code> callback.</li>
+<li>when using three arguments, the first argument is used as the <code>add</code> callback, the second one as the "change" callback, and the third one as the <code>remove</code> callback.</li>
+<li>when using four arguments, the given argument is used as the <code>add</code> callback, the second one as the "change" callback, the third one as the <code>remove</code> callback, and the last one as the <code>swap</code> callback.</li>
+</ol>
+<p>The add/change/remove callbacks accepts the following kind of method signatures ("S" represents the type of the service dependency):</p>
+<div class="codehilite"><pre><span class="n">method</span><span class="p">(</span><span class="n">S</span> <span class="n">service</span><span class="p">)</span>
+<span class="n">method</span><span class="p">(</span><span class="n">S</span> <span class="n">service</span><span class="p">,</span> <span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">serviceProperties</span><span class="p">)</span>
+<span class="n">method</span><span class="p">(</span><span class="n">S</span> <span class="n">service</span><span class="p">,</span> <span class="n">Dictionary</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">serviceProperties</span><span class="p">)</span>
+<span class="n">method</span><span class="p">(</span><span class="n">ServiceReference</span><span class="o">&lt;</span><span class="n">S</span><span class="o">&gt;</span> <span class="n">serviceRef</span><span class="p">,</span> <span class="n">S</span> <span class="n">service</span><span class="p">),</span>
+<span class="n">method</span><span class="p">(</span><span class="n">ServiceReference</span><span class="o">&lt;</span><span class="n">S</span><span class="o">&gt;</span> <span class="n">serviceRef</span><span class="p">)</span>
+<span class="n">method</span><span class="p">(</span><span class="n">Component</span> <span class="n">serviceComponent</span><span class="p">)</span>
+<span class="n">method</span><span class="p">(</span><span class="n">Component</span> <span class="n">serviceComponent</span><span class="p">,</span> <span class="n">ServiceReference</span><span class="o">&lt;</span><span class="n">S</span><span class="o">&gt;</span> <span class="n">serviceRef</span><span class="p">)</span>
+<span class="n">method</span><span class="p">(</span><span class="n">Component</span> <span class="n">serviceComponent</span><span class="p">,</span> <span class="n">S</span> <span class="n">service</span><span class="p">)</span> 
+<span class="n">method</span><span class="p">(</span><span class="n">Component</span> <span class="n">serviceComponent</span><span class="p">,</span> <span class="n">ServiceReference</span><span class="o">&lt;</span><span class="n">S</span><span class="o">&gt;</span> <span class="n">serviceRef</span><span class="p">,</span> <span class="n">S</span> <span class="n">service</span><span class="p">)</span>
+</pre></div>
+
+
+<p>And the "swap" callbacks accepts the following method signatures:</p>
+<div class="codehilite"><pre><span class="n">swapMethod</span><span class="p">(</span><span class="n">S</span> <span class="n">oldService</span><span class="p">,</span> <span class="n">S</span> <span class="n">newService</span><span class="p">)</span>
+<span class="n">swapMethod</span><span class="p">(</span><span class="n">ServiceReference</span><span class="o">&lt;</span><span class="n">S</span><span class="o">&gt;</span> <span class="n">oldRef</span><span class="p">,</span> <span class="n">S</span> <span class="n">old</span><span class="p">,</span> <span class="n">ServiceReference</span><span class="o">&lt;</span><span class="n">S</span><span class="o">&gt;</span> <span class="n">newRef</span><span class="p">,</span> <span class="n">S</span> <span class="n">newService</span><span class="p">)</span>
+<span class="n">swapMethod</span><span class="p">(</span><span class="n">Component</span> <span class="n">component</span><span class="p">,</span> <span class="n">S</span> <span class="n">oldService</span><span class="p">,</span> <span class="n">S</span> <span class="n">newService</span><span class="p">)</span>
+<span class="n">swapMethod</span><span class="p">(</span><span class="n">Component</span> <span class="n">component</span><span class="p">,</span> <span class="n">ServiceReference</span><span class="o">&lt;</span><span class="n">S</span><span class="o">&gt;</span> <span class="n">oldRef</span><span class="p">,</span> <span class="n">S</span> <span class="n">old</span><span class="p">,</span> <span class="n">ServiceReference</span><span class="o">&lt;</span><span class="n">S</span><span class="o">&gt;</span> <span class="n">newRef</span><span class="p">,</span> <span class="n">S</span> <span class="n">newService</span><span class="p">)</span>
+</pre></div>
+
+
+<p>Now you can also use a more type-safe callback using a Java 8 method reference:</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="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="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>or:</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="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="nl">Hello:</span><span class="o">:</span><span class="n">unsetLog</span><span class="o">)));</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h2 id="defining-service-dependency-object-instance-callback">Defining Service Dependency Object instance callback<a class="headerlink" href="#defining-service-dependency-object-instance-callback" title="Permanent link">&para;</a></h2>
+<p>Sometimes, you want to inject the dependency to a seperate object that is not part of the component implementation classes.
+In this case, you can use the "<code>cbi</code>" method (which stands for "<code>callback instance</code>").</p>
+<p>For example, the following example injects a dependency in a DependencyHandler instance:</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">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>
+</pre></div>
+
+
+<p>or using method reference:</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">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>
+</pre></div>
+
+
+<p>You can chain multiple callbacks:</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">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>
+</pre></div>
+
+
+<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>
+<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">provides</span><span class="o">(</span><span class="n">HelloService</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="s">&quot;p1&quot;</span><span class="o">,</span> <span class="s">&quot;v1&quot;</span><span class="o">,</span> <span class="s">&quot;p2&quot;</span><span class="o">,</span> <span class="mi">123</span><span class="o">));</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</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>
+<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">provides</span><span class="o">(</span><span class="n">HelloService</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">p1</span> <span class="o">-&gt;</span> <span class="s">&quot;v1&quot;</span><span class="o">,</span> <span class="n">p2</span> <span class="o">-&gt;</span> <span class="mi">123</span><span class="o">));</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h2 id="managing-components-outside-of-activators">Managing components outside of Activators.<a class="headerlink" href="#managing-components-outside-of-activators" title="Permanent link">&para;</a></h2>
+<p>You can create Components outside of the Activator by using some static factory methods from the <code>DependencyManagerActivator</code> class.</p>
+<p>For example, considere a use case where you want to retrieve some informations from some already injected services, and you then want to dynamically add more dependencies from your
+<code>init</code> component callback. First let's look at the Activator:</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">Pojo</span><span class="o">.</span><span class="na">class</span><span class="o">).</span><span class="na">withCnf</span><span class="o">(</span><span class="s">&quot;pojo.pid&quot;</span><span class="o">));</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<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>
+
+<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="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>
+</pre></div>
+
+
+<p>The available variety of factory methods allows you to also create some DM objects and add them manually, like:</p>
+<div class="codehilite"><pre><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="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="o">}</span>
+</pre></div>
+
+
+<h2 id="completablefuture-dependency">CompletableFuture dependency.<a class="headerlink" href="#completablefuture-dependency" title="Permanent link">&para;</a></h2>
+<p>The new library provides a new feature; you can now make your component depend on the result of a jdk8 <code>CompletableFuture</code>.
+CompletableFuture java8 class provides an asynchronous event-driven model and you can now define dependencies on any asynchronous events,
+like if they were service dependencies.</p>
+<p>Assume you develop an Http Service and you want to register it in the OSGi service registry only once the service is listening on port 80.
+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>
+   <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="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>
+<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>
+<li>a required <code>ServiceProvider</code>: with <code>(p1=v1)</code> service filter and using a "setProvider" callback.</li>
+<li>a Configuration with pid=<code>org.apache.felix.dm.lambda.samples.hello.ServiceConsumer</code>.</li>
+</ul>
+<p>Now assume we have <code>ServiceProvider</code> provided with p1="v1" and p2=123 service properties; and the provider also depends on:</p>
+<ul>
+<li>a required <code>LogService</code> service (injected in class fields).</li>
+<li>a required <code>EventAdmin</code> service  (injected in class fields).</li>
+</ul>
+<p>Then we have the following typical Activator (we define both components in the same Activator for simplicity):</p>
+<div class="codehilite"><pre><span class="n">import</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">DependencyActivatorBase</span><span class="p">;</span>
+<span class="p">...</span>
+
+<span class="p">:::</span><span class="n">java</span>
+<span class="n">public</span> <span class="n">class</span> <span class="n">Activator</span> <span class="n">extends</span> <span class="n">DependencyActivatorBase</span> <span class="p">{</span>
+    <span class="p">@</span><span class="n">Override</span>
+    <span class="n">public</span> <span class="n">void</span> <span class="n">init</span><span class="p">(</span><span class="n">BundleContext</span> <span class="n">ctx</span><span class="p">,</span> <span class="n">DependencyManager</span> <span class="n">dm</span><span class="p">)</span> <span class="n">throws</span> <span class="n">Exception</span> <span class="p">{</span>
+        <span class="o">//</span> <span class="n">Declare</span> <span class="n">our</span> <span class="n">Consumer</span> <span class="n">component</span>
+
+        <span class="n">Component</span> <span class="n">consumer</span> <span class="p">=</span> <span class="n">dm</span><span class="p">.</span><span class="n">createComponent</span><span class="p">()</span>
+            <span class="p">.</span><span class="n">setImplementation</span><span class="p">(</span><span class="n">ServiceConsumer</span><span class="p">.</span><span class="n">class</span><span class="p">)</span>
+        <span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">createServiceDependency</span><span class="p">().</span><span class="n">setService</span><span class="p">(</span><span class="n">ServiceProvider</span><span class="p">.</span><span class="n">class</span><span class="p">,</span> &quot;<span class="p">(</span><span class="n">p1</span><span class="p">=</span><span class="n">v1</span><span class="p">)</span>&quot;<span class="p">).</span><span class="n">setRequired</span><span class="p">(</span><span class="n">true</span><span class="p">).</span><span class="n">setCallbacks</span><span class="p">(</span>&quot;<span class="n">setProvider</span>&quot;<span class="p">,</span> <span class="n">null</span><span class="p">))</span>
+        <span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">createConfigurationDependency</span><span class="p">().</span><span class="n">setPid</span><span class="p">(</span>&quot;<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">samples</span><span class="p">.</span><span class="n">hello</span><span class="p">.</span><span class="n">ServiceConsumer</span>&quot;<span class="p">));</span>
+        <span class="n">dm</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">consumer</span><span class="p">);</span>
+
+       <span class="o">//</span> <span class="n">Declare</span> <span class="n">our</span> <span class="n">ServiceProvider</span> <span class="n">service</span> <span class="n">component</span>
+
+       <span class="n">Properties</span> <span class="k">properties</span> <span class="p">=</span> <span class="n">new</span> <span class="n">Properties</span><span class="p">();</span>
+       <span class="n">Properties</span><span class="p">.</span><span class="n">put</span><span class="p">(</span>&quot;<span class="n">p1</span>&quot;<span class="p">,</span> &quot;<span class="n">v1</span>&quot;<span class="p">);</span>
+       <span class="k">properties</span><span class="p">.</span><span class="n">put</span><span class="p">(</span>&quot;<span class="n">p2</span>&quot;<span class="p">,</span> 123<span class="p">);</span>
+       <span class="n">Component</span> <span class="n">provider</span> <span class="p">=</span> <span class="n">dm</span><span class="p">.</span><span class="n">createComponent</span><span class="p">()</span>
+           <span class="p">.</span><span class="n">setImplementation</span><span class="p">(</span><span class="n">ServiceProviderImpl</span><span class="p">.</span><span class="n">class</span><span class="p">)</span>
+           <span class="p">.</span><span class="n">setInterface</span><span class="p">(</span><span class="n">ServiceProvider</span><span class="p">.</span><span class="n">class</span><span class="p">.</span><span class="n">getName</span><span class="p">(),</span> <span class="k">properties</span><span class="p">)</span>
+           <span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">createServiceDependency</span><span class="p">().</span><span class="n">setService</span><span class="p">(</span><span class="n">LogService</span><span class="p">.</span><span class="n">class</span><span class="p">).</span><span class="n">setRequired</span><span class="p">(</span><span class="n">true</span><span class="p">))</span>
+           <span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">createServiceDependency</span><span class="p">().</span><span class="n">setService</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="n">null</span><span class="p">).</span><span class="n">setRequired</span><span class="p">(</span><span class="n">true</span><span class="p">));</span>
+       <span class="n">dm</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">provider</span><span class="p">);</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>Now, let's rework the above example, using the new dm-lambda API:</p>
+<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="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">DependencyManagerActivator</span> <span class="o">{</span>
+    <span class="nd">@Override</span>
+    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">activate</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+        <span class="c1">// Declare our Consumer component</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">ServiceConsumer</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">ServiceProvider</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">filter</span><span class="o">(</span><span class="s">&quot;(p1=v1)&quot;</span><span class="o">).</span><span class="na">cb</span><span class="o">(</span><span class="nl">ServiceConsumer:</span><span class="o">:</span><span class="n">setProvider</span><span class="o">))</span>
+    <span class="o">.</span><span class="na">withCnf</span><span class="o">(</span><span class="n">ServiceConsumer</span><span class="o">.</span><span class="na">class</span><span class="o">));</span>
+
+        <span class="c1">// Declare our ServiceProvider service component:</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">ServiceProviderImpl</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
+            <span class="o">.</span><span class="na">provides</span><span class="o">(</span><span class="n">ServiceProvider</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">p1</span> <span class="o">-&gt;</span> <span class="s">&quot;v1&quot;</span><span class="o">,</span> <span class="n">p2</span> <span class="o">-&gt;</span> <span class="mi">123</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="n">EventAdmin</span><span class="o">.</span><span class="na">class</span><span class="o">));</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h2 id="sample-codes">Sample codes<a class="headerlink" href="#sample-codes" title="Permanent link">&para;</a></h2>
+<p>many samples codes are available from the distribution source release: Please take a look at the following:</p>
+<h3 id="orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasampleshello">org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/hello/<a class="headerlink" href="#orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasampleshello" title="Permanent link">&para;</a></h3>
+<p>This sample provides a DM Activator declaring one service consumer and a service provider. The
+ServiceConsumer is also depending on a configuration pid  (see org.apache.felix.dependencymanager.samples.hello.Configurator).</p>
+<h3 id="orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplescompositefactory">org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/compositefactory/<a class="headerlink" href="#orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplescompositefactory" title="Permanent link">&para;</a></h3>
+<p>This Activator is an example usage of DM composite components. A composite component is implemented
+using a composition of multiple object instances, which are used to implement a given service.</p>
+<p>The sample also uses a Factory approach in order to instantiate the composition of objects: A
+"CompositionManager" is first injected with a Configuration that can possibly be used to create
+and configure all the composites.</p>
+<p>Dependencies are injected is some of the component implementation instances, using java8 method references. For instance,
+the LogService is only injected in the ProviderImpl and the ProviderComposite1 class and not in the ProviderComposite2 class.</p>
+<h3 id="orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplesdevice">org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/device/<a class="headerlink" href="#orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplesdevice" title="Permanent link">&para;</a></h3>
+<p>This is an example showing a Dependency Manager "Adapter" in action. Two kinds of services are
+registered in the registry: some Device, and some DeviceParameter services. For each Device (having
+a given id), there is also a corresponding "DeviceParameter" service, having the same id.</p>
+<p>Then a "DeviceAccessImpl" adapter service is defined: it is used to "adapt" the "Device" service to
+a "DeviceAccess" service, which provides the union of each pair of Device/DeviceParameter having the
+same device.id . The adapter also dynamically propagate the service properties of the adapted Device
+service.</p>
+<h3 id="orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplesdictionary">org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/dictionary/<a class="headerlink" href="#orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplesdictionary" title="Permanent link">&para;</a></h3>
+<p>This sample shows a "SpellChecker" application which provides a
+"dictionary:spellcheck" GOGO shell command. The GOGO "dictionary:spellcheck" command accepts a
+string as parameter, which is checked for proper exactness. The SpellChecker class has a
+required/multiple (1..N) dependency over every available "DictionaryService" services, which are
+internally used by the SpellChecker command, when checking word exactness.</p>
+<p>A DictionaryService is defined using a FactoryConfigurationAdapterService , allowing to instantiate
+many "DictionaryService" instances for each configuration that are added to the
+factory pid "Spell Checker Configuration (api)" from web console.
+The factory pid configuration metatypes are defined using the bnd "metatype" annotations
+(see DictionaryConfiguration.java).</p>
+<p>The DictionaryService is decorated with a DictionaryAspect, which you can instantiate by adding a
+configuration to the "Spell Checker Aspect Dictionary (api)" pid from web console. The
+aspect configuration metatype is also declared using the bnd metatype annotations (see
+DictionaryAspectConfiguration.java). </p>
+<p>Before running this sample, go to webconsole, and add some words in the Spell Checker Configuration (api) factory PID, and
+in the Spell Checker Aspect Dictionary (api) PID.</p>
+<p>Then go to gogo shell, and type dm help. You will normally see the dictionary:spellcheck command.
+Type dictionary:spellcheck with some words configured either in the spell checker configuration, or in the spell checker aspect configuration,
+and the dictionary will check for proper word exactness in the configuration.</p>
+<h3 id="orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplesfactory">org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/factory/<a class="headerlink" href="#orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplesfactory" title="Permanent link">&para;</a></h3>
+<p>This sample is an example usage of DM components that are created using a Factory object. 
+The Factory is defined using java8 method references.</p>
+<h3 id="orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplesfuture">org.apache.felix.dependencymanager.lambda.samples/src/org/apache/felix/dm/lambda/samples/future/<a class="headerlink" href="#orgapachefelixdependencymanagerlambdasamplessrcorgapachefelixdmlambdasamplesfuture" title="Permanent link">&para;</a></h3>
+<p>The purpose of this sample is to show an example usage of the new "CompletableFuture" dependency that has been
+added in the dm-lambda library. CompletableFuture java8 class provides functional operations and promotes an asynchronous event-driven model.</p>
+<p>In such model, you can use the new dm-lambda library to add dependencies on asynchronous events using the standard JDK CompletableFuture class.</p>
+<p>In this example, the Activator first defines a PageLink component that is used to download a given page from the web. The service then parses 
+the content of the page and returns all available hrefs (links) found from the web page.</p>
+<p>The PageLink is initialized with the Felix web site URL, which is asynchronously downloaded from the PageLink::init method, using a CompletableFuture. 
+The CF is then added as a "FutureDependency" in the PageLinkImpl.init() method, and when the CF completes, the PageLinkImpl.start() callback is invoked 
+and the service is registered.</p>
+<p>The Activator is then getting injected with the PageLink service, and displays the links (hrefs) found from the Felix web site.</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
+      </div>
+      <div class="trademarkFooter"> 
+        Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project
+        logo are trademarks of The Apache Software Foundation. All other marks mentioned
+        may be trademarks or registered trademarks of their respective owners.
+      </div>
+    </div>
+  </body>
+</html>



Mime
View raw message