blob: 3cb0d4a91a809efb5e71337f37e7f5a9e1229d80 [file] [log] [blame]
<!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 - iPOJO Hierarchical Composition Overview</title>
<link rel="icon" href="/res/favicon.ico">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="The most powerful component model for OSGi">
<link href="/ipojo/web/bootstrap/css/bootstrap-cerulean.css" rel="stylesheet">
<link href="/ipojo/web/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<link href="/ipojo/web/bootstrap/css/font-awesome.min.css" rel="stylesheet">
<link href="/ipojo/web/style.css" rel="stylesheet">
<!-- Overide alert's colors -->
<link href="/ipojo/web/bootstrap/css/alert.css" rel="stylesheet">
<link rel="stylesheet" href="/ipojo/web/github.css" type="text/css" media="all">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/ipojo/web/bootstrap/js/bootstrap.min.js"></script>
</head>
<body data-spy="scroll" data-target=".subnav">
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/documentation/subprojects/apache-felix-ipojo.html">Apache Felix iPOJO</a>
<div class="nav-collapse" id="main-menu">
<ul class="nav" id="main-menu-left">
<li><a href="/documentation/subprojects/apache-felix-ipojo/ipojo-news.html">News</a></li>
<li><a href="http://felix.apache.org/downloads.cgi">Downloads</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Tutorials <b class="caret"></b></a>
<ul class="dropdown-menu" id="tutorials-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-why-choose-ipojo.html">Why choose iPOJO</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-successstories.html">Success stories</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-feature-overview.html">Features</a></li>
<li class="divider"></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-in-10-minutes.html">iPOJO in 10 minutes</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/how-to-use-ipojo-annotations.html">Using Annotations</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-hello-word-maven-based-tutorial.html">Maven tutorial</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-advanced-tutorial.html">Advanced tutorial</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/apache-felix-ipojo-dosgi.html">Using Distributed OSGi</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-composition-tutorial.html">Application Composition</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Documentation <b class="caret"></b></a>
<ul class="dropdown-menu" id="user-guide-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/service-requirement-handler.html">Requiring a service</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/providing-osgi-services.html">Providing a service</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/lifecycle-callback-handler.html">Lifecycle management</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/configuration-handler.html">Configuration</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/architecture-handler.html">Introspection</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/controller-lifecycle-handler.html">Impacting the lifecycle</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/injecting-bundle-context.html">Accessing the Bundle Context</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/apache-felix-ipojo-instances.html">Creating instances</a></li>
<li class="divider"></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">External <em>handlers</em></a>
<ul class="dropdown-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/event-admin-handlers.html">Asynchronous communication</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/ipojo-jmx-handler.html">JMX management</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/extender-pattern-handler.html">Extender pattern</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/white-board-pattern-handler.html">Whiteboard pattern</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/temporal-service-dependency.html">Temporal dependencies</a></li>
</ul>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Configuration Admin &amp; Factories</a>
<ul class="dropdown-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/combining-ipojo-and-configuration-admin.html">iPOJO and config admin</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/ipojo-factory-service.html">Using the iPOJO Factory service</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/how-to-use-ipojo-factories.html">Factories and Instances</a></li>
</ul>
</li>
<li class="divider"></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Advanced topics</a>
<ul class="dropdown-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/instance-vs-service-controller.html">Instance vs. Service Controllers</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/service-binding-interceptors.html">Service Binding Interceptors</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/using-xml-schemas.html">XML Schemas</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/apache-felix-ipojo-api.html">Using the iPOJO API</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/constructing-pojo-objects-with-factory-methods.html">Constructing service objects with factory methods</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/using-ipojo-introspection-api.html">Using the introspection API</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-testing-components.html">Testing components</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/using-stereotypes.html">Using @Stereotypes</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-eclipse-integration.html">Eclipse Integration</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/ipojo-extender-configuration.html">Configuring iPOJO's Extender</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-faq.html">FAQ</a></li>
<li class="divider"></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/how-to-write-your-own-handler.html">Handler development</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/how-to-use-ipojo-manipulation-metadata.html">Manipulation Metadata </a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/dive-into-the-ipojo-manipulation-depths.html">Dive into the iPOJO Manipulation depths</a></li>
<li><a href="http://felix.apache.org/ipojo/api/1.12.1">Javadoc</a></li>
</ul>
</li>
</ul>
</li>
<li class="dropdown" id="tools-menu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Tools <b class="caret"></b></a>
<ul class="dropdown-menu" id="swatch-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-ant-task.html">Ant Task</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-maven-plug-in.html">Maven Plugin</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-arch-command.html">Architecture commands</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/apache-felix-ipojo-online-manipulator.html">Online Manipulator</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-webconsole-plugin.html">Webconsole plugin</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-karaf-feature.html">Apache Karaf Features</a></li>
</ul>
</li>
<li class="dropdown" id="community-menu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Community <b class="caret"></b></a>
<ul class="dropdown-menu" id="swatch-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/ipojo-support.html">Support</a></li>
<li><a href="http://www.apache.org/">ASF</a></li>
<li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li><a href="http://www.apache.org/foundation/thanks.html">Sponsors</a></li>
</ul>
</li>
<li class="dropdown" id="misc-menu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Misc <b class="caret"></b></a>
<ul class="dropdown-menu" id="swatch-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-supportedvms.html">Supported JVMs</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-supportedosgi.html">Supported OSGi Implementations</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/articles-and-presentations.html">Article & Presentations</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/developing-camel-mediators-with-ipojo.html">Developping Camel mediators with iPOJO</a></li>
</ul>
</li>
</ul>
<ul class="nav pull-right" id="main-menu-right">
<li><a rel="tooltip" target="_blank" href="http://felix.apache.org">Apache Felix <i class="icon-share-alt"></i></a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<div class="content">
<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>
<h1 id="introduction">Introduction<a class="headerlink" href="#introduction" title="Permanent link">&para;</a></h1>
<p><em>iPOJO is an extensible, service-oriented component model implemented on the top of the OSGi framework that aims to simplify the development of OSGiâ„¢ applications. iPOJO follows a POJO-based component approach using external metadata to describe how POJO components should be managed by the iPOJO runtime. Some of the standard features of iPOJO include automatic service dependency management, service publication, and configuration property injection.</em></p>
<p>Another feature of iPOJO is component factories. As stated previously, an iPOJO component is described by its metadata. In iPOJO, the metadata describes a component type. For each component type, iPOJO registers a factory service that can be used to create instances of the component type described by the metadata.</p>
<p>In addition to these features, iPOJO also provides a service-oriented composition model. iPOJO's composition model tries to merge:
<em> Component-based composition and
</em> Dynamic service flexibility.</p>
<p>This document presents iPOJO's hierarchical service composition concepts and a simple example to illustrate them.</p>
<h1 id="motivation">Motivation<a class="headerlink" href="#motivation" title="Permanent link">&para;</a></h1>
<p>Component composition occurs in two fashions:
<em> Horizontal composition: A provided interface from one component instance is bound to corresponding required interface of another component instance.
</em> Vertical composition: Component instances are contained inside of another component instance.</p>
<p>Typically, at runtime, a component composition is an unmodifiable set of connected component instances. The main motivation of iPOJO is to remove this limitation and introduce a more dynamic and flexible approach. iPOJO achieves its goals by applying service-oriented concepts to component orientation. Dynamic horizontal composition is supported by iPOJO's dependency injection mechanism described elsewhere (<a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/how-to-write-your-own-handler.html">How to write your own handler</a>) and dynamic vertical composition is supported by iPOJO's hierarchical composition mechanism described below.</p>
<p>iPOJO hierarchical composition tries to merge component composition and dynamic service flexibility to allow:
<em> Run-time/late binding.
</em> Service run-time dynamics.
* Implementation evolution.</p>
<p>The result is a flexible, yet easy-to-use service-oriented component model.</p>
<h1 id="hierachical-service-composition">Hierachical Service Composition<a class="headerlink" href="#hierachical-service-composition" title="Permanent link">&para;</a></h1>
<p>iPOJO essentially provides a kind of service-oriented architecture definition language (ADL). This service-oriented ADL allows you to define <em>composite</em> components. The main differences between a traditional component-oriented composite and an iPOJO composite is that the iPOJO composite's constituent entities are described in terms of abstract service interfaces instead of specific component types/instances and bindings are inferred from dependency metadata data rather than explicitly declared. This approach means that composite components in iPOJO are not concrete component implementations; rather, they are abstract implementations whose precise implementation selection is deferred until run time.</p>
<p>Unlike a POJO component in iPOJO that has code associated with it, a composite component is completely described by its metadata. Similar to a POJO component, however, the metadata describes a component type for which iPOJO registers a factory service that can be used to create instances of the composite component.</p>
<p>A composite can be thought of as a service registry or a scoping mechanism of the global OSGiâ„¢ service registry. Composites can contain other composite, creating a hierarchy of service registries. The OSGiâ„¢ service registry is the root composite.</p>
<p>A composite can:
<em> Contain services.
</em> Require services from its parent composite.
* Provide services to its parent composite.</p>
<p>A service contained in a composite is a <em>sub-service</em>, which is isomorphic to sub-components in traditional component-oriented composites. A sub-service is a service instance created from a component factory. Sub-services are not visible outside of the composite and can only see other services that reside in the composite service registry. The set of services in the composite service registry are all sub-services as well as all required services. Sub-services are not aware of the fact that they are inside of a composite and provide and use services normally within their composite.</p>
<h1 id="hello-world-composite">"Hello World" Composite<a class="headerlink" href="#hello-world-composite" title="Permanent link">&para;</a></h1>
<p>This section describes a simple composite example that requires an aggregated set of services from the parent composite, contains 3 sub-services, and provides one service to the parent composite.</p>
<h2 id="the-killer-application">The "Killer" Application<a class="headerlink" href="#the-killer-application" title="Permanent link">&para;</a></h2>
<p>To illustrate composite we design a "Hello World" application named <em>HelloComposition</em>. This composite offers a service for dispatching a "Hello" message to each person listed in a Directory service. Each person is published as a service and is used by the composition to get the name of the person in order to write the message.!compo1.jpg|align=center!
The composite provides the HelloDispatcher service:</p>
<div class="codehilite"><pre><span class="n">public</span> <span class="n">interface</span> <span class="n">HelloDispatcher</span> <span class="p">{</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">dispatch</span><span class="p">();</span>
<span class="n">public</span> <span class="n">String</span> <span class="n">getLanguage</span><span class="p">();</span>
<span class="n">public</span> <span class="n">List</span><span class="o">&lt;</span><span class="n">Person</span><span class="o">&gt;</span> <span class="n">getPersons</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
<p>The next section describes the abstract composite implementation.</p>
<h2 id="composite-design">Composite Design<a class="headerlink" href="#composite-design" title="Permanent link">&para;</a></h2>
<p>To implement this composite, we reuse existing service implementations;we have three off-the-shelf services:
<em> Hello service: Returns a "Hello" message in a particular language.
</em> Directory service: Aggregates Person services.
* Dispatch service: Requires Hello and Directory services to dispatch a "Hello" message to each person contained in the Directory.!compo2.jpg|align=center!
The following code snippet shows the Hello service interface:</p>
<div class="codehilite"><pre><span class="n">public</span> <span class="n">interface</span> <span class="n">Hello</span> <span class="p">{</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">hello</span><span class="p">(</span><span class="n">String</span> <span class="n">name</span><span class="p">);</span>
<span class="n">public</span> <span class="n">String</span> <span class="n">getLanguage</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
<p>The following code snippet shows the Directory service interface:</p>
<div class="codehilite"><pre><span class="n">public</span> <span class="n">interface</span> <span class="n">Directory</span> <span class="p">{</span>
<span class="n">public</span> <span class="n">Person</span> <span class="n">getPerson</span><span class="p">(</span><span class="n">String</span> <span class="n">name</span><span class="p">);</span>
<span class="n">public</span> <span class="n">List</span><span class="o">&lt;</span><span class="n">Person</span><span class="o">&gt;</span> <span class="n">getPersons</span><span class="p">();</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">addPerson</span><span class="p">(</span><span class="n">String</span> <span class="n">name</span><span class="p">,</span> <span class="n">String</span> <span class="n">address</span><span class="p">);</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">removePerson</span><span class="p">(</span><span class="n">String</span> <span class="n">name</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>The following code snippet shows the Person service interface:</p>
<div class="codehilite"><pre><span class="n">public</span> <span class="n">interface</span> <span class="n">Person</span> <span class="p">{</span>
<span class="n">public</span> <span class="n">String</span> <span class="n">getName</span><span class="p">();</span>
<span class="n">public</span> <span class="n">String</span> <span class="n">getAddress</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
<p>The following code snippet shows the Dispatch service interface:</p>
<div class="codehilite"><pre><span class="n">public</span> <span class="n">interface</span> <span class="n">Dispatcher</span> <span class="p">{</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">dispatch</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
<p>These services define the overall abstract implementation of the composite.</p>
<h2 id="composite-description">Composite Description<a class="headerlink" href="#composite-description" title="Permanent link">&para;</a></h2>
<p>To describe our composite, we use the iPOJO service-oriented ADL:</p>
<div class="codehilite"><pre><span class="nt">&lt;composite</span> <span class="na">name=</span><span class="s">&quot;HelloComposition&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;requires</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.composition.ex1.person.Person&quot;</span> <span class="na">aggregate=</span><span class="s">&quot;true&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;service</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.composition.ex1.hello.Hello&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;service</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.composition.ex1.say.Dispatcher&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;service</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.composition.ex1.directory.Directory&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;provides</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.composition.ex1.compo.HelloDispatcher&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/composite&gt;</span>
</pre></div>
<p>The composite is described in term of service specification, resulting in an abstract component implementation; it declares:
<em> An requirement for all available Person services from the parent composite.
</em> Sub-services for Hello, Dispatcher, and Directory services.
* A provided HelloDispatcher service to the parent composite.</p>
<p>When this composite is instantiated, all Person services from the parent composite are made available in the composite service registry and instances of the Hello, Dispatcher, and Directory are created from available factory services and their corresponding services are published in the composite service registry. The provided HelloDispatcher service is based on method delagation to sub-service specifications as depicted in the following image:!compo3.jpg|align=center!
The delegation of HelloDispatcher service methods to sub-service methods is automatically performed by iPOJO based on method name and method parameter matching.</p>
<h3 id="composite-description-future-work">Composite Description Future Work<a class="headerlink" href="#composite-description-future-work" title="Permanent link">&para;</a></h3>
<p>The composite description presented here does not entirely conform to the ideal model proposed in the earlier sections of this document. Specifically, while the composite is defined in terms of services, the composition as described only really makes sense if we were aware of implementation-specific dependencies of the eventual Dispatcher component type. In other words, for us to choose the Hello and Directory sub-services, we had to know that the eventual implementation of the Dispatcher sub-service would have dependencies on these other sub-services. Unfortunately, this violates the goal of iPOJO to define composites purely in terms of abstract services.</p>
<p>The main reason for this limitation is that OSGi service specifications are comprised of only two parts:
1. A human-readable document.
1. A Java service interface definition.</p>
<p>To realize iPOJO, OSGi service specifications must be extended to contain other information. For example, services must be able to declare specification-level dependencies on other services. Services with specification-level dependencies are referred to as <em>composable services</em>, since it is possible to compose them with other service. In the core OSGi framework, all service dependencies are at the implementation level, thus only component instances are composable.</p>
<p>Composable services are interesting because they make it possible to define services with parameterized behavior or algorithms. For example, a service to select something from a table could have a specification-level dependency on a sorting service, so that sort order is configurable externally. It might appear as if such a scenario were possible with standard OSGi services, but it is not possible unless you make assumptions about the component implementations.</p>
<p>For example, in standard OSGi if component implementation A provides service Foo and requires service Bar, it is not possible to know whether component implementation B, which also provides Foo and requires Bar, uses Bar for the same purpose as A. Composable services makes this possible, since the purpose of such service dependencies can be defined in the service specification. The resulting model obeys two levels of service dependencies:
<em> Specification-level dependencies: Dependencies that are imposed on all implementations and whose purpose is well defined.
</em> Implementation-level dependencies: Dependencies that are arbitrarily selected by the component developer for a specific component implementation and whose purpose is unknown.</p>
<p>As part of the ongoing work of iPOJO, specification-level dependencies (as well as other service specification improvements) will be introduced to the iPOJO model to further refine its service-oriented component model. Using the current example as an illustration, the current approach under investigation for specification-level dependencies looks like this:</p>
<p><a href="">Coming soon...</a></p>
<h2 id="packaging">Packaging<a class="headerlink" href="#packaging" title="Permanent link">&para;</a></h2>
<p>A composite component type is described in the metadata.xml file of an iPOJO bundle which means that iPOJO creates a factory service for the composite, like all iPOJO components. Also like all iPOJO components, it is possible to create an instance of the composite in the metadata file by declaring an instance, such as:</p>
<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">instance</span> <span class="n">component</span><span class="p">=</span>&quot;<span class="n">HelloComposition</span>&quot; <span class="n">name</span><span class="p">=</span>&quot;<span class="n">hello</span><span class="o">-</span><span class="n">composition</span>&quot;<span class="o">/&gt;</span>
</pre></div>
<h2 id="run-time">Run Time<a class="headerlink" href="#run-time" title="Permanent link">&para;</a></h2>
<p>Imagine at run time you have:
<em> Two factories that can create Hello service provider instances.
</em> A factory that can create Dispatcher service provider instances.
<em> A factory that can create Directory service provider instances.
</em> Several existing Person service instances.</p>
<p>When you deploy the example composition and create an instance of it, all aspects of it are automatically managed by iPOJO:
<em> All available Person services from the parent composite are imported into the composite.
</em> One Hello service provider, one Directory service provider, and one Dispatcher service provider are instantiated inside the composite.
* The HelloDispatcher service method calls are wired to the constituent sub-services and it is provided into the parent composite.</p>
<p>If the factory which creates the Hello provider disappears (i.e., its instances become invalid), the composite will automatically switch to the second one to validate the composite service. If the second Hello provider disappears too, then the composite will be invalidated (i.e., the provided service will be revoked) and it will wait for new factory providing Hello service instances, which may themselves also be composite implementations.</p>
<p>When a Person service appears in the parent composite, it is automatically inserted into the composite. Likewise, if a Person service disappears from the parent composite, it is automatically removed from the composite.</p>
<p>A <a href="http://clement.plop-plop.net/animations/composite/composite.htm">flash demo</a> of this composition is available.</p>
<h1 id="composite-concepts-and-features">Composite Concepts and Features<a class="headerlink" href="#composite-concepts-and-features" title="Permanent link">&para;</a></h1>
<p>The following subsections define the various concepts and features of iPOJO's composite components.</p>
<h2 id="service-requirement">Service Requirement<a class="headerlink" href="#service-requirement" title="Permanent link">&para;</a></h2>
<p>The composite can require services from the parent composite. Each requirement is describe by an <code>&lt;requires&gt;</code> element in the composite description. An imported service must specify the target service specification. Additionally, required sub-services can specify:
<em> Cardinality: Indicates whether a single provider instance is imported or an aggregated set of the available providers instances is imported.
</em> Optionality: Indicates whether the imported sub-service is optional or mandatory.
* Filtering: Indicates how the services available in the parent composite can be further filtered using an LDAP expression evaluated over their service properties.</p>
<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">requires</span> <span class="n">specification</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">ipojo</span><span class="p">.</span><span class="n">test</span><span class="p">.</span><span class="n">scenarios</span><span class="p">.</span><span class="n">service</span><span class="p">.</span><span class="n">Hello</span>&quot;
<span class="n">optional</span><span class="p">=</span>&quot;<span class="n">true</span>&quot; <span class="n">aggregate</span><span class="p">=</span>&quot;<span class="n">true</span>&quot; <span class="n">filter</span><span class="p">=</span>&quot;<span class="p">(</span><span class="n">language</span><span class="p">=</span><span class="n">en</span><span class="p">)</span>&quot;<span class="o">/&gt;</span>
</pre></div>
<h2 id="service-provisioning">Service Provisioning<a class="headerlink" href="#service-provisioning" title="Permanent link">&para;</a></h2>
<p>The composite can provide services to its parent composite. Each provided service is described by a <code>&lt;provides&gt;</code> element in the composite description. A provide service must specify provided service specification.</p>
<p>Service provision is realized by delegating method invocations on the service interface to methods on the sub-service instances contained in the composition. A delegation mapping is automatically created by matching method names and arguments types. If a delegation mapping cannot be determined, the composition is invalidated.</p>
<p>Service specifications can also declare certain methods as optional in the service interface; this is done by declaring that a method throws an <code>UnsupportedOperationException</code>. Optional methods need not have a mapping for delegation purposes. If a non-optional service method does not have a mapping for delegation, then a warning message is issued.</p>
<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">provides</span> <span class="n">specification</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">ipojo</span><span class="p">.</span><span class="n">composition</span><span class="p">.</span><span class="n">ex1</span><span class="p">.</span><span class="n">service</span><span class="p">.</span><span class="n">HelloDispatcher</span>&quot;<span class="o">/&gt;</span>
</pre></div>
<h2 id="sub-service-instantiation">Sub-Service Instantiation<a class="headerlink" href="#sub-service-instantiation" title="Permanent link">&para;</a></h2>
<p>A composite can contain sub-services, which result in private service instances at run time. The composite will track factories able to create targeted specification providers. The created service instances are accessible only inside the composite. Sub-service instances may also be composites. Each sub-service to instantiate is represented in the composite description by a <code>&lt;service&gt;</code> element. The sub-services must specify the desired service specification for the sub-service. Additionally, the sub-service may specify:
<em> Cardinality: Indicates whether a single provider instance is created or an aggregated set of the available provider instances is imported.
</em> Optionality: Indicates whether the created sub-service instance is optional or mandatory.
<em> Filtering: Indicates how the service factories available in the parent composite can be further filtered using an LDAP expression evaluated over their service properties.
</em> Configuration: Indicates the configuration to inject in the created instances.</p>
<div class="codehilite"><pre><span class="nt">&lt;composite</span> <span class="na">name=</span><span class="s">&quot;composite.bar &quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;service</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.test.scenarios.service.Hello&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;language&quot;</span> <span class="na">value=</span><span class="s">&quot;en&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/service&gt;</span>
<span class="nt">&lt;/composite&gt;</span>
</pre></div>
<h2 id="instance-injection">Instance injection<a class="headerlink" href="#instance-injection" title="Permanent link">&para;</a></h2>
<p>A composite can contain instances. These instances does not need to provide any service and are identified by their component types. The composite will track the corresponding factories and create the instances. The instances are accessible only inside the composite and their service requirements are resolved inside the composite too. Each instance to instantiate is represented in the composite description by a <code>&lt;instance&gt;</code> element. The instance can specify the desired configuration. The following code snippet will inject an instance of the Hello factory with the configuration : language=en.</p>
<div class="codehilite"><pre><span class="nt">&lt;composite</span> <span class="na">name=</span><span class="s">&quot;composite.bar &quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">component=</span><span class="s">&quot;Hello&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;language&quot;</span> <span class="na">value=</span><span class="s">&quot;en&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/instance&gt;</span>
<span class="nt">&lt;/composite&gt;</span>
</pre></div>
<p>Instance injection can be use for front end. However, these instances can be used to help a composite to provide a service (despite the instance does not provide a service). Indeed, these instances can be used as glue code to provide a service, containing method implementations of the provided service. For example, in the previous instance we had a Dispatcher service dispatching Hello message to Persons. Instead of this sub-service it is possible to inject in instance containing the <em>dispatch</em> method with a customized dispatching algorithm. A glue code instance can require services as any other iPOJO component.</p>
<div class="codehilite"><pre><span class="nt">&lt;composite</span> <span class="na">name=</span><span class="s">&quot;HelloComposition&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;requires</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.composition.ex1.person.Person&quot;</span> <span class="na">aggregate=</span><span class="s">&quot;true&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;service</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.composition.ex1.hello.Hello&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;service</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.composition.ex1.directory.Directory&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">component=</span><span class="s">&quot;MyDispatcher&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;provides</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.composition.ex1.compo.HelloDispatcher&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/composite&gt;</span>
</pre></div>
<p><em>Note:</em> To use instances as glue code be sure that your bundle, containing your composite, imports the implementation of the component type. Moreover, the factory allowing to create the instance must be available when starting your bundle to compute correctly the delegation mapping.</p>
<h2 id="architecture">Architecture<a class="headerlink" href="#architecture" title="Permanent link">&para;</a></h2>
<p>iPOJO composites can expose their internal architecture for reflection. This can be useful, for example, when debugging to understand why a given composite is currently invalid, such as when a given import cannot be satisfied. For a composite to expose its internal architecture, it must set the architecture flag, such as:</p>
<div class="codehilite"><pre><span class="nt">&lt;composite</span> <span class="na">name=</span><span class="s">&quot;composite.bar &quot;</span> <span class="na">architecture=</span><span class="s">&quot;true&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;service</span> <span class="na">specification=</span><span class="s">&quot;org.apache.felix.ipojo.test.scenarios.service.Hello&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;language&quot;</span> <span class="na">value=</span><span class="s">&quot;en&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/service&gt;</span>
<span class="nt">&lt;/composite&gt;</span>
</pre></div>
<p>With this flag set, iPOJO publishes an architecture service for the composite. The architecture of the composite can be examined using the "arch" shell command for Felix.</p>
<h2 id="composition-model-extensibility">Composition Model Extensibility<a class="headerlink" href="#composition-model-extensibility" title="Permanent link">&para;</a></h2>
<p>Like the rest of iPOJO, the composition model is extensible. The composite container is composed of a "composite handler", which is a special handler designed to support composite components. More documentation to come on this feature.</p>
</div>
</div>
<hr/>
<div class="container">
<footer id="footer">
<div class="row">
<div class="trademarkFooter span7">
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 class="timestamp span3 offset2">
Rev. 1700393 by cziegeler on Tue, 1 Sep 2015 06:04:06 +0000
</div>
</div>
</footer>
</div>
</body>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-1518442-4");
pageTracker._trackPageview();
} catch(err) {}
</script>
</html>