felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Felix > iPOJO FAQ
Date Thu, 27 May 2010 16:18:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=FELIX&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="http://cwiki.apache.org/confluence/display/FELIX/iPOJO+FAQ">iPOJO
FAQ</a></h2>
    <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~clement.escoffier">Clement
Escoffier</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >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. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2.
Using a different version of the manipulator during the manipulation <br>You can configure
the version of the manipulator that you want to use when you&#39;re using the maven-ipojo-plugin
or the iPOJO ant task. This allows to benefit latest improvements. <br> <br>For
Maven, Just declare a dependency of the maven-ipojo-plugin <br>{code:xml|title=Maven}
<br>&lt;plugin&gt; <br>        &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
<br>        &lt;artifactId&gt;maven-ipojo-plugin&lt;/artifactId&gt;
<br>        &lt;executions&gt; <br>          &lt;execution&gt;
<br>            &lt;goals&gt; <br>              &lt;goal&gt;ipojo-bundle&lt;/goal&gt;
<br>            &lt;/goals&gt; <br>          &lt;/execution&gt;
<br>        &lt;/executions&gt; <br>        &lt;dependencies&gt;
<br>        	&lt;dependency&gt; <br>        		&lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
<br>        		&lt;artifactId&gt;org.apache.felix.ipojo.manipulator&lt;/artifactId&gt;
<br>        		&lt;version&gt;1.6.2&lt;/version&gt; <br>      
 	&lt;/dependency&gt; <br>        &lt;/dependencies&gt; <br> 
    &lt;/plugin&gt; <br>{code} <br> <br>For Ant, just configure
