You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by bu...@apache.org on 2013/02/03 07:45:22 UTC

svn commit: r849204 [20/33] - in /websites/staging/felix/trunk/content: ./ documentation/subprojects/ documentation/subprojects/apache-felix-ipojo/ documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/ documentation/subprojects/apac...

Modified: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/lifecycle-callback-handler.html
==============================================================================
--- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/lifecycle-callback-handler.html (original)
+++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/lifecycle-callback-handler.html Sun Feb  3 06:45:21 2013
@@ -20,9 +20,45 @@
   <head>
     <title>Apache Felix - Lifecycle Callback Handler</title>
     <link rel="icon" href="/res/favicon.ico">
-    <link rel="stylesheet" href="/res/site.css" type="text/css" media="all">
-    <link rel="stylesheet" href="/res/codehilite.css" type="text/css" media="all">
+    <link rel="stylesheet" href="/site/media.data/site.css" type="text/css" media="all">
+    <link rel="stylesheet" href="/ipojo/site/superfish.css" type="text/css" media="all">
+    <link rel="stylesheet" href="/ipojo/site/style.css" type="text/css" media="all">
     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    
+    <!--
+    <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="/ipojo/site/jquery-1.js"></script>
+    <script type="text/javascript" src="/ipojo/site/hoverIntent.js"></script>
+    <script type="text/javascript" src="/ipojo/site/superfish.js"></script> 
+    <script type="text/javascript" src="/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>
+    
   </head>
   <body>
     <div class="title">
@@ -37,182 +73,266 @@
         </a>
       </div>
     </div>
+  
+    <div class="main">
+    <div class="main">
+    <div class="page-header">
+    <img src="/ipojo/site/header.png" class="header">
+    <a href="http://ipojo.org"><img src="/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="">Home</a>                          
+        </li>
+        <li>
+        <a href="">Why choose iPOJO</a>
+        </li>
+        <li>
+        <a href="">Success stories</a>
+        </li>
+        <li>
+        <a href="">Features</a>
+        </li>
+    </ul>
+    </li>   
     
-    <div class="menu"> 
-      <p><a href="/news.html">news</a>  <br />
-<a href="/license.html">license</a>  <br />
-<a href="/downloads.cgi">downloads</a>  <br />
-<a href="/documentation.html">documentation</a>  <br />
-<a href="/mailinglists.html">mailing lists</a>  <br />
-<a href="/documentation/community/contributing.html">contributing</a>  <br />
-<a href="/sitemap.html">site map</a>  <br />
-<a href="http://www.apache.org/">asf</a>  <br />
-<a href="http://www.apache.org/security/">security</a>  <br />
-<a href="http://www.apache.org/foundation/sponsorship.html">sponsorship</a>  <br />
-<a href="http://www.apache.org/foundation/thanks.html">sponsors</a>  <br />
-</p>
-<iframe
-    src="http://www.apache.org/ads/button.html"
-    style="border-width:0; float: left"
-    frameborder="0"
-    scrolling="no"
-    width="135"
-    height="135">
-</iframe>
-    </div>
+    <li class="">           
+    <!-- Menu download -->
+    <li>
+    <a href="/downloads.cgi">Download </a>
+    </li>
     
