You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by bu...@apache.org on 2018/10/09 13:32:06 UTC

svn commit: r1036186 - in /websites/staging/felix/trunk/content: ./ documentation/subprojects/apache-felix-dependency-manager/reference/component-aspect.html

Author: buildbot
Date: Tue Oct  9 13:32:06 2018
New Revision: 1036186

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/reference/component-aspect.html

Propchange: websites/staging/felix/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Tue Oct  9 13:32:06 2018
@@ -1 +1 @@
-1843261
+1843262

Modified: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-aspect.html
==============================================================================
--- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-aspect.html (original)
+++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-aspect.html Tue Oct  9 13:32:06 2018
@@ -88,116 +88,23 @@ h2:hover > .headerlink, h3:hover > .head
   visibility: hidden;
 }
 h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
-<p>Aspects, as part of aspect oriented programming, can be used in a dynamic environment such as OSGi to "extend" existing services and add certain "capabilities" to them. Examples of these are adding a specific caching mechanism to a storage service or implementing logging. Aspects in OSGi can be applied to services and can be added and removed at runtime.</p>
-<p>Aspects allow you to define an "interceptor", or chain of interceptors for a service to add features like caching or logging, etc. An aspect will be applied to any service that matches the specified interface and filter. For each matching service an aspect will be created based on the aspect implementation class. The aspect will be registered with the same interface and properties as the original service, plus any extra properties you supply here. It will also inherit all dependencies, and if you declare the original service as a member it will be injected.</p>
-<h2 id="usage-example-using-annotation">Usage example using annotation<a class="headerlink" href="#usage-example-using-annotation" title="Permanent link">&para;</a></h2>
-<p>The <em>@AspectService</em> annotation allows you to create an aspect service. In this example, a "DatabaseCache" aspect service is used to add caching functionality to an existing Database service.</p>
-<h3 id="sample-code">Sample code<a class="headerlink" href="#sample-code" title="Permanent link">&para;</a></h3>
-<p>First, here is the original Database service:</p>
+<p>Aspects, as part of aspect oriented programming, can be used in a dynamic environment 
+such as OSGi to "extend" existing services and add certain "capabilities" to them. 
+Examples of these are adding a specific caching mechanism to a storage service or 
+implementing logging. Aspects in OSGi can be applied to services and can be added and 
+removed at runtime.</p>
+<p>To define an aspect component, you need to create an <a href="http://felix.staging.apache.org/apidocs/dependencymanager/r12/org/apache/felix/dm/AspectComponent.html">AspectComponent</a> component
+using the DependencyActivatorBase.createAspectComponent() or the DependencyManager.createAspectComponent() method.
+This interface extends the Component interface in order to add extra setters methods needed to define an asoect service component.</p>
+<p>Usage example: </p>
+<p>In this example, a "DatabaseCache" aspect service is used to add caching functionality 
+to an existing Database service. Here is the DatabaseCache aspect service will sit 
+between any Database service consumer and the original Database service:</p>
 <div class="codehilite"><pre><span class="kd">interface</span> <span class="nc">Database</span> <span class="o">{</span>
     <span class="n">String</span> <span class="nf">get</span><span class="o">(</span><span class="n">String</span> <span class="n">key</span><span class="o">);</span>
 <span class="o">}</span>
 
