You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by bu...@apache.org on 2012/08/29 15:09:36 UTC

svn commit: r830451 - in /websites/staging/aries/trunk/content: ./ modules/spi-fly.html

Author: buildbot
Date: Wed Aug 29 13:09:35 2012
New Revision: 830451

Log:
Staging update by buildbot for aries

Modified:
    websites/staging/aries/trunk/content/   (props changed)
    websites/staging/aries/trunk/content/modules/spi-fly.html

Propchange: websites/staging/aries/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Wed Aug 29 13:09:35 2012
@@ -1 +1 @@
-1378489
+1378529

Modified: websites/staging/aries/trunk/content/modules/spi-fly.html
==============================================================================
--- websites/staging/aries/trunk/content/modules/spi-fly.html (original)
+++ websites/staging/aries/trunk/content/modules/spi-fly.html Wed Aug 29 13:09:35 2012
@@ -268,20 +268,20 @@
             <!-- Content -->
             <div class="wiki-content"><h1 id="spi-fly">SPI Fly</h1>
 <p>This page describes the SPI Fly component.
-The SPI Fly component is aimed at providing general support for the JRE SPI
-mechanism, including the usage of <tt>java.util.ServiceLoader</tt>, 
-<tt>META-INF/services</tt> and similar methods in OSGi.</p>
+The SPI Fly component is aimed at providing OSGi support for JRE SPI
+mechanisms, including the usage of <tt>java.util.ServiceLoader</tt>, 
+<tt>META-INF/services</tt> and similar methods.</p>
 <p>SPI Fly is the Reference Implementation of the OSGi ServiceLoader Mediator specification, chapter 133 in the <a href="http://www.osgi.org/Download/Release5" title="OSGi Enterprise Specification">OSGi 
 Enterprise Specification</a>, available from version 5.</p>
 <h2 id="the-problem">The Problem</h2>
-<p><tt>java.util.ServiceLoader.load()</tt> and other similar methods such as 
+<p>Java's <tt>java.util.ServiceLoader.load()</tt> and other similar methods such as 
 <tt>sun.misc.Service.providers()</tt>, but also other static finder methods such as the 
 <tt>FactoryFinder.find()</tt> methods try to locate 'service' implementations by looking for 
 resources in the META-INF/services directory of all the jars visible to the 
 <strong><em>Thread Context ClassLoader</em></strong> (TCCL).</p>
-<p>There are a number of issues with this approach in OSGi:</p>
+<p>There are a number of issues with the above mechanisms when used in OSGi:</p>
 <ol>
-<li>The Thread Context ClassLoader is not defined in general in an OSGi context. It can and has to be set by the caller and OSGi cannot enforce that. </li>
+<li>The Thread Context ClassLoader is not defined in general in an OSGi context. It can and has to be set by the caller and OSGi cannot generally enforce that. </li>
 <li>A bundle can't Import-Package META-INF/services as potentially many bundles will contain this pseudo-package and the OSGi framework will only bind a single exporter to an importer for a given package.</li>
 <li>Instantiating an SPI provider generally requires access to internal implementation classes, by exporting these classes an implementing bundle would break its encapsulation. </li>
 <li>Even if an implementation class was exported, importing this class in a consumer bundle would bind it to the specific implementation package provided, which violates the principle of loose coupling.</li>
@@ -290,19 +290,20 @@ resources in the META-INF/services direc
 <p>The SPI Fly project makes it possible to use existing code that uses 
 <tt>ServiceLoader.load()</tt> and similar mechanisms under OSGi.</p>
 <h2 id="making-it-work">Making it Work</h2>
-<p>In order to make the ServiceLoader approach work under OSGi, calling code can be woven
+<p>In order to make ServiceLoader (and other similar SPI or plugin mechanisms) work under OSGi, calling code can be woven
 to set the TCCL to the appropriate providers very briefly, only for the duration of the
 call. The SPI Fly component does precisely this.</p>
-<p>SPI Fly supports two modes of operation:</p>
+<p>SPI Fly supports two modes of configuration:</p>
 <ul>
 <li>OSGi Specification compliant configuration. This is based on OSGi generic requirements and capabilities and 
-provides portability across implementations of this specification, but only covers <tt>java.util.ServiceLoader</tt>. <a href="#specconf">Find it here</a>.</li>
+provides portability across implementations of this specification. However, it only covers <tt>java.util.ServiceLoader</tt>. <a href="#specconf">Find it here</a>.</li>
 <li>If you need to handle cases other than <tt>java.util.ServiceLoader</tt>, such as the various FactoryFinders, 
 <tt>javax.imageio.spi.ServiceRegistry</tt>, <tt>javax.sound.sampled.AudioSystem</tt> or others that use the TCCL
 to find an implementation, you can use the <a href="#specificconf">SPI Fly-specific configuration</a>.</li>
 </ul>
 <p>Additionally, services found in the META-INF/services location in opted-in bundles will be registered in the OSGi Service 
