blob: 502bcb124f65c09297faeb0cc3710a8d49642f73 [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 FAQ</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="apache-felix-ipojo-faq">Apache Felix iPOJO FAQ<a class="headerlink" href="#apache-felix-ipojo-faq" title="Permanent link">&para;</a></h1>
<div class="toc">
<ul>
<li><a href="#apache-felix-ipojo-faq">Apache Felix iPOJO FAQ</a><ul>
<li><a href="#injecting-the-bundle-context-in-a-pojo">Injecting the bundle context in a POJO</a></li>
<li><a href="#accessing-services-inside-inner-and-anonymous-classes">Accessing services inside inner and anonymous classes</a></li>
<li><a href="#using-a-different-version-of-the-manipulator-during-the-manipulation">Using a different version of the manipulator during the manipulation</a></li>
<li><a href="#callbacks-order">Callbacks order.</a></li>
<li><a href="#disabling-proxies-in-ipojo-16">Disabling proxies in iPOJO 1.6+</a></li>
<li><a href="#use-dynamic-proxies-instead-of-smart-proxies">Use dynamic proxies instead of smart proxies</a></li>
<li><a href="#can-i-use-ipojo-with-other-osgi-implementations">Can I use iPOJO with other OSGi implementations?</a></li>
<li><a href="#detecting-optional-service-unavailability">Detecting optional service unavailability</a></li>
<li><a href="#setting-the-ipojo-log-level">Setting the iPOJO log level</a></li>
<li><a href="#installing-ipojo-in-service-mix-kernel">Installing iPOJO in Service Mix Kernel</a></li>
<li><a href="#ipojo-and-file-install">iPOJO and File Install</a></li>
<li><a href="#ipojo-handler-start-level">iPOJO handler start level</a></li>
<li><a href="#why-does-my-bundle-import-unused-packages">Why does my bundle import unused packages?</a></li>
<li><a href="#how-does-ipojo-compare-to-declarative-services-or-blueprint">How does iPOJO compare to Declarative Services or Blueprint?</a></li>
</ul>
</li>
</ul>
</div>
<h2 id="injecting-the-bundle-context-in-a-pojo">Injecting the bundle context in a POJO<a class="headerlink" href="#injecting-the-bundle-context-in-a-pojo" title="Permanent link">&para;</a></h2>
<p>It is sometimes useful to inject the bundle context in your POJO. Then, your POJO is able to deal with the OSGi environment as <em>regular</em> OSGi applications. It is possible to a POJO to get its <code>BundleContext</code>. A POJO can receive its bundle context as an argument of its constructor. The next code snippet shows an example:</p>
<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">ASimplePOJO</span><span class="o">{</span>
<span class="kd">private</span> <span class="n">BundleContext</span> <span class="n">context</span><span class="o">;</span>
<span class="kd">public</span> <span class="nf">ASimplePOJO</span><span class="o">(</span><span class="n">BundleContext</span> <span class="n">bc</span><span class="o">)</span> <span class="o">{</span>
<span class="n">context</span> <span class="o">=</span> <span class="n">bc</span><span class="o">;</span>
<span class="c1">// do something...</span>
<span class="o">}</span>
<span class="o">}</span>
</pre></div>
<p>As you see on the previous snippet, the bundle context is injected in the POJO. Then the POJO can use it as a 'normal' bundle context. The POJO code can:</p>
<ul>
<li>load classes</li>
<li>register / unregister services</li>
<li>discover, track and use services</li>
</ul>
<p>However, all these interactions are no more managed by the iPOJO container. So, be careful to manage the dynamism, synchronization, listeners...</p>
<h2 id="accessing-services-inside-inner-and-anonymous-classes">Accessing services inside inner and anonymous classes<a class="headerlink" href="#accessing-services-inside-inner-and-anonymous-classes" title="Permanent link">&para;</a></h2>
<p>An inner class is a class defined inside another class. This mechanism is useful in order to avoid creating a bunch of small files. So, it is common when creating threads, Swing listeners ... Generally speaking, inner classes are regular classes treated as separate classes. However this is an oversimplification. Some of the information about an inner class is not in its class file. See section 4.7.5 for further details on [http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html]</p>
<p>An inner class can access fields of its outer class. Since the iPOJO 1.0.0 version, fields managed by iPOJO, such as a service dependencies and properties, are also available from the inner class. Indeed, iPOJO manipulation also manipulates inner and nested classes, and accesses to outer class fields are correctly managed.</p>
<h2 id="using-a-different-version-of-the-manipulator-during-the-manipulation">Using a different version of the manipulator during the manipulation<a class="headerlink" href="#using-a-different-version-of-the-manipulator-during-the-manipulation" title="Permanent link">&para;</a></h2>
<p>You can configure the version of the manipulator that you want to use when you're using the maven-ipojo-plugin or the iPOJO ant task. This allows to benefit latest improvements.</p>
<p>For Maven, Just declare a dependency on the manipulator that you want to use in the maven-ipojo-plugin plugin section:</p>
<div class="codehilite"><pre><span class="nt">&lt;plugin&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.felix<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>maven-ipojo-plugin<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;executions&gt;</span>
<span class="nt">&lt;execution&gt;</span>
<span class="nt">&lt;goals&gt;</span>
<span class="nt">&lt;goal&gt;</span>ipojo-bundle<span class="nt">&lt;/goal&gt;</span>
<span class="nt">&lt;/goals&gt;</span>
<span class="nt">&lt;/execution&gt;</span>
<span class="nt">&lt;/executions&gt;</span>
<span class="nt">&lt;dependencies&gt;</span>
<span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.felix<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>org.apache.felix.ipojo.manipulator<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>1.12.1<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span>
<span class="nt">&lt;/dependencies&gt;</span>
<span class="nt">&lt;/plugin&gt;</span>
</pre></div>
<p>For Ant, just configure the classpath of the iPOJO ant task with the Manipulator that you want to use:</p>
<div class="codehilite"><pre><span class="nt">&lt;taskdef</span> <span class="na">name=</span><span class="s">&quot;ipojo&quot;</span>
<span class="na">classname=</span><span class="s">&quot;org.apache.felix.ipojo.task.IPojoTask&quot;</span>
<span class="na">classpath=</span><span class="s">&quot;../ipojo/manipulator/org.apache.felix.ipojo.manipulator-1.7.0-SNAPSHOT.jar; lib/org.apache.felix.ipojo.ant-1.7.0-SNAPSHOT.jar;&quot;</span> <span class="nt">/&gt;</span>
</pre></div>
<h2 id="callbacks-order">Callbacks order.<a class="headerlink" href="#callbacks-order" title="Permanent link">&para;</a></h2>
<p>A lot of handlers define callbacks to notify the implementation class. The 'core' callbacks are called in the following order:</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">CallbacksOrder</span> <span class="kd">implements</span> <span class="n">MyService</span> <span class="o">{</span>
<span class="kd">public</span> <span class="nf">CallbacksOrder</span><span class="o">()</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;1 Constructor&quot;</span><span class="o">);</span>
<span class="o">}</span>
<span class="nd">@Bind</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">bind</span><span class="o">(</span><span class="n">LogService</span> <span class="n">log</span><span class="o">)</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;2 Bind &quot;</span> <span class="o">+</span> <span class="n">log</span><span class="o">);</span>
<span class="o">}</span>
<span class="nd">@Property</span><span class="o">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;prop&quot;</span><span class="o">)</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">setProp</span><span class="o">(</span><span class="n">String</span> <span class="n">v</span><span class="o">)</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;3 Set prop &quot;</span> <span class="o">+</span> <span class="n">v</span><span class="o">);</span>
<span class="o">}</span>
<span class="nd">@Validate</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">validate</span><span class="o">()</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;4 Validate&quot;</span><span class="o">);</span>
<span class="o">}</span>
<span class="nd">@PostRegistration</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">registered</span><span class="o">(</span><span class="n">ServiceReference</span> <span class="n">ref</span><span class="o">)</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;5 Registered&quot;</span><span class="o">);</span>
<span class="o">}</span>
<span class="c1">// --- On Service Departure ---</span>
<span class="nd">@Unbind</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">unbind</span><span class="o">(</span><span class="n">LogService</span> <span class="n">log</span><span class="o">)</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;6 Unbind &quot;</span> <span class="o">+</span> <span class="n">log</span><span class="o">);</span>
<span class="o">}</span>
<span class="c1">// Remaining of the flow</span>
<span class="nd">@PostUnregistration</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">unregistered</span><span class="o">(</span><span class="n">ServiceReference</span> <span class="n">ref</span><span class="o">)</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;7 Unregistered&quot;</span><span class="o">);</span>
<span class="o">}</span>
<span class="nd">@Invalidate</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">invalidate</span><span class="o">()</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;8 Invalidate&quot;</span><span class="o">);</span>
<span class="o">}</span>
<span class="c1">// --- End of the callback order</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">doNothing</span><span class="o">()</span> <span class="o">{</span>
<span class="c1">// Do nothing...</span>
<span class="o">}</span>
<span class="o">}</span>
</pre></div>
<h2 id="disabling-proxies-in-ipojo-16">Disabling proxies in iPOJO 1.6+<a class="headerlink" href="#disabling-proxies-in-ipojo-16" title="Permanent link">&para;</a></h2>
<p>iPOJO 1.6.0 has generalized the proxy usage. However this mechanism can be disabled.</p>
<p>To disable the proxies on the entire framework, just set the property <code>ipojo.proxy</code> to <code>disabled</code> (this set the default 'proxy' value). This property is either a system property (<code>-Dipojo.proxy=disabled</code> in the command line) or a framework property (given to the framework during its initialization).</p>
<p>You can also disable proxies for specific dependencies by using the <code>proxy</code> attribute:</p>
<div class="codehilite"><pre><span class="nd">@Requires</span><span class="o">(</span><span class="n">proxy</span><span class="o">=</span><span class="kc">false</span><span class="o">)</span>
<span class="kd">private</span> <span class="n">LogService</span> <span class="n">log</span>
</pre></div>
<p>or</p>
<div class="codehilite"><pre><span class="nt">&lt;requires</span> <span class="na">field=</span><span class="s">&quot;log&quot;</span> <span class="na">proxy=</span><span class="s">&quot;false&quot;</span><span class="nt">/&gt;</span>
</pre></div>
<p>The default value of the <code>proxy</code> attribute is the value of the <code>ipojo.proxy</code> property.</p>
<h2 id="use-dynamic-proxies-instead-of-smart-proxies">Use dynamic proxies instead of smart proxies<a class="headerlink" href="#use-dynamic-proxies-instead-of-smart-proxies" title="Permanent link">&para;</a></h2>
<p>Smart proxies are generated on the fly using bytecode generation. However this mechanism may not be always supported by the VM (like Dalvik (Android)). To disabled smart proxies (used by default) and use dynamic proxy instead, set the property <code>ipojo.proxy.type</code> to <code>dynamic-proxy</code>. This property is either a system property or a framework property.</p>
<h2 id="can-i-use-ipojo-with-other-osgi-implementations">Can I use iPOJO with other OSGi implementations?<a class="headerlink" href="#can-i-use-ipojo-with-other-osgi-implementations" title="Permanent link">&para;</a></h2>
<p>iPOJO relies on the OSGi R4.1 specification, so works on any compliant implementation. Moreover, iPOJO is weekly tested on Apache Felix, Eclipse Equinox and Knopflerfish..</p>
<p>For further information, refer to the <a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-supportedosgi.html">supported OSGi implementations</a> page and on this [blog|http://ipojo-dark-side.blogspot.com/2008/11/lessons-learned-from-ipojo-testing.html] post.</p>
<h2 id="detecting-optional-service-unavailability">Detecting optional service unavailability<a class="headerlink" href="#detecting-optional-service-unavailability" title="Permanent link">&para;</a></h2>
<p>Sometimes it is useful to check if an optional service dependency is fulfilled or not. In order to propose a pretty simple development model, iPOJO injects proxies by default which avoid such check (Because proxies hide such details). By disabling proxies, you can easily check to unavailability.</p>
<ul>
<li>
<p>First, disable the proxy injection:</p>
<p>:::java
@Requires(proxy=false)
private LogService log;</p>
</li>
<li>
<p>The injected object will be a direct reference. By default, iPOJO injects a <code>Nullable</code> object, on which you can call service method without checking for <code>null</code>. To detect Nullable objects, just use <code>instanceof</code></p>
<p>:::java
@Requires(proxy=false)
private LogService log;</p>
<p>public void doSomething() {
if (log instanceof Nullable) {
// Service unavailable
} else {
// Service available
}
}</p>
</li>
<li>
<p>If you prefer injecting <code>null</code> instead of a <code>Nullable</code>, just disable Nullable injection too. However, be care to check for <code>null</code> before each invocation.</p>
<p>:::java
@Requires(proxy=false, nullable=false)
private LogService log;</p>
<p>public void doSomething() {
if (log == null) {
// Service unavailable
} else {
// Service available
}
}</p>
</li>
</ul>
<h2 id="setting-the-ipojo-log-level">Setting the iPOJO log level<a class="headerlink" href="#setting-the-ipojo-log-level" title="Permanent link">&para;</a></h2>
<p>By default, iPOJO logs only warning and error messages. There are two different methods to configure the log level. First, you can set the global log level by setting the <em>ipojo.log.level</em> system property. This replaces the default log level (warning). All iPOJO instances will be impacted. However, each bundle containing component types can specify a different log level. To set this level, add the <em>ipojo-log-level</em> header in your manifest. The possible values for these two properties are:</p>
<div class="codehilite"><pre><span class="o">*</span> <span class="n">info</span>
<span class="o">*</span> <span class="n">debug</span>
<span class="o">*</span> <span class="n">warning</span> <span class="p">(</span><span class="n">default</span><span class="p">)</span>
<span class="o">*</span> <span class="n">error</span>
</pre></div>
<h2 id="installing-ipojo-in-service-mix-kernel">Installing iPOJO in Service Mix Kernel<a class="headerlink" href="#installing-ipojo-in-service-mix-kernel" title="Permanent link">&para;</a></h2>
<p>You can use iPOJO in Service Mix Kernel. To deploy and start it, just execute the following command line in the ServiceMix Kernel Shell.</p>
<div class="codehilite"><pre>osgi install -s mvn:org.apache.felix/org.apache.felix.ipojo/1.2.0
</pre></div>
<p>The iPOJO bundle is downloaded from the central maven repository.</p>
<h2 id="ipojo-and-file-install">iPOJO and File Install<a class="headerlink" href="#ipojo-and-file-install" title="Permanent link">&para;</a></h2>
<p>Thanks to File install you can create, disposed and reconfigure instances from <em>cfg</em> files. You can also reconfiguring a creatged instance (configured to expose a <a href="http://felix.apache.org/site/configuration-handler.html#ConfigurationHandler-ExposingaManagedService">ManagedService</a>) with <em>cfg</em> files too. More information about this topic is available [here|http://ipojo-dark-side.blogspot.com/2009/04/ipojo-and-file-install-configuring.html].</p>
<h2 id="ipojo-handler-start-level">iPOJO handler <em>start</em> level<a class="headerlink" href="#ipojo-handler-start-level" title="Permanent link">&para;</a></h2>
<p>iPOJO Handlers have a <em>start</em> level. This is <em>not</em> the <code>OSGi Start Level</code>. This level is used to determine in which order handler are configured, started and stopped. Handlers with a low level are configured and started before handlers with a high level. Moreover they are stopped after handlers with a high level. By default, handlers have no level. It means that they have the maximum level (<code>Integer.MAX</code>).</p>
<p>Here are the levels of core handlers:</p>
<ul>
<li>Service Dependency: 0 (minimum level)</li>
<li>Lifecycle Callback: 1</li>
<li>Configuration Properties: 1</li>
<li>Service Providing: 3</li>
<li>Controller Handler: no level (Integer.MAX)</li>
<li>Architecture Handler: no level (Integer.MAX)</li>
</ul>
<p>From these levels, we can see that bind methods will be called before set methods from configuration properties. So, when a POJO objects, callback are called in this order:</p>
<ol>
<li>bind methods</li>
<li>validate method</li>
<li>setter methods from instance configuration</li>
</ol>
<div class="alert alert-info info" markdown="1">
<h4>Changes in the 1.3.0-SNAPSHOT</h4>
iPOJO 1.3.0-SNAPSHOT sets the lifecycle callback handler level to 2. So, setter methods from instance properties are called before the validate method.
</div>
<h2 id="why-does-my-bundle-import-unused-packages">Why does my bundle import unused packages?<a class="headerlink" href="#why-does-my-bundle-import-unused-packages" title="Permanent link">&para;</a></h2>
<p>If you check iPOJO bundle imported packages, you will see that some packages where added:</p>
<ul>
<li>org.apache.felix.ipojo;version= 1.2.0</li>
<li>org.apache.felix.ipojo.architecture;version= 1.2.0</li>
<li>org.osgi.service.cm;version=1.2</li>
<li>org.osgi.service.log;version=1.3</li>
</ul>
<p>The <code>org.apache.felix.ipojo</code> package is the main iPOJO package. Manipulated class use it to get access to injected values. The <code>org.apache.felix.ipojo.architecture</code> package is used to expose <em>Architecture</em> service (allowing instance introspection). This service is exposed with the bundle context from the bundle declaring the component type.</p>
<p>The <code>org.osgi.service.cm</code> package is imported to publish <em>ManagedService</em> and <em>ManagedServiceFactory</em> with the bundle context from the bundle declaring the component type. So, if you look for services exposed by a bundle declaring component types, you will see <em>ManagedServiceFactory</em> services.
Finally, the <code>org.osgi.service.log</code> is imported because iPOJO delegates log to a log service (if available). This service is get from the bundle context from the bundle declaring the component type. So, to get this service, the package of the service interface is imported. Then, according to implementations, log services may get the bundle logging the message.</p>
<h2 id="how-does-ipojo-compare-to-declarative-services-or-blueprint">How does iPOJO compare to Declarative Services or Blueprint?<a class="headerlink" href="#how-does-ipojo-compare-to-declarative-services-or-blueprint" title="Permanent link">&para;</a></h2>
<p>The following table highlights some of the features of each system, it does not attempt to highlight every feature of each.</p>
<table class="table table-striped">
<thead>
<tr>
<th>Dependency Injection</th>
<th>Declarative Service</th>
<th>Blueprint</th>
<th>iPOJO</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Callback injection</strong></td>
<td>Yes</td>
<td>Yes (public method only)</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Constructor injection</strong></td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Field injection</strong></td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Proxy injection</strong></td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Collections (List, Set...) injection</strong></td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Mock (<em>nullable, default-implementation</em>) injection</strong></td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
</tbody>
</table>
<p><br/></p>
<table class="table table-striped">
<thead>
<tr>
<th>Lifecycle</th>
<th>Declarative Service</th>
<th>Blueprint</th>
<th>iPOJO</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Lifecycle callbacks (activate / deactivate)</strong></td>
<td>Yes</td>
<td>Yes (public method only)</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Factory / Prototype</strong></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Lazzy initialization</strong></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Damping</strong></td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Handling of the synchronization</strong></td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Code can impact the lifecycle</strong></td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Code can impact the service publication</strong></td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
</tbody>
</table>
<p><br/>
<table class="table table-striped">
<thead>
<tr>
<th>Configuration</th>
<th>Declarative Service</th>
<th>Blueprint</th>
<th>iPOJO</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Property configuration</strong></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Property injectin inside field</strong></td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Property injection using <em>setters</em></strong></td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Configuration admin support</strong></td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Code can update the configuration</strong></td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
</tbody>
</table>
<br/>
<table class="table table-striped">
<thead>
<tr>
<th>Component configuration</th>
<th>Declarative Service</th>
<th>Blueprint</th>
<th>iPOJO</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>XML</strong></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Annotations</strong></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Defining components using an API</strong></td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td><strong>Reconfiguring components using an API</strong></td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
</tbody>
</table></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>