-<span class="nd">@Component</span>
-<span class="kd">class</span> <span class="nc">DatabaseImpl</span> <span class="kd">implements</span> <span class="n">Database</span> <span class="o">{</span>
-    <span class="n">String</span> <span class="nf">get</span><span class="o">(</span><span class="n">String</span> <span class="n">key</span><span class="o">)</span> <span class="o">{</span>
-        <span class="c1">// fetch the key value from the actual database</span>
-    <span class="o">}</span>
-<span class="o">}</span>
-</pre></div>
-
-
-<p>Next, here is the DatabaseCache aspect service, which sits between any Database service consumer and the actual DatabaseImpl service:</p>
-<div class="codehilite"><pre><span class="p">@</span><span class="n">AspectService</span><span class="p">(</span><span class="n">ranking</span><span class="p">=</span>10<span class="p">)</span>
-<span class="n">class</span> <span class="n">DatabaseCache</span> <span class="n">implements</span> <span class="n">Database</span> <span class="p">{</span>
-    <span class="n">volatile</span> <span class="n">Database</span> <span class="n">originalDatabase</span><span class="p">;</span> <span class="o">//</span> <span class="n">injected</span>
-
-    <span class="p">@</span><span class="n">ServiceDependency</span><span class="p">(</span><span class="n">required</span><span class="p">=</span><span class="n">false</span><span class="p">)</span>
-    <span class="n">volatile</span> <span class="n">LogService</span> <span class="nb">log</span><span class="p">;</span>
-
-    <span class="n">String</span> <span class="n">get</span><span class="p">(</span><span class="n">String</span> <span class="n">key</span><span class="p">)</span> <span class="p">{</span>
-        <span class="n">String</span> <span class="n">value</span> <span class="p">=</span> <span class="n">cache</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">);</span>
-        <span class="k">if</span> <span class="p">(</span><span class="n">value</span> <span class="o">==</span> <span class="n">null</span><span class="p">)</span> <span class="p">{</span>
-            <span class="n">value</span> <span class="p">=</span> <span class="n">this</span><span class="p">.</span><span class="n">originalDatabase</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">);</span>
-            <span class="n">store</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">);</span>
-        <span class="p">}</span>
-        <span class="k">return</span> <span class="n">value</span><span class="p">;</span>
-    <span class="p">}</span>
-    <span class="p">...</span> 
-<span class="p">}</span>
-</pre></div>
-
-
-<p>The aspect service, when started will be bound to the original Database service and will be reinjected to any Database service consumer. For example, the following Database service client will be reinjected with the aspect service in the volatile field:</p>
-<div class="codehilite"><pre><span class="nd">@Component</span> 
-<span class="kd">class</span> <span class="nc">DatabaseClient</span> <span class="o">{</span>
-    <span class="nd">@ServiceDependency</span>
-    <span class="kd">volatile</span> <span class="n">Database</span> <span class="n">dbase</span><span class="o">;</span>
-
-    <span class="o">....</span>
-<span class="o">}</span>
-</pre></div>
-
-
-<p>The Database client can also define a "swap" callback in order to be notified when the aspect service is injected:</p>
-<div class="codehilite"><pre><span class="nd">@Component</span> 
-<span class="kd">class</span> <span class="nc">DatabaseClient</span> <span class="o">{</span>
-    <span class="nd">@ServiceDependency</span><span class="o">(</span><span class="n">swap</span><span class="o">=</span><span class="s">&quot;swapDatabase&quot;</span><span class="o">)</span>
-    <span class="kd">volatile</span> <span class="n">Database</span> <span class="n">dbase</span><span class="o">;</span>
-
-    <span class="kt">void</span> <span class="nf">swapDatabase</span><span class="o">(</span><span class="n">Database</span> <span class="n">oldDatabase</span><span class="o">,</span> <span class="n">Database</span> <span class="n">newDatabase</span><span class="o">)</span> <span class="o">{</span>
-        <span class="k">this</span><span class="o">.</span><span class="na">dbase</span> <span class="o">=</span> <span class="n">newDatabase</span><span class="o">;</span>
-    <span class="o">}</span>
-
-    <span class="o">....</span>
-<span class="o">}</span>
-</pre></div>
-
-
-<h3 id="annotation-attributes">Annotation attributes<a class="headerlink" href="#annotation-attributes" title="Permanent link">&para;</a></h3>
-<hr />
-<p><strong><code>ranking</code></strong>  <br />
-<em>Required</em>: No  <br />
-<em>Default</em>: --  </p>
-<p>Sets the ranking of this aspect. Since aspects are chained, the ranking 
-defines the order in which they are chained. Chain ranking is implemented as 
-a service ranking so service lookups automatically retrieve the top of the 
-chain.</p>
-<hr />
-<p><strong><code>service</code></strong>  <br />
-<em>Required</em>: No  <br />
-<em>Default</em>: all directly implemented interfaces.  </p>
-<p>Sets the service interface to apply the aspect to. By default, the directly 
-implemented interface is used.</p>
-<hr />
-<p><strong><code>filter</code></strong>  <br />
-<em>Required</em>: No  <br />
-<em>Default</em>: --</p>
-<p>Sets the filter condition to use with the service interface this aspect is 
-applying to.</p>
-<hr />
-<p><strong><code>properties</code></strong>  <br />
-<em>Required</em>: No  <br />
-<em>Default</em>: --</p>
-<p>Sets Additional properties to use with the aspect service registration.</p>
-<hr />
-<p><strong><code>field</code></strong>  <br />
-<em>Required</em>: No  <br />
-<em>Default</em>: --</p>
-<p>Sets the field name where to inject the original service. By default, the original service is injected in any attributes in the aspect implementation that are of the same type as the aspect interface.</p>
-<hr />
-<p><strong><code>factoryMethod</code></strong>  <br />
-<em>Required</em>: No  <br />
-<em>Default</em>: --</p>
-<p>Sets the static method used to create the aspect service implementation 
-instance. The default constructor of the annotated class is used. 
-The factoryMethod can be used to provide a specific aspect implements, 
-like a DynamicProxy.</p>
-<h2 id="usage-example-using-api">Usage example using API<a class="headerlink" href="#usage-example-using-api" title="Permanent link">&para;</a></h2>
-<p>You can use the org.apache.felix.dependencymanager.AspectComponent interface which defines all the aspect parameters.
-The AspectComponent can be created using the DependencyManagerActivatorBase or DependencyManager createAspectComponent().</p>
-<h3 id="sample-code_1">Sample code<a class="headerlink" href="#sample-code_1" title="Permanent link">&para;</a></h3>
-<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Activator</span> <span class="kd">extends</span> <span class="n">DependencyActivatorBase</span> <span class="o">{</span>
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">Activator</span> <span class="kd">extends</span> <span class="n">DependencyActivatorBase</span> <span class="o">{</span>
      <span class="o">&amp;</span><span class="n">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">context</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">aspectComponent</span> <span class="o">=</span> <span class="n">createAspectComponent</span><span class="o">()</span>
@@ -208,22 +115,8 @@ The AspectComponent can be created using
      <span class="o">}</span>
 <span class="o">}</span>
 </pre></div>