-Registry so that OSGi-aware consumers can simply find them there.</p>
+Registry so that OSGi-aware consumers can simply find them there. This is supported in both the spec-compliant as 
+well as the proprietary configuration modes.</p>
 <h2 id="getting-spi-fly">Getting SPI Fly</h2>
 <h3 id="releases">Releases</h3>
 <p>There are no releases of SPI-Fly at this point in time, but when 
@@ -310,12 +311,12 @@ once released releases will be available
 <h3 id="building-the-code">Building the code</h3>
 <p>The code can be found in
 <a href="http://svn.apache.org/repos/asf/aries/trunk/spi-fly">http://svn.apache.org/repos/asf/aries/trunk/spi-fly</a>.</p>
-<p>To build, use Maven 3.x and run 'mvn install'</p>
-<h1 id="wzxhzdk13configuration-osgi-spec-compliant"><a id="specconf"/>Configuration: OSGi Spec-compliant</h1>
+<p>To build, use Maven 3.x and run <tt>mvn install</tt></p>
+<h1 id="wzxhzdk15configuration-osgi-spec-compliant"><a id="specconf"/>Configuration: OSGi Spec-compliant</h1>
 <p>All the details surrounding this type of configuration are covered in the 
 <a href="http://www.osgi.org/Download/Release5" title="OSGi Enterprise Specification">OSGi Enterprise Specification</a> (from version 5) chapter 133. This section provides a short overview.</p>
 <h2 id="providers">Providers</h2>
-<p>SPI provider bundles opt in to being processed by specifying a requirement on the 
+<p>SPI provider bundles opt in to being registered by specifying a requirement on the 
 <tt>osgi.serviceloader.registrar</tt> extender. This is done by adding the following Bundle Manifest header. Without this they will not be considered by SPI Fly:</p>
 <p><tt>&nbsp;&nbsp;Require-Capability: osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</tt></p>
 <p>Additionally, they need to provide capabilities for all the APIs that are exposed through this mechanism, for example:</p>
@@ -324,7 +325,7 @@ once released releases will be available
 ensure consistent class spaces.</p>
 <p>See the <tt>spi-fly-example-provider2-bundle</tt> for an example of a spec-compliant provider.</p>
 <h2 id="consumers">Consumers</h2>
-<p>A SPI consumer (i.e. a bundle using the <tt>java.util.ServiceLoader.load()</tt> API) needs to specify required capabilities
+<p>An SPI consumer (i.e. a bundle using the <tt>java.util.ServiceLoader.load()</tt> API) needs to specify required capabilities
 in the Required-Capability Manifest header. Two different types of requirements must be specified:</p>
 <ul>
 <li>A requirement on the SPI Fly mechanism. This is stated as follows<br/>
@@ -339,11 +340,12 @@ the cardinality directive.</li>
 <p>All requirements are combined into a single Require-Capability header:</p>
 <p><tt>&nbsp;&nbsp;Require-Capability: osgi.serviceloader; filter:="(osgi.serviceloader=org.apache.aries.spifly.mysvc.MySPIProvider)";cardinality:=multiple,osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)"</tt></p>
 <p>See the <tt>spi-fly-example-client2-bundle</tt> for an example of a spec-compliant consumer.</p>
-<h1 id="wzxhzdk36configuration-spi-fly-specific"><a id="specificconf"/>Configuration: SPI Fly-specific</h1>
+<h1 id="wzxhzdk38configuration-spi-fly-specific"><a id="specificconf"/>Configuration: SPI Fly-specific</h1>
 <p>This section describes how to use SPI Fly's proprietary configuration
 mechanism. It provides more features, but doesn't provide the 
 portability that spec-compliance configuration gives. If you 
-are only using SPI Fly with java.util.ServiceLoader then consider
+are only using SPI Fly with <tt>java.util.ServiceLoader</tt> or you are only using the provided 
+services through the OSGi Service Registry, then consider
 using the <a href="#specconf">spec-compliant</a> configuration for portability.</p>
 <h2 id="providers_1">Providers</h2>
 <p>First for all, SPI Fly needs to be made aware of any bundles that provide the services.
@@ -357,28 +359,30 @@ directory and register them.</li>
 MySvc2.</li>
 </ul>
 <p>Additionally services found in META-INF/services are registered in the OSGi Service 