the classpath of the iPOJO ant task with the Manipulator that you want to use: <br>{code:xml|title=Ant}
<br>&lt;taskdef name=&quot;ipojo&quot; <br>        classname=&quot;org.apache.felix.ipojo.task.IPojoTask&quot;
<br>        classpath=&quot;lib/org.apache.felix.ipojo.ant-1.6.2-SNAPSHOT.jar&quot;
/&gt; <br>{code} <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2. Callbacks order.  <br>A
lot of handlers define callbacks to notify the implementation class. The &#39;core&#39;
callbacks are called in the following order: <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <style type="text/css">
 @import url(http://felix.apache.org/ipojo/site/superfish.css); 
</style>

<style type="text/css">
 @import url(http://felix.apache.org/ipojo/site/style.css); 
</style>

<p>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>

<script type="text/javascript" src="http://felix.apache.org/ipojo/site/jquery-1.js"></script>
<script type="text/javascript" src="http://felix.apache.org/ipojo/site/hoverIntent.js"></script>
<script type="text/javascript" src="http://felix.apache.org/ipojo/site/superfish.js"></script>

<script type="text/javascript" src="http://felix.apache.org/ipojo/site/supersubs.js"></script>


<script type="text/javascript"> 
 
    $(document).ready(function(){ 
        $("ul.sf-menu").supersubs({ 
            minWidth:    14,   // minimum width of sub-menus in em units 
            maxWidth:    30,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish();  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
    }); 
 
</script>
<div class="main">
<div class="page-header"/>
<img src="http://felix.apache.org/ipojo/site/header.png" class="header">
<a href="http://ipojo.org"><img src="http://felix.apache.org/ipojo/site/ipojo.png"
width="225" class="header-logo"></a>
<ul class="sf-menu sf-js-enabled sf-shadow" id="ipojo-menu">
<li class="current">
<!-- Menu Overview -->
<a href="#" class="sf-with-ul">Overview<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
<ul>
	<li>
	<a href="/confluence/display/FELIX/Apache+Felix+iPOJO" title="Apache Felix iPOJO">Home</a>
						
	</li>
	<li>
	<a href="/confluence/display/FELIX/apache-felix-ipojo-why-choose-ipojo" title="apache-felix-ipojo-why-choose-ipojo">Why
choose iPOJO</a>
	</li>
	<li>
	<a href="/confluence/display/FELIX/apache-felix-ipojo-successstories" title="apache-felix-ipojo-successstories">Success
stories</a>
	</li>
	<li>
	<a href="/confluence/display/FELIX/Apache+Felix+iPOJO+Feature+Overview" title="Apache
Felix iPOJO Feature Overview">Features</a>
	</li>
</ul>
</li>	

<li class="">			
<!-- Menu download -->
<li>
<a href="/confluence/display/FELIX/Download" title="Download">Download </a>
</li>

<li class="">					
<!-- Menu Documentation -->
<a href="#" class="sf-with-ul">Documentation<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
<ul>
    <!-- sub-menu : getting started -->
    <li class="">
    <a href="#" class="sf-with-ul">Getting Started<span class="sf-sub-indicator">
»</span><span class="sf-sub-indicator"> »</span></a>
    <ul>
     <li><a href="/confluence/display/FELIX/iPOJO+in+10+minutes" title="iPOJO in
10 minutes">iPOJO in 10 minutes</a></li>
     <li><a href="/confluence/display/FELIX/How+to+use+iPOJO+Annotations" title="How
to use iPOJO Annotations">Using Annotations</a></li>
     <li><a href="/confluence/display/FELIX/iPOJO+Hello+Word+%28Maven-Based%29+tutorial"
title="iPOJO Hello Word (Maven-Based) tutorial">Maven tutorial</a></li>
     <li><a href="/confluence/display/FELIX/iPOJO+Advanced+Tutorial" title="iPOJO
Advanced Tutorial">Advanced tutorial</a></li>
     <li><a href="/confluence/display/FELIX/apache-felix-ipojo-dosgi" title="apache-felix-ipojo-dosgi">Using
Distributed OSGi</a></li>
     <li><a href="/confluence/display/FELIX/iPOJO+Composition+Tutorial" title="iPOJO
Composition Tutorial">Application Composition</a></li>
    </ul>
    </li> <!-- end of getting started -->
    <!-- sub menu : Describing Components -->
     <li class="">
        <a href="http://felix.apache.org/site/describing-components.html" class="sf-with-ul">Describing
components<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator">
»</span></a>
        <ul>
        <li><a href="/confluence/display/FELIX/Service+Requirement+Handler" title="Service
Requirement Handler">Requiring a service</a></li>
        <li><a href="/confluence/display/FELIX/Providing+OSGi+services" title="Providing
OSGi services">Providing a service</a></li>
        <li><a href="/confluence/display/FELIX/Lifecycle+Callback+Handler" title="Lifecycle
Callback Handler">Lifecycle management</a></li>
        <li><a href="/confluence/display/FELIX/Configuration+Handler" title="Configuration
Handler">Configuration</a></li>
        <li><a href="/confluence/display/FELIX/Architecture+Handler" title="Architecture
Handler">Introspection</a></li>
        <li><a href="/confluence/display/FELIX/Controller+Lifecycle+Handler" title="Controller
Lifecycle Handler">Impacting the lifecycle</a></li>
        <li><a href="/confluence/display/FELIX/Event+Admin+Handlers" title="Event
Admin Handlers">Asynchronous communication</a></li>
        <li><a href="/confluence/display/FELIX/iPOJO+JMX+Handler" title="iPOJO JMX
Handler">JMX management</a></li>
        <li><a href="/confluence/display/FELIX/Extender+Pattern+Handler" title="Extender
Pattern Handler">Extender pattern</a></li>
        <li><a href="/confluence/display/FELIX/White+Board+Pattern+Handler" title="White
Board Pattern Handler">Whiteboard pattern</a></li>
        <li><a href="/confluence/display/FELIX/Temporal+Service+Dependency" title="Temporal
Service Dependency">Temporal dependencies</a></li>
        </ul>
     </li> <!-- End of describing components -->
    <!-- sub-menu : User Guide -->
    <li class="">
    <a href="" class="sf-with-ul">User Guide<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
        <ul>
        <li><a href="/confluence/display/FELIX/Combining+iPOJO+and+Configuration+Admin"
title="Combining iPOJO and Configuration Admin">iPOJO and config admin</a></li>
        <li><a href="/confluence/display/FELIX/How-to+use+iPOJO+factories" title="How-to
use iPOJO factories">Factories and Instances</a></li>
        <li><a href="/confluence/display/FELIX/Using+XML+Schemas" title="Using XML
Schemas">XML Schemas</a></li>
        <li><a href="/confluence/display/FELIX/apache-felix-ipojo-api" title="apache-felix-ipojo-api">API</a></li>
        <li><a href="/confluence/display/FELIX/apache-felix-ipojo-testing-components"
title="apache-felix-ipojo-testing-components">Testing components</a></li>
        <li><a href="/confluence/display/FELIX/apache-felix-ipojo-eclipse-integration"
title="apache-felix-ipojo-eclipse-integration">Eclipse Integration</a></li>
        <li><a href="/confluence/display/FELIX/iPOJO+FAQ" title="iPOJO FAQ">FAQ</a></li>
        <li><a href="/confluence/display/FELIX/iPOJO-Reference-Card" title="iPOJO-Reference-Card">Reference
Card</a></li>
        </ul>
    </li> <!-- end of user guide -->
    <!-- sub-menu : Dev Guide -->
    <li> 
    <a href="#" class="sf-with-ul">Advanced Topics<span class="sf-sub-indicator">
»</span><span class="sf-sub-indicator"> »</span></a>
       <ul>
        <li><a href="http://felix.apache.org/ipojo/api/1.6.0" class="external-link"
rel="nofollow">Javadoc</a></li>
        <li><a href="/confluence/display/FELIX/How+to+write+your+own+handler" title="How
to write your own handler">Handler development</a></li>
        <li><a href="/confluence/display/FELIX/How+to+use+iPOJO+Manipulation+Metadata"
title="How to use iPOJO Manipulation Metadata">Manipulation Metadata </a></li>
        <li><a href="/confluence/display/FELIX/Dive+into+the+iPOJO+Manipulation+depths"
title="Dive into the iPOJO Manipulation depths">Dive into the iPOJO Manipulation depths</a></li>
       </ul>
    </li> <!-- End of Dev guide -->
</ul> 
</li> <!-- End of doc -->
<!-- Menu 4 : Tools -->
<li class="">
<a href="#" class="sf-with-ul">Tools<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
<ul>
   <li><a href="/confluence/display/FELIX/iPOJO+Ant+Task" title="iPOJO Ant Task">Ant
Task</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO+Eclipse+Plug-in" title="iPOJO Eclipse
Plug-in">Eclipse Plugin</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO+Maven+Plug-in" title="iPOJO Maven
Plug-in">Maven Plugin</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO-Arch-Command" title="iPOJO-Arch-Command"><tt>arch</tt>
shell command</a></li>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-online-manipulator"
title="apache-felix-ipojo-online-manipulator">Online Manipulator</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO+Webconsole+Plugin" title="iPOJO Webconsole
Plugin">Webconsole plugin</a></li>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-junit4osgi" title="apache-felix-ipojo-junit4osgi">Junit4OSGi</a></li>
</ul>   
</li><!-- End of tools -->	
<!-- Menu 5 : Support -->
<li>
<a href="/confluence/display/FELIX/ipojo-support" title="ipojo-support">Support </a>
</li>
<!-- End of the menu 5 -->			
<!-- Menu 6 : Misc -->
<li class="">
<a href="#" class="sf-with-ul">Misc<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
<ul>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-supportedVMs" title="apache-felix-ipojo-supportedVMs">Supported
JVMs</a></li>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-supportedOSGi" title="apache-felix-ipojo-supportedOSGi">Supported
OSGi Implementations</a></li>
   <li><a href="http://ipojo-dark-side.blogspot.com" class="external-link" rel="nofollow">iPOJO's
Dark Side Blog</a></li>
   <li><a href="/confluence/pages/viewpage.action?pageId=54954" title="Article &amp;
Presentations">Article &amp; Presentations</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><!-- End of misc -->
</ul> <!-- End of the menu -->
</div> <!-- Page header -->
</p>

<div class="content">


<h1><a name="iPOJOFAQ-ApacheFelixiPOJOFAQ"></a>Apache Felix iPOJO FAQ</h1>

<div class="toc"><div>
<ul>
    <li><a href='#iPOJOFAQ-InjectingthebundlecontextinaPOJO'>Injecting the bundle
context in a POJO</a></li>
    <li><a href='#iPOJOFAQ-Accessingservicesinsideinnerandanonymousclasses'>Accessing
services inside inner and anonymous classes</a></li>
    <li><a href='#iPOJOFAQ-Usingadifferentversionofthemanipulatorduringthemanipulation'>Using
a different version of the manipulator during the manipulation</a></li>
    <li><a href='#iPOJOFAQ-Callbacksorder.'>Callbacks order.</a></li>
    <li><a href='#iPOJOFAQ-CanIuseiPOJOwithotherOSGiimplementations%3F'>Can I
use iPOJO with other OSGi implementations?</a></li>
    <li><a href='#iPOJOFAQ-SettingtheiPOJOloglevel'>Setting the iPOJO log level</a></li>
    <li><a href='#iPOJOFAQ-InstallingiPOJOinServiceMixKernel'>Installing iPOJO
in Service Mix Kernel</a></li>
    <li><a href='#iPOJOFAQ-iPOJOandFileInstall'>iPOJO and File Install</a></li>
    <li><a href='#iPOJOFAQ-iPOJOhandlerstartlevel'>iPOJO handler <em>start</em>
level</a></li>
    <li><a href='#iPOJOFAQ-Whydoesmybundleimportunusedpackages%3F'>Why does my
bundle import unused packages?</a></li>
</ul></div></div>

<h2><a name="iPOJOFAQ-InjectingthebundlecontextinaPOJO"></a>Injecting the
bundle context in a POJO</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 <tt>BundleContext</tt>. A POJO can receive
its bundle context as an argument of its constructor. The next code snippet shows an example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class ASimplePOJO{
	<span class="code-keyword">private</span> BundleContext context;
	<span class="code-keyword">public</span> ASimplePOJO(BundleContext bc) {
		context = bc;
		<span class="code-comment">// <span class="code-keyword">do</span> something...
</span>	}}
</pre>
</div></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><a name="iPOJOFAQ-Accessingservicesinsideinnerandanonymousclasses"></a>Accessing
services inside inner and anonymous classes</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:<br/>
<a href="http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html" class="external-link"
rel="nofollow">http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html</a></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><a name="iPOJOFAQ-Usingadifferentversionofthemanipulatorduringthemanipulation"></a>Using
a different version of the manipulator during the manipulation</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 of the maven-ipojo-plugin</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Maven</b></div><div class="codeContent
panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;plugin&gt;</span>
        <span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span
class="code-tag">&lt;/groupId&gt;</span>
        <span class="code-tag">&lt;artifactId&gt;</span>maven-ipojo-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
        <span class="code-tag">&lt;executions&gt;</span>
          <span class="code-tag">&lt;execution&gt;</span>
            <span class="code-tag">&lt;goals&gt;</span>
              <span class="code-tag">&lt;goal&gt;</span>ipojo-bundle<span
class="code-tag">&lt;/goal&gt;</span>
            <span class="code-tag">&lt;/goals&gt;</span>
          <span class="code-tag">&lt;/execution&gt;</span>
        <span class="code-tag">&lt;/executions&gt;</span>
        <span class="code-tag">&lt;dependencies&gt;</span>
        	<span class="code-tag">&lt;dependency&gt;</span>
        		<span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span
class="code-tag">&lt;/groupId&gt;</span>
        		<span class="code-tag">&lt;artifactId&gt;</span>org.apache.felix.ipojo.manipulator<span
class="code-tag">&lt;/artifactId&gt;</span>
        		<span class="code-tag">&lt;version&gt;</span>1.6.2<span class="code-tag">&lt;/version&gt;</span>
        	<span class="code-tag">&lt;/dependency&gt;</span>
        <span class="code-tag">&lt;/dependencies&gt;</span>
      <span class="code-tag">&lt;/plugin&gt;</span>
</pre>
</div></div>

<p>For Ant, just configure the classpath of the iPOJO ant task with the Manipulator
that you want to use:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Ant</b></div><div class="codeContent
panelContent">
<pre class="code-xml">
&lt;taskdef name=<span class="code-quote">"ipojo"</span>
        classname=<span class="code-quote">"org.apache.felix.ipojo.task.IPojoTask"</span>
        classpath=<span class="code-quote">"lib/org.apache.felix.ipojo.ant-1.6.2-SNAPSHOT.jar"</span>
/&gt;
</pre>
</div></div>


<h2><a name="iPOJOFAQ-Callbacksorder."></a>Callbacks order. </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="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
@Component
@Provides
<span class="code-keyword">public</span> class CallbacksOrder <span class="code-keyword">implements</span>
MyService {

	<span class="code-keyword">public</span> CallbacksOrder() {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"1
Constructor"</span>);
	}

	@Bind
	<span class="code-keyword">public</span> void bind(LogService log) {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"2
Bind "</span> + log);
	}

	@Property(name=<span class="code-quote">"prop"</span>)
	<span class="code-keyword">public</span> void setProp(<span class="code-object">String</span>
v) {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"3
Set prop "</span> + v);
	}


	@Validate
	<span class="code-keyword">public</span> void validate() {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"4
Validate"</span>);
	}

	@PostRegistration
	<span class="code-keyword">public</span> void registered(ServiceReference ref)
{
		<span class="code-object">System</span>.out.println(<span class="code-quote">"5
Registered"</span>);
	}

	<span class="code-comment">// --- On Service Departure ---
</span>
	@Unbind
	<span class="code-keyword">public</span> void unbind(LogService log) {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"6
Unbind "</span> + log);
	}

	<span class="code-comment">// Remaining of the flow
</span>

	@PostUnregistration
	<span class="code-keyword">public</span> void unregistered(ServiceReference ref)
{
		<span class="code-object">System</span>.out.println(<span class="code-quote">"7
Unregistered"</span>);
	}

	@Invalidate
	<span class="code-keyword">public</span> void invalidate() {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"8
Invalidate"</span>);
	}

        <span class="code-comment">// --- End of the callback order
</span>
	<span class="code-keyword">public</span> void doNothing() {
		<span class="code-comment">// Do nothing...
</span>	}

}
</pre>
</div></div>

<h2><a name="iPOJOFAQ-CanIuseiPOJOwithotherOSGiimplementations%3F"></a>Can
I use iPOJO with other OSGi implementations?</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..<br/>
For further information, refer to the <a href="/confluence/display/FELIX/apache-felix-ipojo-supportedOSGi"
title="apache-felix-ipojo-supportedOSGi">supported OSGi implementations</a> page
and on this <a href="http://ipojo-dark-side.blogspot.com/2008/11/lessons-learned-from-ipojo-testing.html"
class="external-link" rel="nofollow">blog</a> post.</p>

<h2><a name="iPOJOFAQ-SettingtheiPOJOloglevel"></a>Setting the iPOJO log
level</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>
<ul>
	<li>info</li>
	<li>debug</li>
	<li>warning (default)</li>
	<li>error</li>
</ul>


<h2><a name="iPOJOFAQ-InstallingiPOJOinServiceMixKernel"></a>Installing
iPOJO in Service Mix Kernel</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="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
osgi install -s mvn:org.apache.felix/org.apache.felix.ipojo/1.2.0 
</pre>
</div></div>

<p>The iPOJO bundle is downloaded from the central maven repository.</p>

<h2><a name="iPOJOFAQ-iPOJOandFileInstall"></a>iPOJO and File Install</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"
class="external-link" rel="nofollow">ManagedService</a>) with <em>cfg</em>
files too. More information about this topic is available <a href="http://ipojo-dark-side.blogspot.com/2009/04/ipojo-and-file-install-configuring.html"
class="external-link" rel="nofollow">here</a>.</p>

<h2><a name="iPOJOFAQ-iPOJOhandlerstartlevel"></a>iPOJO handler <em>start</em>
level</h2>
<p>iPOJO Handlers have a <em>start</em> level. This is <b>not</b>
the <tt>OSGi Start Level</tt>. 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
(<tt>Integer.MAX</tt>). </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='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Changes in
the 1.3.0-SNAPSHOT</b><br />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.</td></tr></table></div>

<h2><a name="iPOJOFAQ-Whydoesmybundleimportunusedpackages%3F"></a>Why does
my bundle import unused packages?</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 <tt>org.apache.felix.ipojo</tt> package is the main iPOJO package.
Manipulated class use it to get access to injected values. The <tt>org.apache.felix.ipojo.architecture</tt>
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.
<br/>
The <tt>org.osgi.service.cm</tt> 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. <br/>
Finally, the <tt>org.osgi.service.log</tt> 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.
<br class="atl-forced-newline" />
<br class="atl-forced-newline" /></p>

 </div>
        <img src="http://felix.apache.org/ipojo/site/footer.png" class="footer">
</div>

<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>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="http://cwiki.apache.org/confluence/display/FELIX/iPOJO+FAQ">View Online</a>
        |
        <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=82868&revisedVersion=25&originalVersion=24">View
Changes</a>
                |
        <a href="http://cwiki.apache.org/confluence/display/FELIX/iPOJO+FAQ?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message