-    <div class="main">
-      <div class="breadcrump" style="font-size: 80%;">
-        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>&nbsp;&raquo&nbsp;<a href="/documentation/subprojects.html">Apache Felix Subproject Documentation</a>&nbsp;&raquo&nbsp;<a href="/documentation/subprojects/apache-felix-ipojo.html">Apache Felix iPOJO</a>&nbsp;&raquo&nbsp;<a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide.html">apache-felix-ipojo-userguide</a>&nbsp;&raquo&nbsp;<a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components.html">Describing components</a>
-      </div>
-
+    <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="">iPOJO in 10 minutes</a></li>
+         <li><a href="">Using Annotations</a></li>
+         <li><a href="">Maven tutorial</a></li>
+         <li><a href="">Advanced tutorial</a></li>
+         <li><a href="">Using Distributed OSGi</a></li>
+         <li><a href="">Application Composition</a></li>
+        </ul>
+        </li> <!-- end of getting started -->
+        <!-- sub menu : Describing Components -->
+         <li class="">
+            <a href="" class="sf-with-ul">Describing components<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
+            <ul>
+            <li><a href="">Requiring a service</a></li>
+            <li><a href="">Providing a service</a></li>
+            <li><a href="">Lifecycle management</a></li>
+            <li><a href="">Configuration</a></li>
+            <li><a href="">Introspection</a></li>
+            <li><a href="">Impacting the lifecycle</a></li>
+            <li><a href="">Asynchronous communication</a></li>
+            <li><a href="">JMX management</a></li>
+            <li><a href="">Extender pattern</a></li>
+            <li><a href="">Whiteboard pattern</a></li>
+            <li><a href="">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="">iPOJO and config admin</a></li>
+            <li><a href="">Factories and Instances</a></li>
+            <li><a href="">XML Schemas</a></li>
+            <li><a href="">API</a></li>
+            <li><a href="">Testing components</a></li>
+            <li><a href="">Eclipse Integration</a></li>
+            <li><a href="">FAQ</a></li>
+            <li><a href="">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">Javadoc</a></li>
+            <li><a href="">Handler development</a></li>
+            <li><a href="">Manipulation Metadata </a></li>
+            <li><a href="">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="">Ant Task</a></li>
+       <li><a href="">Eclipse Plugin</a></li>
+       <li><a href="">Maven Plugin</a></li>
+       <li><a href="">`arch` shell command</a></li>
+       <li><a href="">Online Manipulator</a></li>
+       <li><a href="">Webconsole plugin</a></li>
+       <li><a href="">Junit4OSGi</a></li>
+    </ul>   
+    </li><!-- End of tools -->  
+    <!-- Menu 5 : Support -->
+    <li>
+    <a href="">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="">Supported JVMs</a></li>
+       <li><a href="">Supported OSGi Implementations</a></li>
+       <li><a href="http://ipojo-dark-side.blogspot.com">iPOJO's Dark Side Blog</a></li>
+       <li><a href="">Article & 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 -->
+  
+      <!-- 
       
       <div class="tip">
            This page is a translated version of <a href="/site/lifecycle-callback-handler.html" target="felix_cwiki">/site/lifecycle-callback-handler.html</a>. In case of
            doubt you might want to refer to the old page.
       </div>
       
+      -->
       
       <h1>Lifecycle Callback Handler</h1>
-      <p>{include:apache-felix-ipojo-header}</p>
-<div class="content">
-
-# Lifecycle callbacks
-
-*It is often necessary to create a POJO object as soon the instance becomes valid (i.e. required services are available). It is also often needed to be able to stop it nicely. This pages presents the iPOJO capabilities to achieve such actions. iPOJO allows you to invoke methods (callbacks) on the POJO object when instance's state changed. For example, it allows invoking a `start` method when the instance becomes valid and a `stop` method when the instance becomes invalid. It allows the creation of `immediate` component. This page presents how to use this handler.*
-
-{div:class=toc}
+      
+      <div class="content">
+        <h1 id="lifecycle-callbacks">Lifecycle callbacks</h1>
+<p><em>It is often necessary to create a POJO object as soon the instance becomes valid (i.e. required services are available). It is also often needed to be able to stop it nicely. This pages presents the iPOJO capabilities to achieve such actions. iPOJO allows you to invoke methods (callbacks) on the POJO object when instance's state changed. For example, it allows invoking a <code>start</code> method when the instance becomes valid and a <code>stop</code> method when the instance becomes invalid. It allows the creation of <code>immediate</code> component. This page presents how to use this handler.</em></p>
+<p>{div:class=toc}
 [TOC]