-Registry. Each service is registered with the <em>spi.provider.url</em> service registration
-property.</p>
+Registry. Each service is registered with the <em>serviceloader.mediator</em> service registration
+property set.</p>
 <p>The <tt>SPI-Provider</tt> header can either be set in the providing bundle itself or in a wrapper bundle
 that holds the original unmodified jar containing the provider internally as a 
 on the <tt>Bundle-ClassPath</tt>.</p>
+<p>See the <tt>spi-fly-example-provider1-bundle</tt> for an example of a provider using this type of configuration.</p>
 <h2 id="consumers_1">Consumers</h2>
-<p>Service consumers also need to opt-in to the process. </p>
+<p>Service consumers also need to opt in to the process. </p>
 <p>To specify a consumer, add the <tt>SPI-Consumer</tt> manifest header to the client bundle. This header 
 will opt-in the bundle to the weaving process where for the duration of the specified call
-the TCCL will be set to the matching provider bundle(s).</p>
+the TCCL will be set to the matching provider bundle(s). Some example SPI-Consumer headers are:</p>
 <ul>
 <li><strong>SPI-Consumer: </strong>* This is a shorthand for 
 <tt>java.util.ServiceLoader#load(java.lang.Class)</tt> and will 
 automatically weave all <tt>ServiceLoader.load(Class)</tt> calls.</li>
-<li><strong>java.util.ServiceLoader#load(java.lang.Class[org.apache.aries.mytest.MySPI])</strong>
+<li><strong>SPI-Consumer: java.util.ServiceLoader#load(java.lang.Class[org.apache.aries.mytest.MySPI])</strong>
 Only process calls to <tt>ServiceLoader.load(Class)</tt> when it is called with 
 <tt>MySPI.class</tt> as argument.</li>
-<li><strong>javax.xml.parsers.DocumentBuilderFactory#newInstance()</strong> weave clients that
+<li><strong>SPI-Consumer: javax.xml.parsers.DocumentBuilderFactory#newInstance()</strong> weave clients that
 call <tt>DocumentBuilderFactory.newInstance()</tt>. </li>
-<li><strong>org.foo.Foo#someMthd(),org.bar.Bar#myMethod()</strong> weave calls to <tt>Foo.someMthd()</tt> and 
-<tt>Bar.myMethod()</tt>. </li>
+<li><strong>SPI-Consumer: org.foo.Foo#someMthd(),org.bar.Bar#myMethod()</strong> weave calls to <tt>Foo.someMthd()</tt> and 
+<tt>Bar.myMethod()</tt>.</li>
 </ul>
+<p>See the <tt>spi-fly-example-client1-bundle/target</tt> for an example of a consumer using this type of configuration. </p>
 <h3 id="special-cases">Special Cases</h3>
 <p>SPI Fly can be used for most SPI provider/lookup systems that use the TCCL pattern to obtain
 implementations. However, some cases some <em>special treatment</em> is needed. This special treatment is often needed when the API itself does not 
@@ -403,20 +407,20 @@ in SPI Fly (yet), but the AudioSystem.ge
 </ul>
 <h1 id="usage">Usage</h1>
 <p>There are currently two ways to use the SPI Fly component. If you have an OSGi 
-4.3 compliant framework that supports WeavingHooks you can use the dynamic weaving approach. </p>
+4.3 (or higher) compliant framework that supports WeavingHooks you can use the dynamic weaving approach. </p>
 <p>If you have an pre-4.3 OSGi framework or don't want to use bytecode weaving at runtime you 
 can use the static weaving approach.</p>
 <h2 id="use-with-dynamic-weaving">Use with Dynamic Weaving</h2>
 <p>Install and start the <tt>org.apache.aries.spifly.dynamic.bundle</tt> into the system. This bundle 
-has a dependency on <tt><a href="http://search.maven.org/#artifactdetails|asm|asm-all|3.2|jar">org.objectweb.asm</a></tt> version 3.2 or newer and on the Aries 
+has a dependency on <tt><a href="http://search.maven.org/#artifactdetails|org.ow2.asm|asm-all|4.0|jar">org.objectweb.asm</a></tt> version 4.0 or newer and on the Aries 
 Util bundle.</p>
 <pre>osgi> ss    
 Framework is launched.    
 id  State       Bundle
 0   ACTIVE      org.eclipse.osgi_3.7.1.R37x_v20110808-1106
 1   ACTIVE      org.objectweb.asm.all_3.2.0
