blob: cb1c694b29edb542079aa102af19a126360ca274 [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-Reference-Card</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="declaring-component-types">Declaring component types<a class="headerlink" href="#declaring-component-types" title="Permanent link">&para;</a></h1>
<p>XML:</p>
<div class="codehilite"><pre><span class="nt">&lt;component</span>
<span class="na">classname=</span><span class="s">&quot;my.Implementation&quot;</span>
<span class="na">name=</span><span class="s">&quot;my-type&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;/component&gt;</span>
</pre></div>
<p>Java:</p>
<div class="codehilite"><pre><span class="nd">@Component</span><span class="o">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;my-type&quot;</span><span class="o">)</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">Implementation</span> <span class="o">{</span>
<span class="c1">// ...</span>
<span class="o">}</span>
</pre></div>
<table class="table table-striped">
<thead>
<tr>
<th>Attribute name</th>
<th>Required</th>
<th>Default value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>classname</td>
<td>yes</td>
<td></td>
<td>indicates the implementation class (automatic when using annotations).</td>
</tr>
<tr>
<td>name</td>
<td>no</td>
<td>the implementation class name</td>
<td>specifies the component class name</td>
</tr>
</tbody>
</table>
<ul>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/how-to-use-ipojo-factories.html">How-to use iPOJO factories</a></li>
</ul>
<h1 id="creating-component-instances">Creating component instances<a class="headerlink" href="#creating-component-instances" title="Permanent link">&para;</a></h1>
<p>XML:</p>
<div class="codehilite"><pre><span class="nt">&lt;instance</span> <span class="na">component=</span><span class="s">&quot;my-type&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">component=</span><span class="s">&quot;my.Implementation&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">component=</span><span class="s">&quot;my-type&quot;</span> <span class="na">name=</span><span class="s">&quot;my-instance&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">component=</span><span class="s">&quot;my-type&quot;</span> <span class="na">name=</span><span class="s">&quot;my-instance&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;property1&quot;</span> <span class="na">value=</span><span class="s">&quot;value1&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/instance&gt;</span>
</pre></div>
<p>Java:</p>
<div class="codehilite"><pre><span class="nd">@Component</span><span class="o">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;my-type&quot;</span><span class="o">)</span>
<span class="nd">@Instantiate</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">Implementation</span> <span class="o">{</span>
<span class="c1">// ...</span>
<span class="o">}</span>
</pre></div>
<table class="table table-striped">
<thead>
<tr>
<th>Attribute name</th>
<th>Required</th>
<th>Default value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>component</td>
<td>yes</td>
<td></td>
<td>specifies the component type (either by using the name or the class name)</td>
</tr>
<tr>
<td>name</td>
<td>no</td>
<td>generated</td>
<td>specifies the instance name.</td>
</tr>
</tbody>
</table>
<ul>
<li>Instances can contains a configuration given under the <code>key-value</code> form. Properties can also by complex type.</li>
<li>How-to use iPOJO factories</li>
</ul>
<h1 id="providing-services">Providing services<a class="headerlink" href="#providing-services" title="Permanent link">&para;</a></h1>
<p>XML:</p>
<div class="codehilite"><pre><span class="nt">&lt;component</span> <span class="na">classname=</span><span class="s">&quot;my.service.implementation&quot;</span> <span class="na">name=</span><span class="s">&quot;my-service-impl&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;provides/&gt;</span>
<span class="nt">&lt;/component&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">name=</span><span class="s">&quot;my-service-impl&quot;</span><span class="nt">/&gt;</span>
</pre></div>
<p>Java:</p>
<div class="codehilite"><pre><span class="nd">@Component</span>
<span class="nd">@Provides</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">Implementation</span> <span class="kd">implements</span> <span class="n">FooService</span> <span class="o">{</span>
<span class="o">...</span>
<span class="o">}</span>
</pre></div>
<ul>
<li>Only instances provides really services, so don't forget to declare an instance.</li>
<li>Published service interfaces must be implemented by your component implementation</li>
</ul>
<table class="table table-striped">
<thead>
<tr>
<th>Attribute name</th>
<th>Required</th>
<th>Default value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>specifications</td>
<td>no</td>
<td>all implemented interfaces</td>
<td>specifies the published service interfaces</td>
</tr>
<tr>
<td>strategy</td>
<td>no</td>
<td>`singleton`</td>
<td>specifies the service object creation policy among `singleton`, `service` (OSGi Service Factory), `method` (use the factory method), `instance` (an object per instance)</td>
</tr>
</tbody>
</table>
<ul>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/providing-osgi-services.html">Providing OSGi services</a></li>
</ul>
<h1 id="publishing-service-properties">Publishing service properties<a class="headerlink" href="#publishing-service-properties" title="Permanent link">&para;</a></h1>
<p>XML:</p>
<div class="codehilite"><pre><span class="nt">&lt;component</span> <span class="na">classname=</span><span class="s">&quot;my.service.implementation&quot;</span> <span class="na">name=</span><span class="s">&quot;my-service-impl&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;provides&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;foo&quot;</span> <span class="na">field=</span><span class="s">&quot;m_foo&quot;</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;bar&quot;</span> <span class="na">field=</span><span class="s">&quot;m_bar&quot;</span> <span class="na">mandatory=</span><span class="s">&quot;true&quot;</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;baz&quot;</span> <span class="na">type=</span><span class="s">&quot;java.lang.String&quot;</span> <span class="nt">/&gt;</span> <span class="c">&lt;!-- Static property (do not change at runtime) --&gt;</span>
<span class="nt">&lt;/provides&gt;</span>
<span class="nt">&lt;/component&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">name=</span><span class="s">&quot;my-service-impl&quot;</span><span class="nt">&gt;</span> <span class="c">&lt;!-- The configuration has to inject value in unvalued mandatory properties --&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;bar&quot;</span> <span class="na">value=</span><span class="s">&quot;5&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;baz&quot;</span> <span class="na">value=</span><span class="s">&quot;my string&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;instance/&gt;</span>
</pre></div>
<p>Java:</p>
<div class="codehilite"><pre><span class="nd">@Component</span>
<span class="nd">@Provides</span><span class="o">(</span><span class="n">specifications</span><span class="o">=</span> <span class="o">{</span><span class="n">FooService</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">BarService</span><span class="o">.</span><span class="na">class</span><span class="o">},</span>
<span class="n">properties</span><span class="o">=</span> <span class="o">{</span>
<span class="nd">@StaticServiceProperty</span><span class="o">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;baz&quot;</span><span class="o">,</span> <span class="n">type</span><span class="o">=</span><span class="s">&quot;java.lang.String&quot;</span><span class="o">)})</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ProvidesProperties</span> <span class="kd">implements</span> <span class="n">FooService</span><span class="o">,</span> <span class="n">BarService</span> <span class="o">{</span>
<span class="nd">@ServiceProperty</span><span class="o">(</span><span class="n">name</span> <span class="o">=</span> <span class="s">&quot;foo&quot;</span><span class="o">)</span>
<span class="kd">public</span> <span class="kt">int</span> <span class="n">m_foo</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span>
<span class="nd">@ServiceProperty</span><span class="o">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;bar&quot;</span><span class="o">,</span> <span class="n">mandatory</span><span class="o">=</span><span class="kc">true</span><span class="o">)</span>
<span class="kd">public</span> <span class="kt">int</span> <span class="n">m_bar</span><span class="o">;</span>
<span class="c1">// ...</span>
<span class="o">}</span>
</pre></div>
<table class="table table-striped">
<thead>
<tr>
<th>Attribute name</th>
<th>Required</th>
<th>Default value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>no</td>
<td>the field name</td>
<td>specifies the published property name</td>
</tr>
<tr>
<td>mandatory</td>
<td>no</td>
<td>false</td>
<td>specifies if the property has to receive a value from the instance configuration</td>
</tr>
<tr>
<td>value</td>
<td>no</td>
<td></td>
<td>specifies the default property value</td>
</tr>
<tr>
<td>field</td>
<td>no</td>
<td>(automatic with annotations)</td>
<td>specifies the injected field</td>
</tr>
<tr>
<td>type</td>
<td>only if there is no fields</td>
<td></td>
<td>specified the property type</td>
</tr>
</tbody>
</table>
<ul>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/providing-osgi-services.html">Providing OSGi services</a></li>
</ul>
<h1 id="using-services-with-field-injection">Using services with field injection<a class="headerlink" href="#using-services-with-field-injection" title="Permanent link">&para;</a></h1>
<p>XML:</p>
<div class="codehilite"><pre><span class="nt">&lt;component</span> <span class="na">classname=</span><span class="s">&quot;my.consumer.Implementation&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;requires</span> <span class="na">field=</span><span class="s">&quot;fs&quot;</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;requires</span> <span class="na">field=</span><span class="s">&quot;bs&quot;</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;/component&gt;</span>
</pre></div>
<p>Java:</p>
<div class="codehilite"><pre><span class="nd">@Component</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">Dependency</span> <span class="o">{</span>
<span class="nd">@Requires</span>
<span class="kd">public</span> <span class="n">FooService</span> <span class="n">fs</span><span class="o">;</span>
<span class="nd">@Requires</span>
<span class="kd">public</span> <span class="n">BarService</span><span class="o">[]</span> <span class="n">bs</span><span class="o">;</span>
<span class="c1">//...</span>
<span class="o">}</span>
</pre></div>
<table class="table table-striped">
<thead>
<tr>
<th>Attribute name</th>
<th>Required</th>
<th>Default value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="confluenceTd"> id </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd"> field name </td>
<td class="confluenceTd"> dependency id </td>
</tr>
<tr>
<td class="confluenceTd"> field </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd"> automatically detected with annotations </td>
<td class="confluenceTd"> injected field </td>
</tr>
<tr>
<td class="confluenceTd"> optional </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd"> false </td>
<td class="confluenceTd"> specifies if the dependency if optional </td>
</tr>
<tr>
<td class="confluenceTd"> aggregate </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd"> false <br class="atl-forced-newline"> (automatically detected with fields) </td>
<td class="confluenceTd"> specifies if the dependency is aggregate of <tt>scalar</tt> </td>
</tr>
<tr>
<td class="confluenceTd"> specification </td>
<td class="confluenceTd"> yes/no </td>
<td class="confluenceTd"> can be discovered from the code </td>
<td class="confluenceTd"> specifies the required service specification. This attribute is required when the service type cannot be inferred from the code (Collection type for fields, callbacks without service objects) </td>
</tr>
<tr>
<td class="confluenceTd"> filter </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd"> no filter </td>
<td class="confluenceTd"> specifies the dependency LDAP filter </td>
</tr>
<tr>
<td class="confluenceTd"> from </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd">&nbsp;</td>
<td class="confluenceTd"> specifies a specific provider by its name </td>
</tr>
<tr>
<td class="confluenceTd"> policy </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd"> <tt>dynamic</tt> </td>
<td class="confluenceTd"> specifies the binding policy among <tt>dynamic</tt>, <tt>static</tt> and <tt>dynamic-priority</tt> </td>
</tr>
<tr>
<td class="confluenceTd"> nullable </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd"> true </td>
<td class="confluenceTd"> enables/disables nullable object injection for optional dependencies </td>
</tr>
<tr>
<td class="confluenceTd"> default-implementation // defaultimplementation for annotations </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd">&nbsp;</td>
<td class="confluenceTd"> specifies the default-implementation for optional dependencies </td>
</tr>
<tr>
<td class="confluenceTd"> comparator </td>
<td class="confluenceTd"> no </td>
<td class="confluenceTd">&nbsp;</td>
<td class="confluenceTd"> specifies the comparator class used to sort service providers </td>
</tr>
</tbody>
</table>
<ul>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/service-requirement-handler.html">Service Requirement Handler</a></li>
</ul>
<h1 id="using-services-with-method-injection">Using services with method injection<a class="headerlink" href="#using-services-with-method-injection" title="Permanent link">&para;</a></h1>
<p>XML:</p>
<div class="codehilite"><pre><span class="nt">&lt;component</span> <span class="na">classname=</span><span class="s">&quot;my.consumer.Implementation&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;requires&gt;</span>
<span class="nt">&lt;callback</span> <span class="na">type=</span><span class="s">&quot;bind&quot;</span> <span class="na">method=</span><span class="s">&quot;bind&quot;</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;callback</span> <span class="na">type=</span><span class="s">&quot;unbind&quot;</span> <span class="na">method=</span><span class="s">&quot;unbind&quot;</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;callback</span> <span class="na">type=</span><span class="s">&quot;modified&quot;</span> <span class="na">method=</span><span class="s">&quot;modified&quot;</span> <span class="nt">/&gt;</span> <span class="c">&lt;!-- for filtered service dependencies, to be notified when a service is modified but still match --&gt;</span>
<span class="nt">&lt;/requires&gt;</span>
<span class="nt">&lt;/component&gt;</span>
</pre></div>
<p>Java:</p>
<div class="codehilite"><pre><span class="p">@</span><span class="n">Component</span>
<span class="n">public</span> <span class="n">class</span> <span class="n">Dependency</span> <span class="p">{</span>
<span class="p">@</span><span class="n">Unbind</span>
<span class="n">public</span> <span class="n">synchronized</span> <span class="n">void</span> <span class="n">unbindBaz</span><span class="p">(</span><span class="n">BazService</span> <span class="n">bz</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span><span class="p">...</span>
<span class="p">}</span>
<span class="p">@</span><span class="n">Bind</span>
<span class="n">public</span> <span class="n">synchronized</span> <span class="n">void</span> <span class="n">bindBaz</span><span class="p">(</span><span class="n">BazService</span> <span class="n">bz</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span> <span class="p">...</span>
<span class="p">}</span>
<span class="p">@</span><span class="n">Modified</span>
<span class="n">public</span> <span class="n">synchronized</span> <span class="n">void</span> <span class="n">modifiedBaz</span><span class="p">()</span> <span class="p">{</span>
<span class="o">//</span> <span class="p">...</span>
<span class="p">}</span>
<span class="o">//</span><span class="p">...</span>
<span class="p">}</span>
</pre></div>
<p>{div:class=borderedTable}
{center}
|Attribute name | Required | Default value | |
|--|--|--|--|
| id | no | field name | dependency id |
| field | no | automatically detected with annotations | injected field |
| optional | no | false | specifies if the dependency if optional |</p>
<p>| specification | yes/no | can be discovered from the code | specifies the required service specification. This attribute is required when the service type cannot be infered from the code (Collection type for fields, callbacks without service objects) |
| filter | no | no filter | specifies the dependency LDAP filter |
| from | no | | specifies a specific provider by its name |
| policy | no | <code>dynamic</code> | specifies the binding policy among <code>dynamic</code>, <code>static</code> and <code>dynamic-priority</code> |
| nullable | no | true | enables/disables nullable object injection for optional dependencies |
| default-implementation // default implementation for annotations | no | | specifies the default-implementation for optional dependencies |
| comparator | no | | specifies the comparator class used to sort service providers |</p>
<table class="table">
<thead>
<tr>
<th>Sub-Element name</th>
<th>Required</th>
<th>Default value</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>callback</td>
<td>no</td>
<td>callback specifies bind and unbind method. Two attributes are required (discovered automatically with annotations). <code>type</code> specified if the callback is a bind or unbind method (among `{bind<code>,</code>unbind<code>,</code>modified<code>\}. The</code>method<code>attribute specified the method to call. The</code>modified` callback is called when the service properties of a bound service are modified and the service still match the filter.</td>
<td></td>
</tr>
<tr>
<td center="center"></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td div="div"></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>* <a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/service-requirement-handler.html">Service Requirement Handler</a></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<h1 id="configuring-service-dependencies-in-the-instance-configuration">Configuring service dependencies in the instance configuration<a class="headerlink" href="#configuring-service-dependencies-in-the-instance-configuration" title="Permanent link">&para;</a></h1>
<p>h2. Configuring the <code>from</code> attribute
* Thanks to the <code>requires.from</code> property, it is possible to override the <code>from</code> attribute value.</p>
<p>{code:xml|From attribute configuration}
<component
classname="...MyComponent"
name="FOO">
<requires field="m_foo" id="id1">
<callback type="bind" method="bind"/>
<callback type="unbind" method="unbind"/>
</requires>
</component></p>
<p><instance name="FOO1" component="FOO"/> <!-- Use the default 'from' value --></p>
<p><instance name="FOO2" component="FOO">
<property name="requires.from">
<property name="id1" value="myprovider"/>
</property>
</instance></p>
<div class="codehilite"><pre> h2. Configuring the attribute
* Thanks to the property, it is possible to override the attribute value.
{code:xml|Filter attribute configuration}
<span class="nt">&lt;component</span>
<span class="na">classname=</span><span class="s">&quot;org.apache.felix.ipojo.example.FilteredDependency&quot;</span>
<span class="na">name=</span><span class="s">&quot;FOO&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;requires</span> <span class="na">field=</span><span class="s">&quot;m_foo&quot;</span> <span class="na">fiter=</span><span class="s">&quot;(foo.property=FOO)&quot;</span> <span class="na">id=</span><span class="s">&quot;id1&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;callback</span> <span class="na">type=</span><span class="s">&quot;bind&quot;</span> <span class="na">method=</span><span class="s">&quot;bind&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;callback</span> <span class="na">type=</span><span class="s">&quot;unbind&quot;</span> <span class="na">method=</span><span class="s">&quot;unbind&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/requires&gt;</span>
<span class="nt">&lt;/component&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">name=</span><span class="s">&quot;FOO1&quot;</span> <span class="na">component=</span><span class="s">&quot;FOO&quot;</span><span class="nt">/&gt;</span> <span class="c">&lt;!-- Use the default &#39;filter&#39; value --&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">name=</span><span class="s">&quot;FOO2&quot;</span> <span class="na">component=</span><span class="s">&quot;FOO&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;requires.filters&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;id1&quot;</span> <span class="na">value=</span><span class="s">&quot;(foo.property=BAR)&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/property&gt;</span>
<span class="nt">&lt;/instance&gt;</span>
</pre></div>
<h1 id="reacting-to-lifecycle-state-changes">Reacting to lifecycle state changes<a class="headerlink" href="#reacting-to-lifecycle-state-changes" title="Permanent link">&para;</a></h1>
<h2 id="immediate-components">Immediate components<a class="headerlink" href="#immediate-components" title="Permanent link">&para;</a></h2>
<ul>
<li>A POJO object (implementation object) is created as soons as the instance becomes valid</li>
<li>
<p>Instances that don't provide services becomes automatically immediate
:::xml
<component classname="my.service.implementation" name="my-service-impl" immediate="true">
<provides/>
</component></p>
<p>{code:java|title=Annotations}
@Component(immediate=true)
@Provides
public class Implementation implements FooService {
...
}</p>
</li>
</ul>
<p>{div:class=borderedTable}
{center}
|Attribute name | Required | Default value | |
|--|--|--|--|
| immediate | no | false // true for instances that don't provide a service | specifies if the instance is immediate or not |
{center}
{div}
* <a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/lifecycle-callback-handler.html">Lifecycle Callback Handler</a></p>
<h2 id="lifecycle-callbacks">Lifecycle callbacks<a class="headerlink" href="#lifecycle-callbacks" title="Permanent link">&para;</a></h2>
<div class="codehilite"><pre>
</pre></div>
<p><component classname="my.implementation" name="my-impl">
<callback transition="validate" method="start" />
<callback transition="invalidate" method="stop" />
</component></p>
<div class="codehilite"><pre><span class="p">{</span><span class="n">code</span><span class="p">:</span><span class="n">java</span><span class="o">|</span><span class="n">title</span><span class="p">=</span><span class="n">Annotations</span><span class="p">}</span>
<span class="p">@</span><span class="n">Component</span>
<span class="n">public</span> <span class="n">class</span> <span class="n">Implementation</span> <span class="p">{</span>
<span class="p">@</span><span class="n">Validate</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">start</span><span class="p">()</span> <span class="p">{</span>
<span class="p">}</span>
<span class="p">@</span><span class="n">Invalidate</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">stop</span><span class="p">()</span> <span class="p">{</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
<ul>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/lifecycle-callback-handler.html">Lifecycle Callback Handler</a></li>
</ul>
<h1 id="declaring-properties">Declaring properties<a class="headerlink" href="#declaring-properties" title="Permanent link">&para;</a></h1>
<div class="codehilite"><pre>
</pre></div>
<p><component classname="my.Implementation" name="my-impl">
<properties propagation="true" managedservice="MyPID">
<property name="boo" method="setBoo" />
<property field="m_bar" mandatory="true"/>
<property field="m_foo" value="4"/>
</properties>
</component>
<instance component="my-impl">
<property name="boo" value="..."/>
<property name="m_bar" value="..."/>
</instance>
<instance component="my-impl">
<property name="boo" value="..."/>
<property name="m_bar" value="..."/>
<property name="managed.service.pid" value="AnotherPID"/>
</instance></p>
<div class="codehilite"><pre><span class="p">{</span><span class="n">code</span><span class="p">:</span><span class="n">java</span><span class="o">|</span><span class="n">title</span><span class="p">=</span><span class="n">Annotations</span><span class="p">}</span>
<span class="p">@</span><span class="n">Component</span><span class="p">(</span><span class="n">managedservice</span><span class="p">=</span>&quot;<span class="n">MyPID</span>&quot;<span class="p">,</span> <span class="n">propagation</span><span class="p">=</span><span class="n">true</span><span class="p">)</span>
<span class="n">public</span> <span class="n">class</span> <span class="n">Implementation</span> <span class="p">{</span>
<span class="p">@</span><span class="n">Property</span><span class="p">(</span><span class="n">name</span><span class="p">=</span>&quot;<span class="n">boo</span>&quot;<span class="p">)</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">setBoo</span><span class="p">(</span><span class="n">int</span> <span class="n">boo</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span><span class="p">...</span>
<span class="p">}</span>
<span class="p">@</span><span class="n">Property</span><span class="p">(</span><span class="n">mandatory</span><span class="p">=</span><span class="n">true</span><span class="p">)</span>
<span class="n">public</span> <span class="n">int</span> <span class="n">m_bar</span><span class="p">;</span>
<span class="p">@</span><span class="n">Property</span><span class="p">(</span><span class="n">value</span><span class="p">=</span>&quot;4&quot;<span class="p">)</span>
<span class="n">public</span> <span class="n">int</span> <span class="n">m_foo</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>{div:class=borderedTable}
{center}
|Attribute name | Required | Default value | |
|--|--|--|--|
| propagation | no | false | specifies if the properties propagation (properties are also published as service properties) is enabled or disabled |
| managedservice | no | instance name | specifies the PID of the published managed service. // This value can be overidden by the <code>managed.service.pid</code> instance property |
| name | no | field name or computed from the method name | specifies if the the property name |
| value | no | | specifies the default property value |
| field | no | automatically detected with annotations | specifies the field in which the property value will be injected |
| method | no | automatically detected with annotations | specifies the setter method in which the property value will be injected |
| mandatory | no | false | specifies if the property has to receive a value from the instance configuration |
{center}
{div}
* <a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/configuration-handler.html">Configuration Handler</a></p>
<h1 id="postregistration-and-postunregistration-callbacks">PostRegistration and PostUnregistration callbacks<a class="headerlink" href="#postregistration-and-postunregistration-callbacks" title="Permanent link">&para;</a></h1>
<ul>
<li>This feature is part of the provided service handler, and so requires that the component provides a service.</li>
<li>
<p>The callback receives a <code>ServiceReference</code> as parameter.
:::xml
<component
classname="...">
<provides
post-unregistration="unregistered" post-registration="registered"/>
</component></p>
<p>{code:java|title=Annotations}
@PostRegistration
public void registered(ServiceReference ref) {
System.out.println("Registered");
}</p>
<p>@PostUnregistration
public void unregistered(ServiceReference ref) {
System.out.println("Unregistered");
}</p>
</li>
<li>
<p><a href="http://felix.apache.org/site/providing-osgi-services.html#ProvidingOSGiservices-Beingnotifiedoftheserviceregistrationandunregistration">Provided Service Handler</a></p>
</li>
</ul>
<h1 id="controlling-service-publication">Controlling service publication<a class="headerlink" href="#controlling-service-publication" title="Permanent link">&para;</a></h1>
<ul>
<li>This feature is part of the provided service handler, and so requires that the component provides a service.</li>
<li>
<p>It allows a component to force the un-publication of a service.
:::xml
<component
classname="...">
<provides>
<controller field="controller" value="false"/>
</provides>
</component></p>
<p>{code:java|title=Annotations}
@ServiceController(value="false")
private boolean controller</p>
</li>
<li>
<p><a href="http://felix.apache.org/site/providing-osgi-services.html">Provided Service Handler</a></p>
</li>
</ul>
<h1 id="using-arch">Using 'arch'<a class="headerlink" href="#using-arch" title="Permanent link">&para;</a></h1>
<ul>
<li>Deploy the 'arch' command bundle (available for Felix and Equinox)</li>
<li>
<p>Launch the 'arch' command in the OSGi Framework Shell
{code:java|title=Felix Shell}
arch =&gt; displays instances name &amp; state (equivalent to arch -instances)
arch -instance $instance<em>name =&gt; displays complete information about the instance $instance</em>name
arch -factories =&gt; display the list of available factories
arch -factory $factory<em>name =&gt; display complete information about the factory $factory</em>name
arch -handlers =&gt; list available handlers</p>
<p>{code:java|title=Felix Gogo}
ipojo:instances =&gt; displays instances name &amp; state (equivalent to arch -instances)
ipojo:instance $instance_name =&gt; displays complete information about the instance $instance_name
ipojo:factories =&gt; display the list of available factories
ipojo:factory $factory_name =&gt; display complete information about the factory $factory_name
ipojo:handlers =&gt; list available handlers</p>
</li>
<li>
<p><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-arch-command.html">iPOJO Arch Command</a></p>
</li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/architecture-handler.html">Architecture Handler</a></li>
</ul>
<h1 id="temporal-dependencies">Temporal Dependencies<a class="headerlink" href="#temporal-dependencies" title="Permanent link">&para;</a></h1>
<ul>
<li>Temporal dependencies are injected in fields. When accessing to the service, the thread waits for the service availability. If a timeout is reached, a timeout policy is executed.</li>
<li>Service objects can be injected as <code>proxies</code> and be given to collaborator objects.</li>
<li>
<p>Temporal dependencies are implemented as an <em>external handlers</em>. To use them, deploy and start the temporal dependency handler bundle.</p>
<p>:::xml
<iPOJO xmlns:temporal="org.apache.felix.ipojo.handler.temporal">
<component
className="my.Implementation"></p>
<p><!-- Temporal dependency configuration -->
<temporal:requires field="mytemporal"/>
<provides/>
</component>
</iPOJO></p>
<p>{code:java|title=Annotations}
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.handler.temporal.Requires;
import org.apache.felix.ipojo.test.scenarios.annotations.service.FooService;</p>
<p>@Component
public class Implementation {</p>
<div class="codehilite"><pre><span class="p">@</span><span class="n">Requires</span> <span class="o">//</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">ipojo</span><span class="p">.</span><span class="n">handler</span><span class="p">.</span><span class="n">temporal</span><span class="p">.</span><span class="n">Requires</span>
<span class="n">private</span> <span class="n">FooService</span> <span class="n">mytemporal</span><span class="p">;</span>
</pre></div>
<p>}</p>
</li>
</ul>
<p>{div:class=borderedTable}
{center}
|Attribute name | Required | Default value | |
|--|--|--|--|
| field | no | automatically detected with annotations | specifies the field in which the service object will be injected |
| timeout | no | 3000 ms | specifies the timeout value (in ms). When the timeout is reached, the on timeout policy is executed |
| onTimeout | no | Runtime Exception | specifies the on timeout policy. Possible values are: <code>null</code>, <code>nullable</code>, <code>empty</code>, <em>default-implementation</em> (class name) |
| specification | only when using Collections | | specifies the required service specification. This attribute is required when the injected field is a Collection |
| proxy | no | false | enables/disables proxy injection. Service injected as proxies can be given to collaborators |
| filter | no | no filter | Filter use to discover matching filter. |
{center}
{div}
* <a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/temporal-service-dependency.html">Temporal Service Dependency</a></p>
<h1 id="sending-and-receiving-events">Sending and receiving events<a class="headerlink" href="#sending-and-receiving-events" title="Permanent link">&para;</a></h1>
<h2 id="receiving-events">Receiving events<a class="headerlink" href="#receiving-events" title="Permanent link">&para;</a></h2>
<ul>
<li>The event admin handler allows receiving events from the Event Admin.</li>
<li>The event admin handler is implemented as an <em>external handlers</em>. To use it, deploy and start the event admin handler bundle and an implementation of the event admin service.</li>
<li>
<p>Event (or data) are receive thanks to a callback method.</p>
<p>:::xml
<ipojo
xmlns:ev="org.apache.felix.ipojo.handlers.event.EventAdminHandler">
<component className="...MyComponent">
<ev:subscriber
name="mySubscriber"
callback="receive"
topics="foo"/>
</component>
</ipojo></p>
<p>{code:java|title=Annotations}
@Component
public class MyComponent {</p>
<div class="codehilite"><pre><span class="p">@</span><span class="n">Subscriber</span><span class="p">(</span><span class="n">name</span><span class="p">=</span>&quot;<span class="n">s1</span>&quot;<span class="p">,</span> <span class="n">data_key</span><span class="p">=</span>&quot;<span class="n">data</span>&quot;<span class="p">)</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">receive1</span><span class="p">(</span><span class="n">Object</span> <span class="n">foo</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span> <span class="n">Nothing</span>
<span class="p">}</span>
<span class="p">@</span><span class="n">Subscriber</span><span class="p">(</span><span class="n">name</span><span class="p">=</span>&quot;<span class="n">s2</span>&quot;<span class="p">,</span> <span class="n">topics</span><span class="p">=</span>&quot;<span class="n">foo</span><span class="p">,</span><span class="n">bar</span>&quot;<span class="p">,</span> <span class="n">filter</span><span class="p">=</span>&quot;<span class="p">(</span><span class="n">foo</span><span class="p">=</span><span class="n">true</span><span class="p">)</span>&quot;<span class="p">)</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">receive2</span><span class="p">(</span><span class="n">Event</span> <span class="n">foo</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span> <span class="n">Nothing</span>
<span class="p">}</span>
<span class="p">@</span><span class="n">Subscriber</span><span class="p">(</span><span class="n">name</span><span class="p">=</span>&quot;<span class="n">s3</span>&quot;<span class="p">,</span> <span class="n">topics</span><span class="p">=</span>&quot;<span class="n">foo</span>&quot;<span class="p">,</span> <span class="n">data_key</span><span class="p">=</span>&quot;<span class="n">data</span>&quot;<span class="p">,</span> <span class="n">data_type</span><span class="p">=</span>&quot;<span class="n">java</span><span class="p">.</span><span class="n">lang</span><span class="p">.</span><span class="n">String</span>&quot;<span class="p">)</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">receive3</span><span class="p">(</span><span class="n">String</span> <span class="n">foo</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span> <span class="n">Nothing</span>
<span class="p">}</span>
</pre></div>
</li>
</ul>
<p>{div:class=borderedTable}
{center}
|Attribute name | Required | Default value | |
|--|--|--|--|
| name | yes | | specifies the name of the event subscriber, acting as a unique identifier. This name is used to configure event subscription in the instance configuration. |</p>
<p>| topics | yes | | specifies the list (comma-separated-list) of the topics that the handler will listen to. Each event sent on a topic present in this list will be sent to the specified callback method. This parameter can be overridden by instances |</p>
<p>If you use this attribute, the parameter passed to the callback method is the the value associated to this key, not the whole event. This attribute is generally used with the <code>data-type</code> attribute to specify the received object type. If an event is received and it does not contain such a key, it is ignored (with a warning message). |</p>
<p>| filter | no | no filter | specifies the event LDAP filter used to filter incoming events before sending them to the callback. The syntax of this field is described in the OSGi EventAdmin Specification. If you don't specify a filter, all events sent on the listened topics will be considered. |
{center}
{div}
* Instance configuration
<strong> event.topics : overrides <code>topics</code> attribute
</strong> event.filter : overrides <code>filter</code> attribute</p>
<p>{code:xml|title=Instance configuration}
<instance component="...MyComponent">
<property name="event.topics">
<property name="mySubscriber" value="foo"/>
</property>
<property name="event.filter">
<property name="mySubscriber"
value="|((arg=Minibar)(arg=Coconuts))"/>
</property>
</instance></p>
<div class="codehilite"><pre>* [Event Admin Handlers]
h2. Sending events
* The event admin handler allows sending events to the Event Admin.
* The event admin handler is implemented as an _external handlers_. To use it, deploy and start the event admin handler bundle and an implementation of the event admin service.
* To send events, your code must contains a field.
:::xml
<span class="nt">&lt;ipojo</span>
<span class="na">xmlns:ev=</span><span class="s">&quot;org.apache.felix.ipojo.handlers.event.EventAdminHandler&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;component</span> <span class="na">className=</span><span class="s">&quot;...MyComponent&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;ev:publisher</span>
<span class="na">name=</span><span class="s">&quot;myPublisher&quot;</span>
<span class="na">field=</span><span class="s">&quot;m_publisher&quot;</span>
<span class="na">topics=</span><span class="s">&quot;bar,nuts&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/component&gt;</span>
<span class="nt">&lt;instance</span> <span class="na">component=</span><span class="s">&quot;...MyComponent&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/ipojo&gt;</span>
</pre></div>
<p>{code:java|title=Annotations}</p>
<p>@Component
public class MyComponent {
// We use qualified names to avoid conflict.
@org.apache.felix.ipojo.handlers.event.Publisher(name="p1", synchronous=true)
org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher1;</p>
<div class="codehilite"><pre><span class="p">@</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">ipojo</span><span class="p">.</span><span class="n">handlers</span><span class="p">.</span><span class="n">event</span><span class="p">.</span><span class="n">Publisher</span><span class="p">(</span><span class="n">name</span><span class="p">=</span>&quot;<span class="n">p2</span>&quot;<span class="p">,</span> <span class="n">synchronous</span><span class="p">=</span><span class="n">false</span><span class="p">,</span> <span class="n">topics</span><span class="p">=</span>&quot;<span class="n">foo</span><span class="p">,</span><span class="n">bar</span>&quot;<span class="p">,</span> <span class="n">data_key</span><span class="p">=</span>&quot;<span class="n">data</span>&quot;<span class="p">)</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">ipojo</span><span class="p">.</span><span class="n">handlers</span><span class="p">.</span><span class="n">event</span><span class="p">.</span><span class="n">publisher</span><span class="p">.</span><span class="n">Publisher</span> <span class="n">publisher2</span><span class="p">;</span>
<span class="p">@</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">ipojo</span><span class="p">.</span><span class="n">handlers</span><span class="p">.</span><span class="n">event</span><span class="p">.</span><span class="n">Publisher</span><span class="p">(</span><span class="n">name</span><span class="p">=</span>&quot;<span class="n">p3</span>&quot;<span class="p">,</span> <span class="n">synchronous</span><span class="p">=</span><span class="n">true</span><span class="p">,</span> <span class="n">topics</span><span class="p">=</span>&quot;<span class="n">bar</span>&quot;<span class="p">)</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">ipojo</span><span class="p">.</span><span class="n">handlers</span><span class="p">.</span><span class="n">event</span><span class="p">.</span><span class="n">publisher</span><span class="p">.</span><span class="n">Publisher</span> <span class="n">publisher3</span><span class="p">;</span>
<span class="o">//</span> <span class="p">...</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">doSomething</span><span class="p">()</span> <span class="p">{</span>
<span class="n">Dictionary</span> <span class="n">e</span> <span class="p">=</span> <span class="n">new</span> <span class="n">Properties</span><span class="p">();</span>
<span class="o">//</span><span class="p">...</span>
<span class="o">//</span> <span class="n">Fill</span> <span class="n">out</span> <span class="n">the</span> <span class="n">event</span>
<span class="o">//</span> <span class="n">Send</span> <span class="n">event</span>
<span class="n">publisher1</span><span class="p">.</span><span class="n">send</span><span class="p">(</span><span class="n">e</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>}</p>
<div class="codehilite"><pre><span class="o">*</span> <span class="p">[</span><span class="n">Event</span> <span class="n">Admin</span> <span class="n">Handlers</span><span class="p">]</span>
<span class="p">{</span><span class="n">div</span><span class="p">:</span><span class="n">class</span><span class="p">=</span><span class="n">borderedTable</span><span class="p">}</span>
<span class="p">{</span><span class="n">center</span><span class="p">}</span>
<span class="o">||</span><span class="n">Attribute</span> <span class="n">name</span> <span class="o">||</span> <span class="n">Required</span> <span class="o">||</span> <span class="n">Default</span> <span class="n">value</span> <span class="o">||</span> <span class="o">||</span>
<span class="o">|</span> <span class="n">name</span> <span class="o">|</span> <span class="n">yes</span> <span class="o">|</span> <span class="o">|</span> <span class="n">specifies</span> <span class="n">the</span> <span class="n">name</span> <span class="n">of</span> <span class="n">the</span> <span class="n">event</span> <span class="n">publisher</span><span class="p">,</span> <span class="n">acting</span> <span class="n">as</span> <span class="n">a</span> <span class="n">unique</span> <span class="n">identifier</span><span class="p">.</span> <span class="n">This</span> <span class="n">name</span> <span class="n">is</span> <span class="n">used</span> <span class="n">to</span> <span class="n">configure</span> <span class="n">event</span> <span class="n">publishing</span> <span class="n">in</span> <span class="n">the</span> <span class="n">instance</span> <span class="n">configuration</span><span class="p">.</span> <span class="o">|</span>
<span class="o">|</span> <span class="n">field</span> <span class="o">|</span> <span class="n">yes</span> <span class="o">\\</span> <span class="n">automatically</span> <span class="n">detected</span> <span class="n">with</span> <span class="n">annotations</span> <span class="o">|</span> <span class="o">|</span> <span class="n">specifies</span> <span class="n">The</span> <span class="n">name</span> <span class="n">of</span> <span class="n">the</span> <span class="n">field</span> <span class="n">used</span> <span class="n">to</span> <span class="n">send</span> <span class="k">events</span><span class="p">.</span> <span class="n">The</span> <span class="n">field</span> <span class="n">is</span> <span class="n">initialized</span> <span class="n">at</span> <span class="n">component</span> <span class="n">instantiation</span> <span class="n">time</span><span class="p">.</span> <span class="n">The</span> <span class="n">type</span> <span class="n">of</span> <span class="n">the</span> <span class="n">field</span> <span class="n">must</span> <span class="n">be</span> <span class="p">:</span> <span class="p">.</span> <span class="o">|</span>
<span class="o">|</span> <span class="n">topics</span> <span class="o">|</span> <span class="n">yes</span> <span class="o">|</span> <span class="o">|</span> <span class="n">specifies</span> <span class="n">the</span> <span class="n">list</span> <span class="p">(</span><span class="n">comma</span><span class="o">-</span><span class="n">separated</span><span class="o">-</span><span class="n">list</span><span class="p">)</span> <span class="n">of</span> <span class="n">the</span> <span class="n">topics</span> <span class="n">on</span> <span class="n">which</span> <span class="k">events</span> <span class="n">will</span> <span class="n">be</span> <span class="n">sent</span><span class="p">.</span> <span class="n">This</span> <span class="n">parameter</span> <span class="n">can</span> <span class="n">be</span> <span class="n">overridden</span> <span class="n">by</span> <span class="n">instances</span> <span class="o">|</span>
<span class="o">|</span> <span class="n">data</span><span class="o">-</span><span class="n">key</span> <span class="o">\\</span> <span class="n">data_key</span> <span class="n">when</span> <span class="n">using</span> <span class="n">annotations</span> <span class="o">|</span> <span class="n">no</span> <span class="o">|</span> <span class="n">user</span><span class="p">.</span><span class="n">data</span> <span class="o">|</span> <span class="n">specifies</span> <span class="n">the</span> <span class="n">data</span> <span class="n">key</span> <span class="n">used</span> <span class="n">when</span> <span class="n">you</span> <span class="n">want</span> <span class="n">to</span> <span class="n">send</span> <span class="n">data</span> <span class="k">events</span><span class="p">.</span> <span class="n">This</span> <span class="n">attribute</span><span class="o">&#39;</span><span class="n">s</span> <span class="n">value</span> <span class="n">is</span> <span class="n">the</span> <span class="n">key</span><span class="p">,</span> <span class="n">in</span> <span class="n">the</span> <span class="n">event</span><span class="o">&#39;</span><span class="n">s</span> <span class="n">dictionary</span><span class="p">,</span> <span class="n">in</span> <span class="n">which</span> <span class="n">sent</span> <span class="n">data</span> <span class="n">are</span> <span class="n">stored</span><span class="p">.</span> <span class="n">When</span> <span class="n">you</span> <span class="n">use</span> <span class="n">the</span> <span class="n">_sendData_</span> <span class="n">method</span> <span class="n">of</span> <span class="n">the</span> <span class="n">Publisher</span><span class="p">,</span> <span class="n">the</span> <span class="n">given</span> <span class="n">object</span> <span class="n">is</span> <span class="n">placed</span> <span class="n">in</span> <span class="n">the</span> <span class="n">event</span> <span class="n">dictionary</span><span class="p">,</span> <span class="n">associated</span> <span class="n">with</span> <span class="n">the</span> <span class="n">specified</span> <span class="n">data</span><span class="o">-</span><span class="n">key</span><span class="p">.</span> <span class="o">|</span>
<span class="o">|</span> <span class="n">synchronous</span> <span class="o">|</span> <span class="n">no</span> <span class="o">|</span> <span class="n">false</span> <span class="o">|</span> <span class="n">specifies</span> <span class="k">if</span> <span class="n">event</span> <span class="n">sending</span> <span class="n">is</span> <span class="n">synchronous</span> <span class="n">or</span> <span class="n">not</span><span class="p">.</span> <span class="o">|</span>
<span class="p">{</span><span class="n">center</span><span class="p">}</span>
<span class="p">{</span><span class="n">div</span><span class="p">}</span>
<span class="o">*</span> <span class="n">Instance</span> <span class="n">configuration</span>
<span class="o">**</span> <span class="n">event</span><span class="p">.</span><span class="n">topics</span> <span class="p">:</span> <span class="n">overrides</span> <span class="n">attribute</span>
<span class="p">{</span><span class="n">code</span><span class="p">:</span><span class="n">xml</span><span class="o">|</span><span class="n">title</span><span class="p">=</span><span class="n">Instance</span> <span class="n">configuration</span><span class="p">}</span>
<span class="o">&lt;</span><span class="n">instance</span> <span class="n">component</span><span class="p">=</span>&quot;<span class="p">...</span><span class="n">MyComponent</span>&quot;<span class="o">&gt;</span>
<span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="p">=</span>&quot;<span class="n">event</span><span class="p">.</span><span class="n">topics</span>&quot;<span class="o">&gt;</span>
<span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="p">=</span>&quot;<span class="n">myPublisher</span>&quot; <span class="n">value</span><span class="p">=</span>&quot;<span class="n">foo</span>&quot;<span class="o">/&gt;</span>
<span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">instance</span><span class="o">&gt;</span>
</pre></div>
<h1 id="extender-pattern">Extender Pattern<a class="headerlink" href="#extender-pattern" title="Permanent link">&para;</a></h1>
<ul>
<li>Allows implementing an <code>Extender pattern</code> without handling obscure details</li>
<li>
<p>The extender pattern handler is implemented as an <em>external handlers</em>. To use it, deploy and start the external pattern handler bundle.</p>
<p>:::xml
<ipojo xmlns:extender="org.apache.felix.ipojo.extender">
<component
classname="org.apache.felix.ipojo.extender.Myextender"></p>
<div class="codehilite"><pre> <span class="o">&lt;</span>!—<span class="n">Extender</span> <span class="n">Pattern</span> <span class="n">handler</span> <span class="n">configuration</span> <span class="o">--&gt;</span>
<span class="o">&lt;</span><span class="n">extender</span><span class="p">:</span><span class="n">extender</span>
<span class="n">extension</span><span class="p">=</span>&quot;<span class="n">My</span><span class="o">-</span><span class="n">Extension</span>&quot;
<span class="n">onArrival</span><span class="p">=</span>&quot;<span class="n">onArrival</span>&quot;
<span class="n">onDeparture</span><span class="p">=</span>&quot;<span class="n">onDeparture</span>&quot;
<span class="o">/&gt;</span>
<span class="o">&lt;</span><span class="n">callback</span> <span class="n">transition</span><span class="p">=</span>&quot;<span class="n">invalidate</span>&quot; <span class="n">method</span><span class="p">=</span>&quot;<span class="n">stopping</span>&quot; <span class="o">/&gt;</span>
<span class="o">&lt;</span><span class="n">callback</span> <span class="n">transition</span><span class="p">=</span>&quot;<span class="n">validate</span>&quot; <span class="n">method</span><span class="p">=</span>&quot;<span class="n">starting</span>&quot; <span class="o">/&gt;</span>
</pre></div>
<p></component>
</ipojo></p>
<p>{code:java|title=Annotations}
@Component
@org.apache.felix.ipojo.extender.Extender(extension="My-Extension", onArrival="onArrival", onDeparture="onDeparture")
public class Myextender {</p>
<div class="codehilite"><pre><span class="n">public</span> <span class="n">void</span> <span class="n">onArrival</span><span class="p">(</span><span class="n">Bundle</span> <span class="n">bundle</span><span class="p">,</span> <span class="n">String</span> <span class="n">extension</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span> <span class="n">handle</span> <span class="n">matching</span> <span class="n">bundle</span> <span class="n">arrival</span>
<span class="p">}</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">onDeparture</span><span class="p">(</span><span class="n">Bundle</span> <span class="n">bundle</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span> <span class="n">handler</span> <span class="n">matching</span> <span class="n">bundle</span> <span class="n">departure</span>
<span class="p">}</span>
</pre></div>
<p>}</p>
</li>
</ul>
<p>{div:class=borderedTable}
{center}
|Attribute name | Required | Default value | |
|--|--|--|--|
| extension | yes | | specifies the required extension (i.e. the required Manifest key) |
| onArrival | yes | | specifies the method called when a matching bundle arrives. The method receives the Bundle object and the extension value |
| onDeparture | yes | | specifies the method called when a matching bundle leaves. The method receives the Bundle object |
{center}
{div}
* <a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/extender-pattern-handler.html">Extender Pattern Handler</a></p>
<h1 id="whiteboard-pattern">Whiteboard Pattern<a class="headerlink" href="#whiteboard-pattern" title="Permanent link">&para;</a></h1>
<ul>
<li>Allows implementing a <code>Whiteboard pattern</code> without handling obscure details</li>
<li>
<p>The whiteboard pattern handler is implemented as an <em>external handlers</em>. To use it, deploy and start the whiteboard pattern handler bundle.</p>
<p>:::xml
<ipojo xmlns:wbp="org.apache.felix.ipojo.whiteboard">
&lt;component
classname="org.apache.felix.ipojo.test.MyWhiteBoardPattern"</p>
<blockquote>
<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">wbp</span><span class="p">:</span><span class="n">wbp</span>
<span class="n">filter</span><span class="p">=</span>&quot;<span class="p">(</span><span class="n">my</span><span class="p">.</span><span class="n">property</span><span class="p">=</span>1<span class="p">)</span>&quot;
<span class="n">onArrival</span><span class="p">=</span>&quot;<span class="n">onArrival</span>&quot;
<span class="n">onDeparture</span><span class="p">=</span>&quot;<span class="n">onDeparture</span>&quot;
<span class="n">onModification</span><span class="p">=</span>&quot;<span class="n">onModification</span>&quot;
<span class="o">/&gt;</span>
</pre></div>
</blockquote>
<div class="codehilite"><pre> <span class="o">&lt;</span><span class="n">provides</span><span class="o">/&gt;</span>
</pre></div>
<p></component></p>
<p>{code:java|title=Annotations}
@Component
@org.apache.felix.ipojo.whiteboard.Wbp(filter="(my.property=1)",
onArrival="onArrival",
onDeparture="onDeparture",
onModification="onModification")
public class WhiteBoardWIModification {</p>
<div class="codehilite"><pre><span class="n">public</span> <span class="n">void</span> <span class="n">onArrival</span><span class="p">(</span><span class="n">ServiceReference</span> <span class="n">ref</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span> <span class="p">...</span>
<span class="p">}</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">onDeparture</span><span class="p">(</span><span class="n">ServiceReference</span> <span class="n">ref</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span> <span class="p">...</span>
<span class="p">}</span>
<span class="n">public</span> <span class="n">void</span> <span class="n">onModification</span><span class="p">(</span><span class="n">ServiceReference</span> <span class="n">ref</span><span class="p">)</span> <span class="p">{</span>
<span class="o">//</span> <span class="p">...</span>
<span class="p">}</span>
</pre></div>
<p>}</p>
</li>
</ul>
<p>{center}
|Attribute name | Required | Default value | |
|--|--|--|--|
| filter | yes | | specifies LDAP filter used to detect required service providers |
| onArrival | yes | | specifies the method called when a matching service provider arrives. The method receives the ServiceReference object |
| onDeparture | yes | | specifies the method called when a matching service provider leaves. The method receives the ServiceReference object |
| omModification | no | | specifies the method called when a matching service provider is modified and is still matching. The method receives the ServiceReference object |
{center}
* <a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/white-board-pattern-handler.html">White Board Pattern Handler</a></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>