-{div}
-
-## Instance Lifecycle
-
-iPOJO instances have a very simple lifecycle. This lifecycle contains two states: `INVALID` and `VALID`. Once an instance is created, this instance can only be valid if all its plugged handlers are valid. In the most basic case it means all required services are available. For example, an instance requiring a service (and so using the dependency handler) cannot be valid if the required service is unavailable. 
-
-An instance starts and stops in the invalid state.
-
-!lifecycle.png|width=50%!
-
-## Lifecycle callback
-
-This handler supports two kinds of callback. The INVALID=>VALID callback are invoked when the instance becomes valid (at starting or when an event allows the instance to become valid). The VALID=>INVALID callback are invoked when the instance becomes invalid (at stopping or when an event invalids the instance).
-
-!callback.png!
-
-## An example
-
-Let's take an example. The following class requires a FooService and has two lifecycle callbacks: start and stop.
-
-    @Component
-    @Instantiate
-    public class Foo {
-                  @Requires
-                  FooService fs;
-
-                  @Validate
-                  private void start() {
-                           // Starting method
-                           //...
-                           fs.foo();
-                           //...
-                    }
-
-                    @Invalidate
-                    protected void stop() {
-                            // Stopping method
-                            if(fs!=null) { fs.foo(); }
-                    }
-    }
-
-You can also remove the annotations to use the XML format:
-
-    <component className="...Foo">
-           <requires field="fs"/>
-           <callback transition="validate" method="start"/>
-           <callback transition="invalidate" method="stop"/>
-    </component>
-    <instance component="...Foo"/>
-
-When an instance of this component type is created, the start method is called as soon as the `Foo` Service (service requirement) becomes available. If the `Foo` Service is no more available or when the instance is stopped, the stop method is called.
-
-The invoked methods have no argument, but could be private, protected or public. Public methods can be in parent classes too. Moreover, the `INVALID=>VALID` (validate) method can use service dependencies (the instance becomes valid means that all required services are available); however, in the stop method (invalidate) it is possible that one of these dependency can be `null`. Indeed, the departure of a service can be the cause of the instance invalidation.
-
-## Managing threads
-
-One usage of lifecycle callback is when the instance needs to create threads. Indeed, the thread can be created in the validate callback, and stopped in the invalidate method. The next class shows an example of a class handling a thread by using lifecycle callbacks.
-
-    @Component
-    @Instantiate
-    public class HelloRequesterImpl implements Runnable {
-
-        final static int DELAY=10000;
-
-        @Requires
-        HelloService[] m_hello;&nbsp; // Service Dependency
-
-        boolean end;
-
-        public void run() {
-          while (!end) {
-            try {
-            synchronized (this) {
-              for(int i = 0; i < m_hello.length; i++) {
-                System.out.println(m_hello[i].sayHello("Clement"));
-              }
-            }
-            Thread.sleep(DELAY);
-            } catch (InterruptedException ie) {
-                 /* will recheck quit */
-            }
-        }
-       }
-
-        @Validate
-        public void starting() {
-          Thread T = new Thread(this);
-          end = false;
-          T.start();
-        }
-
-        @Invalidate
-        public void stopping() { end = true; }
-
-## Invalidate callbacks and services
-The invalidate callback has to be developed defensively. Indeed, inside this callback, it might be possible that a service is no more there (the departure of this service has thrown the instance invalidation, which calls the callback). So, you must check that the service is not `null` before using it:
-
-    @Invalidate
-    public void stop() {
-      if (myservice != null) {
-        // you can use the service
-      }
-      // ...
-    }
-
-Thanks to the iPOJO synchronization model, you can be sure that if the service is available, it will be there until the end of the method.
-
-## Immediate component
-
-An instance of an `immediate` component type is instantiated as soon it becomes valid. It means that, when the instance becomes valid, the constructor of the implementation class is called. This can replace the validate callback. However, it stills a difference between the immediate and the validate callback. The constructor is call only once time. The validate callback is re-called each time the instance becomes valid. Components that do not provide services are automatically set as immediate.
-
-!constructor.png!
-
-To set a component as immediate you must add the `immediate` attribute to `component`:
-
-    @Component(immediate=true)
-    @Instantiate
-    public class MyComponent implements MyService {
-       // ...
-    }
-
-However as there is no 'destructor' in Java, the invalidate callback is necessary if some actions are needed when stopping.
-
-## Callback on several objects
-
-If you instance has created several objects (called the implementation class constructor several times), the callback is called on each object in the creation order.
+{div}</p>
+<h2 id="instance-lifecycle">Instance Lifecycle</h2>
+<p>iPOJO instances have a very simple lifecycle. This lifecycle contains two states: <code>INVALID</code> and <code>VALID</code>. Once an instance is created, this instance can only be valid if all its plugged handlers are valid. In the most basic case it means all required services are available. For example, an instance requiring a service (and so using the dependency handler) cannot be valid if the required service is unavailable. </p>
+<p>An instance starts and stops in the invalid state.</p>
+<p>!lifecycle.png|width=50%!</p>
+<h2 id="lifecycle-callback">Lifecycle callback</h2>
+<p>This handler supports two kinds of callback. The INVALID=&gt;VALID callback are invoked when the instance becomes valid (at starting or when an event allows the instance to become valid). The VALID=&gt;INVALID callback are invoked when the instance becomes invalid (at stopping or when an event invalids the instance).</p>
+<p>!callback.png!</p>
+<h2 id="an-example">An example</h2>
+<p>Let's take an example. The following class requires a FooService and has two lifecycle callbacks: start and stop.</p>
+<div class="codehilite"><pre><span class="nv">@Component</span>
+<span class="nv">@Instantiate</span>
+<span class="n">public</span> <span class="n">class</span> <span class="n">Foo</span> <span class="p">{</span>
+              <span class="nv">@Requires</span>
+              <span class="n">FooService</span> <span class="n">fs</span><span class="p">;</span>
+
+              <span class="nv">@Validate</span>
+              <span class="n">private</span> <span class="n">void</span> <span class="n">start</span><span class="p">()</span> <span class="p">{</span>
+                       <span class="sr">//</span> <span class="n">Starting</span> <span class="n">method</span>
+                       <span class="sr">//</span><span class="o">...</span>
+                       <span class="n">fs</span><span class="o">.</span><span class="n">foo</span><span class="p">();</span>
+                       <span class="sr">//</span><span class="o">...</span>
+                <span class="p">}</span>
+
+                <span class="nv">@Invalidate</span>
+                <span class="n">protected</span> <span class="n">void</span> <span class="n">stop</span><span class="p">()</span> <span class="p">{</span>
+                        <span class="sr">//</span> <span class="n">Stopping</span> <span class="n">method</span>
+                        <span class="k">if</span><span class="p">(</span><span class="n">fs</span><span class="o">!=</span><span class="n">null</span><span class="p">)</span> <span class="p">{</span> <span class="n">fs</span><span class="o">.</span><span class="n">foo</span><span class="p">();</span> <span class="p">}</span>
+                <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>You can also remove the annotations to use the XML format:</p>
+<div class="codehilite"><pre><span class="nt">&lt;component</span> <span class="na">className=</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;fs&quot;</span><span class="nt">/&gt;</span>
+       <span class="nt">&lt;callback</span> <span class="na">transition=</span><span class="s">&quot;validate&quot;</span> <span class="na">method=</span><span class="s">&quot;start&quot;</span><span class="nt">/&gt;</span>
+       <span class="nt">&lt;callback</span> <span class="na">transition=</span><span class="s">&quot;invalidate&quot;</span> <span class="na">method=</span><span class="s">&quot;stop&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;...Foo&quot;</span><span class="nt">/&gt;</span>
+</pre></div>
+
+
+<p>When an instance of this component type is created, the start method is called as soon as the <code>Foo</code> Service (service requirement) becomes available. If the <code>Foo</code> Service is no more available or when the instance is stopped, the stop method is called.</p>
+<p>The invoked methods have no argument, but could be private, protected or public. Public methods can be in parent classes too. Moreover, the <code>INVALID=&gt;VALID</code> (validate) method can use service dependencies (the instance becomes valid means that all required services are available); however, in the stop method (invalidate) it is possible that one of these dependency can be <code>null</code>. Indeed, the departure of a service can be the cause of the instance invalidation.</p>
+<h2 id="managing-threads">Managing threads</h2>
+<p>One usage of lifecycle callback is when the instance needs to create threads. Indeed, the thread can be created in the validate callback, and stopped in the invalidate method. The next class shows an example of a class handling a thread by using lifecycle callbacks.</p>
+<div class="codehilite"><pre><span class="nv">@Component</span>
+<span class="nv">@Instantiate</span>
+<span class="n">public</span> <span class="n">class</span> <span class="n">HelloRequesterImpl</span> <span class="n">implements</span> <span class="n">Runnable</span> <span class="p">{</span>
+
+    <span class="n">final</span> <span class="n">static</span> <span class="nb">int</span> <span class="n">DELAY</span><span class="o">=</span><span class="mi">10000</span><span class="p">;</span>
+
+    <span class="nv">@Requires</span>
+    <span class="n">HelloService</span><span class="o">[]</span> <span class="n">m_hello</span><span class="p">;</span><span class="o">&amp;</span><span class="n">nbsp</span><span class="p">;</span> <span class="sr">//</span> <span class="n">Service</span> <span class="n">Dependency</span>
+
+    <span class="n">boolean</span> <span class="n">end</span><span class="p">;</span>
+
+    <span class="n">public</span> <span class="n">void</span> <span class="n">run</span><span class="p">()</span> <span class="p">{</span>
+      <span class="k">while</span> <span class="p">(</span><span class="o">!</span><span class="n">end</span><span class="p">)</span> <span class="p">{</span>
+        <span class="n">try</span> <span class="p">{</span>
+        <span class="n">synchronized</span> <span class="p">(</span><span class="n">this</span><span class="p">)</span> <span class="p">{</span>
+          <span class="k">for</span><span class="p">(</span><span class="nb">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">m_hello</span><span class="o">.</span><span class="nb">length</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="n">println</span><span class="p">(</span><span class="n">m_hello</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sayHello</span><span class="p">(</span><span class="s">&quot;Clement&quot;</span><span class="p">));</span>
+          <span class="p">}</span>
+        <span class="p">}</span>
+        <span class="n">Thread</span><span class="o">.</span><span class="nb">sleep</span><span class="p">(</span><span class="n">DELAY</span><span class="p">);</span>
+        <span class="p">}</span> <span class="n">catch</span> <span class="p">(</span><span class="n">InterruptedException</span> <span class="n">ie</span><span class="p">)</span> <span class="p">{</span>
+             <span class="sr">/* will recheck quit */</span>
+        <span class="p">}</span>
+    <span class="p">}</span>
+   <span class="p">}</span>
+
+    <span class="nv">@Validate</span>
+    <span class="n">public</span> <span class="n">void</span> <span class="n">starting</span><span class="p">()</span> <span class="p">{</span>
+      <span class="n">Thread</span> <span class="n">T</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Thread</span><span class="p">(</span><span class="n">this</span><span class="p">);</span>
+      <span class="n">end</span> <span class="o">=</span> <span class="n">false</span><span class="p">;</span>
+      <span class="n">T</span><span class="o">.</span><span class="n">start</span><span class="p">();</span>
+    <span class="p">}</span>
+
+    <span class="nv">@Invalidate</span>
+    <span class="n">public</span> <span class="n">void</span> <span class="n">stopping</span><span class="p">()</span> <span class="p">{</span> <span class="n">end</span> <span class="o">=</span> <span class="n">true</span><span class="p">;</span> <span class="p">}</span>
+</pre></div>
+
+
+<h2 id="invalidate-callbacks-and-services">Invalidate callbacks and services</h2>
+<p>The invalidate callback has to be developed defensively. Indeed, inside this callback, it might be possible that a service is no more there (the departure of this service has thrown the instance invalidation, which calls the callback). So, you must check that the service is not <code>null</code> before using it:</p>
+<div class="codehilite"><pre><span class="nv">@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="k">if</span> <span class="p">(</span><span class="n">myservice</span> <span class="o">!=</span> <span class="n">null</span><span class="p">)</span> <span class="p">{</span>
+    <span class="sr">//</span> <span class="n">you</span> <span class="n">can</span> <span class="k">use</span> <span class="n">the</span> <span class="n">service</span>
+  <span class="p">}</span>
+  <span class="sr">//</span> <span class="o">...</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>Thanks to the iPOJO synchronization model, you can be sure that if the service is available, it will be there until the end of the method.</p>
+<h2 id="immediate-component">Immediate component</h2>
+<p>An instance of an <code>immediate</code> component type is instantiated as soon it becomes valid. It means that, when the instance becomes valid, the constructor of the implementation class is called. This can replace the validate callback. However, it stills a difference between the immediate and the validate callback. The constructor is call only once time. The validate callback is re-called each time the instance becomes valid. Components that do not provide services are automatically set as immediate.</p>
+<p>!constructor.png!</p>
+<p>To set a component as immediate you must add the <code>immediate</code> attribute to <code>component</code>:</p>
+<div class="codehilite"><pre><span class="nv">@Component</span><span class="p">(</span><span class="n">immediate</span><span class="o">=</span><span class="n">true</span><span class="p">)</span>
+<span class="nv">@Instantiate</span>
+<span class="n">public</span> <span class="n">class</span> <span class="n">MyComponent</span> <span class="n">implements</span> <span class="n">MyService</span> <span class="p">{</span>
+   <span class="sr">//</span> <span class="o">...</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>However as there is no 'destructor' in Java, the invalidate callback is necessary if some actions are needed when stopping.</p>
+<h2 id="callback-on-several-objects">Callback on several objects</h2>
+<p>If you instance has created several objects (called the implementation class constructor several times), the callback is called on each object in the creation order.</p>
+      </div>
+      
+      <img src="http://felix.apache.org/ipojo/site/footer.png" class="footer">
 
-{include:apache-felix-ipojo-footer}
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1422427 by fmeschbe on Sun, 16 Dec 2012 00:36:51 +0000
+        Rev. 1441864 by fmeschbe on Sun, 3 Feb 2013 06:44:40 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project
@@ -220,5 +340,18 @@ If you instance has created several obje
         may be trademarks or registered trademarks of their respective owners.
       </div>
     </div>
+    </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>
+
   </body>
 </html>