-2   ACTIVE      org.apache.aries.util_0.5.0.SNAPSHOT
-3   ACTIVE      org.apache.aries.spifly.dynamic.bundle_0.4.0.SNAPSHOT
+2   ACTIVE      org.apache.aries.util_1.0.0
+3   ACTIVE      org.apache.aries.spifly.dynamic.bundle_1.0.0
 </pre>
 
 <p>Note that, as with any OSGi Bundle that uses the OSGi 4.3 WeavingHooks, the weaver
@@ -430,10 +434,10 @@ bundle and inserts calls to set the corr
 Provider bundles are still handled dynamically.</p>
 <h3 id="to-statically-weave-a-bundle">To statically weave a bundle</h3>
 <p>The easiest way to invoke the static weaver is to take the <tt>org.apache.aries.spifly.static.tool</tt>
-jar with dependencies. This jar can be created by running <tt>mvn assembly:single</tt> in this maven module.</p>
+jar with dependencies.</p>
 <p>Then run the static tool on any bundle that needs processing:
 <pre>
-java -jar org.apache.aries.spifly.static.tool-0.4-with-dependencies.jar mybundle.jar
+java -jar org.apache.aries.spifly.static.tool-1.0.0-with-dependencies.jar mybundle.jar
 </pre></p>
 <p>This will produce a second bundle with the same name with the _spifly suffix appended, so 
 in this case the generated bundle will be called mybundle_spifly.jar.</p>
@@ -444,8 +448,8 @@ Framework is launched.
 id  State       Bundle
 0   ACTIVE      org.eclipse.osgi_3.6.2.R36x_v20110210
 1   ACTIVE      org.eclipse.osgi.services_3.2.100.v20100503
-2   ACTIVE      org.apache.aries.util_0.5.0.SNAPSHOT
-3   ACTIVE      org.apache.aries.spifly.static.bundle_0.4.0.SNAPSHOT</pre></p>
+2   ACTIVE      org.apache.aries.util_1.0.0
+3   ACTIVE      org.apache.aries.spifly.static.bundle_1.0.0</pre></p>
 <p>Then install and start the statically woven bundle into the system.</p>
 <h2 id="examples">Examples</h2>
 <p>The <tt>spi-fly-examples</tt> directory contains a number of example bundles that can be 
@@ -454,11 +458,11 @@ used for testing or experimenting.</p>
 <ul>
 <li><strong>spi-fly-example-spi-bundle</strong> - a bundle providing an SPI interface used by the other example bundles.</li>
 <li><strong>spi-fly-example-provider1-jar</strong> - a plain jar file providing an implementation of the SPI (via <tt>META-INF/services</tt>).</li>
-<li><strong>spi-fly-example-provider1-bundle</strong> - a bundle that wraps the jar file from the previous bullet and specifies it in its Bundle-ClassPath. This example represents the common case where an existing SPI provider is wrapped as-is in an OSGi bundle.</li>
-<li><strong>spi-fly-example-provider2-bundle</strong> - a bundle that directly provides an SPI service (via <tt>META-INF/services</tt>).</li>
+<li><strong>spi-fly-example-provider1-bundle</strong> - a bundle that wraps the jar file from the previous bullet and specifies it in its Bundle-ClassPath. This example represents the common case where an existing SPI provider is wrapped as-is in an OSGi bundle. This example uses the SPI Fly proprietary configuration.</li>
+<li><strong>spi-fly-example-provider2-bundle</strong> - a bundle that directly provides an SPI service (via <tt>META-INF/services</tt>). This example uses OSGi  specification compliant configuration.</li>
 <li><strong>spi-fly-example-client1-jar</strong> - a plain jar using java.util.ServiceLoader.load() to obtain and invoke all services provided of a certain SPI.</li>
-<li><strong>spi-fly-example-client1-bundle</strong> - a bundle that wraps the jar file from the previous bullet and lists it in its Bundle-ClassPath. This example represents the common case where an existing SPI consumer is wrapped as-is in an OSGi bundle.</li>
-<li><strong>spi-fly-example-client2-bundle</strong> - a bundle that has code that invokes <tt>java.util.ServiceLoader.load()</tt> directly.</li>
+<li><strong>spi-fly-example-client1-bundle</strong> - a bundle that wraps the jar file from the previous bullet and lists it in its Bundle-ClassPath. This example represents the common case where an existing SPI consumer is wrapped as-is in an OSGi bundle. This example uses SPI Fly proprietary configuration.</li>
+<li><strong>spi-fly-example-client2-bundle</strong> - a bundle that has code that invokes <tt>java.util.ServiceLoader.load()</tt> directly. This example uses OSGi specification compliant configuration.</li>
 </ul></div>
             <!-- Content -->
           </td>