-
-
-<h2 id="usage-example-using-lambda-api">Usage example using Lambda API<a class="headerlink" href="#usage-example-using-lambda-api" title="Permanent link">&para;</a></h2>
-<p>When using the Dependency Manager Lambda API, the ogr.apache.felix.dm.lambda.DependencyManagerActivator.aspect() method can be used to define an aspect service.</p>
-<h3 id="sample-code_2">Sample code<a class="headerlink" href="#sample-code_2" title="Permanent link">&para;</a></h3>
-<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">org.apache.felix.dm.DependencyManager</span><span class="o">;</span>
-<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">DependencyManagerActivator</span> <span class="o">{</span>
-    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">init</span><span class="o">(</span><span class="n">BundleContext</span> <span class="n">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">aspect</span><span class="o">(</span><span class="n">Database</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">asp</span> <span class="o">-&gt;</span> <span class="n">asp</span><span class="o">.</span><span class="na">impl</span><span class="o">(</span><span class="n">DatabaseCache</span><span class="o">.</span><span class="na">class</span><span class="o">).</span><span class="na">rank</span><span class="o">(</span><span class="mi">10</span><span class="o">).</span><span class="na">withSvc</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="kc">false</span><span class="o">));</span>
-    <span class="o">}</span>
- <span class="o">}</span>
-</pre></div>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1842519 by pderop on Mon, 1 Oct 2018 16:58:10 +0000
+        Rev. 1843262 by pderop on Tue, 9 Oct 2018 13:31:49 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project