felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1453391 [1/4] - in /felix/trunk/ipojo: arch-gogo/ arch-gogo/src/main/java/org/apache/felix/ipojo/arch/gogo/ runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/ runtime/composite...
Date Wed, 06 Mar 2013 15:44:14 GMT
Author: clement
Date: Wed Mar  6 15:44:12 2013
New Revision: 1453391

URL: http://svn.apache.org/r1453391
Log:
Fix https://issues.apache.org/jira/browse/FELIX-3948

Provide the new extender model.

This work was mostly done by Guillaume Sauthier.

Added:
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Declaration.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/ExtensionDeclaration.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Status.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/TypeDeclaration.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilder.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilderException.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/BundleProcessor.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Lifecycle.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/LifecycleQueueService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/builder/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/builder/ReflectiveFactoryBuilder.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/AbstractDeclaration.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultExtensionDeclaration.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultInstanceDeclaration.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultTypeDeclaration.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/DeclarationLinker.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ChainedBundleProcessor.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ComponentsBundleProcessor.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ExtensionBundleProcessor.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ForwardingBundleProcessor.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/QueuingActivationProcessor.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/ReverseBundleProcessor.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/ExecutorQueueService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallable.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/PrefixedThreadFactory.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/Statistic.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/SynchronousQueueService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/HeaderPreferenceSelection.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/Preference.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/PreferenceQueueService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/PreferenceSelection.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/ForwardingQueueService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/Callback.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/JobInfo.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/QueueService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/Log.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/declaration/
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultExtensionDeclarationTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultInstanceDeclarationTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultTypeDeclarationTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/linker/
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/linker/DeclarationLinkerTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/processor/
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/processor/ChainedBundleProcessorTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/processor/ExtensionBundleProcessorTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/processor/ReverseBundleProcessorTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/ExecutorQueueServiceTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallableTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/PrefixedThreadFactoryTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/SynchronousQueueServiceTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/SleepingCallable.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/StringCallable.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/pref/
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/pref/HeaderPreferenceSelectionTestCase.java
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueServiceTestCase.java
Removed:
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/Extender.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
Modified:
    felix/trunk/ipojo/arch-gogo/pom.xml
    felix/trunk/ipojo/arch-gogo/src/main/java/org/apache/felix/ipojo/arch/gogo/Arch.java
    felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
    felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
    felix/trunk/ipojo/runtime/core/pom.xml
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/Factory.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/Logger.java

Modified: felix/trunk/ipojo/arch-gogo/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/arch-gogo/pom.xml?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/arch-gogo/pom.xml (original)
+++ felix/trunk/ipojo/arch-gogo/pom.xml Wed Mar  6 15:44:12 2013
@@ -40,7 +40,7 @@
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.ipojo</artifactId>
-            <version>1.6.2</version>
+            <version>1.9.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>

Modified: felix/trunk/ipojo/arch-gogo/src/main/java/org/apache/felix/ipojo/arch/gogo/Arch.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/arch-gogo/src/main/java/org/apache/felix/ipojo/arch/gogo/Arch.java?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/arch-gogo/src/main/java/org/apache/felix/ipojo/arch/gogo/Arch.java (original)
+++ felix/trunk/ipojo/arch-gogo/src/main/java/org/apache/felix/ipojo/arch/gogo/Arch.java Wed Mar  6 15:44:12 2013
@@ -19,6 +19,7 @@
 package org.apache.felix.ipojo.arch.gogo;
 
 import java.io.PrintStream;
+import java.util.Dictionary;
 
 import org.apache.felix.ipojo.ComponentInstance;
 import org.apache.felix.ipojo.Factory;
@@ -30,6 +31,9 @@ import org.apache.felix.ipojo.annotation
 import org.apache.felix.ipojo.annotations.ServiceProperty;
 import org.apache.felix.ipojo.architecture.Architecture;
 import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.extender.ExtensionDeclaration;
+import org.apache.felix.ipojo.extender.InstanceDeclaration;
+import org.apache.felix.ipojo.extender.TypeDeclaration;
 import org.apache.felix.service.command.Descriptor;
 /**
  * iPOJO Arch command giving information about the current
@@ -56,7 +60,8 @@ public class Arch {
         "instance",
         "factory",
         "factories",
-        "handlers"
+        "handlers",
+        "extensions"
     };
     
     /**
@@ -76,7 +81,16 @@ public class Arch {
      */
     @Requires(optional = true)
     private HandlerFactory[] m_handlers;
-    
+
+    @Requires(optional = true)
+    private InstanceDeclaration[] m_instances;
+
+    @Requires(optional = true)
+    private TypeDeclaration[] m_types;
+
+    @Requires(optional = true)
+    private ExtensionDeclaration[] m_extensions;
+
     /**
      * Displays iPOJO instances.
      */
@@ -95,6 +109,15 @@ public class Arch {
                 buffer.append("Instance " + instance.getName() + " -> stopped \n");
             }
         }
+
+        for (InstanceDeclaration instance : m_instances) {
+            // Only print unbound instances (others already printed above)
+            if (!instance.getStatus().isBound()) {
+                buffer.append("Instance " + name(instance.getConfiguration()) + " of type " + instance.getConfiguration().get("component") + " is not bound.\n");
+                buffer.append("  Reason: " + instance.getStatus().getMessage());
+                buffer.append("\n");
+            }
+        }
         
         if (buffer.length() == 0) {
             buffer.append("No instances \n");
@@ -102,7 +125,15 @@ public class Arch {
         
         System.out.println(buffer.toString());   
     }
-    
+
+    private String name(Dictionary<String, Object> configuration) {
+        String name = (String) configuration.get("instance.name");
+        if (name == null) {
+            name = "unnamed";
+        }
+        return name;
+    }
+
     /**
      * Displays the architecture of a specific instance.
      * @param instance the instance name
@@ -116,6 +147,17 @@ public class Arch {
                 return;
             }
         }
+
+        for (InstanceDeclaration instanceDeclaration : m_instances) {
+            if (!instanceDeclaration.getStatus().isBound()) {
+                if (instance.equals(name(instanceDeclaration.getConfiguration()))) {
+                    System.out.println("Instance " + instance + " not bound to its factory");
+                    System.out.println(" -> " + instanceDeclaration.getStatus().getMessage());
+                    return;
+                }
+            }
+        }
+
         System.err.println("Instance " + instance + " not found");
     }
     
@@ -140,7 +182,17 @@ public class Arch {
                 found = true;
             }
         }
-        
+
+
+        for (TypeDeclaration type : m_types) {
+            if (!type.getStatus().isBound()) {
+                if (factory.equals(type.getComponentName())) {
+                    System.out.println("Factory " + factory + " not bound");
+                    System.out.println(" -> " + type.getStatus().getMessage());
+                    found = true;
+                }
+            }
+        }
         if (! found) {
             System.err.println("Factory " + factory + " not found");
         }
@@ -159,6 +211,14 @@ public class Arch {
                 buffer.append("Factory " + m_factories[i].getName() + " (INVALID : " + m_factories[i].getMissingHandlers() + ") \n");
             }
         }
+
+        for (TypeDeclaration type : m_types) {
+            if (!type.getStatus().isBound()) {
+                buffer.append("Factory " + type.getComponentName() + " is not bound\n");
+                buffer.append("  Reason: " + type.getStatus().getMessage());
+                buffer.append("\n");
+            }
+        }
         
         if (buffer.length() == 0) {
             buffer.append("No factories \n");
@@ -166,7 +226,7 @@ public class Arch {
         
         System.out.println(buffer.toString());
     }
-    
+
     /**
      * Displays the list of available handlers.
      */
@@ -184,6 +244,25 @@ public class Arch {
                 out.println("Handler " + name + " (INVALID : " + m_handlers[i].getMissingHandlers() + ")");
             }
         }
+
+        for (TypeDeclaration type : m_types) {
+            if (!type.getStatus().isBound()) {
+                out.println("HandlerFactory " + type.getComponentName() + " is not bound");
+                out.println("  Reason: " + type.getStatus().getMessage());
+            }
+        }
+    }
+
+    /**
+     * Displays the list of available extensions.
+     */
+    @Descriptor("Display iPOJO extensions")
+    public void extensions() {
+        PrintStream out = System.out;
+        out.println("Available extensions:");
+        for (ExtensionDeclaration extension : m_extensions) {
+            out.println("  * " + extension.getExtensionName());
+        }
     }
 
 }

Modified: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java (original)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java Wed Mar  6 15:44:12 2013
@@ -21,8 +21,10 @@ import org.ops4j.pax.exam.spi.reactors.P
 import org.ops4j.pax.exam.spi.reactors.PerMethod;
 import org.ops4j.pax.tinybundles.core.TinyBundle;
 import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.ow2.chameleon.testing.helpers.IPOJOHelper;
 import org.ow2.chameleon.testing.helpers.OSGiHelper;
 import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
@@ -129,6 +131,8 @@ public class Common {
         }
         String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
         System.out.println("OSGi Framework : " + vendor + " - " + version);
+
+        waitForStability(bc);
     }
 
     @After
@@ -221,5 +225,75 @@ public class Common {
         fail("Assertion failed : " + s);
     }
 
+    /**
+     * Waits for stability:
+     * <ul>
+     * <li>all bundles are activated
+     * <li>service count is stable
+     * </ul>
+     * If the stability can't be reached after a specified time,
+     * the method throws a {@link IllegalStateException}.
+     * @param context the bundle context
+     * @throws IllegalStateException when the stability can't be reach after a several attempts.
+     */
+    private void waitForStability(BundleContext context) throws IllegalStateException {
+        // Wait for bundle initialization.
+        boolean bundleStability = getBundleStability(context);
+        int count = 0;
+        while (!bundleStability && count < 500) {
+            try {
+                Thread.sleep(5);
+            } catch (InterruptedException e) {
+                // Interrupted
+            }
+            count++;
+            bundleStability = getBundleStability(context);
+        }
+
+        if (count == 500) {
+            System.err.println("Bundle stability isn't reached after 500 tries");
+            throw new IllegalStateException("Cannot reach the bundle stability");
+        }
+
+        boolean serviceStability = false;
+        count = 0;
+        int count1 = 0;
+        int count2 = 0;
+        while (! serviceStability && count < 500) {
+            try {
+                ServiceReference[] refs = context.getServiceReferences((String) null, null);
+                count1 = refs.length;
+                Thread.sleep(500);
+                refs = context.getServiceReferences((String) null, null);
+                count2 = refs.length;
+                serviceStability = count1 == count2;
+            } catch (Exception e) {
+                System.err.println(e);
+                serviceStability = false;
+                // Nothing to do, while recheck the condition
+            }
+            count++;
+        }
+
+        if (count == 500) {
+            System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
+            throw new IllegalStateException("Cannot reach the service stability");
+        }
+    }
+
+    /**
+     * Are bundle stables.
+     * @param bc the bundle context
+     * @return <code>true</code> if every bundles are activated.
+     */
+    private boolean getBundleStability(BundleContext bc) {
+        boolean stability = true;
+        Bundle[] bundles = bc.getBundles();
+        for (int i = 0; i < bundles.length; i++) {
+            stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
+        }
+        return stability;
+    }
+
 
 }

Modified: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java (original)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java Wed Mar  6 15:44:12 2013
@@ -21,8 +21,10 @@ import org.ops4j.pax.exam.spi.reactors.P
 import org.ops4j.pax.exam.spi.reactors.PerMethod;
 import org.ops4j.pax.tinybundles.core.TinyBundle;
 import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.ow2.chameleon.testing.helpers.IPOJOHelper;
 import org.ow2.chameleon.testing.helpers.OSGiHelper;
 import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
@@ -129,6 +131,8 @@ public class Common {
         }
         String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
         System.out.println("OSGi Framework : " + vendor + " - " + version);
+
+        waitForStability(bc);
     }
 
     @After
@@ -221,5 +225,75 @@ public class Common {
         fail("Assertion failed : " + s);
     }
 
+    /**
+     * Waits for stability:
+     * <ul>
+     * <li>all bundles are activated
+     * <li>service count is stable
+     * </ul>
+     * If the stability can't be reached after a specified time,
+     * the method throws a {@link IllegalStateException}.
+     * @param context the bundle context
+     * @throws IllegalStateException when the stability can't be reach after a several attempts.
+     */
+    private void waitForStability(BundleContext context) throws IllegalStateException {
+        // Wait for bundle initialization.
+        boolean bundleStability = getBundleStability(context);
+        int count = 0;
+        while (!bundleStability && count < 500) {
+            try {
+                Thread.sleep(5);
+            } catch (InterruptedException e) {
+                // Interrupted
+            }
+            count++;
+            bundleStability = getBundleStability(context);
+        }
+
+        if (count == 500) {
+            System.err.println("Bundle stability isn't reached after 500 tries");
+            throw new IllegalStateException("Cannot reach the bundle stability");
+        }
+
+        boolean serviceStability = false;
+        count = 0;
+        int count1 = 0;
+        int count2 = 0;
+        while (! serviceStability && count < 500) {
+            try {
+                ServiceReference[] refs = context.getServiceReferences((String) null, null);
+                count1 = refs.length;
+                Thread.sleep(500);
+                refs = context.getServiceReferences((String) null, null);
+                count2 = refs.length;
+                serviceStability = count1 == count2;
+            } catch (Exception e) {
+                System.err.println(e);
+                serviceStability = false;
+                // Nothing to do, while recheck the condition
+            }
+            count++;
+        }
+
+        if (count == 500) {
+            System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
+            throw new IllegalStateException("Cannot reach the service stability");
+        }
+    }
+
+    /**
+     * Are bundle stables.
+     * @param bc the bundle context
+     * @return <code>true</code> if every bundles are activated.
+     */
+    private boolean getBundleStability(BundleContext bc) {
+        boolean stability = true;
+        Bundle[] bundles = bc.getBundles();
+        for (int i = 0; i < bundles.length; i++) {
+            stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
+        }
+        return stability;
+    }
+
 
 }

Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java Wed Mar  6 15:44:12 2013
@@ -19,6 +19,7 @@ import org.ops4j.pax.tinybundles.core.Ti
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.ow2.chameleon.testing.helpers.IPOJOHelper;
 import org.ow2.chameleon.testing.helpers.OSGiHelper;
 import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
@@ -79,6 +80,8 @@ public class Common {
         }
         String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
         System.out.println("OSGi Framework : " + vendor + " - " + version);
+
+        waitForStability(bc);
     }
 
     @After
@@ -152,4 +155,74 @@ public class Common {
         }
     }
 
+    /**
+     * Waits for stability:
+     * <ul>
+     * <li>all bundles are activated
+     * <li>service count is stable
+     * </ul>
+     * If the stability can't be reached after a specified time,
+     * the method throws a {@link IllegalStateException}.
+     * @param context the bundle context
+     * @throws IllegalStateException when the stability can't be reach after a several attempts.
+     */
+    private void waitForStability(BundleContext context) throws IllegalStateException {
+        // Wait for bundle initialization.
+        boolean bundleStability = getBundleStability(context);
+        int count = 0;
+        while (!bundleStability && count < 500) {
+            try {
+                Thread.sleep(5);
+            } catch (InterruptedException e) {
+                // Interrupted
+            }
+            count++;
+            bundleStability = getBundleStability(context);
+        }
+
+        if (count == 500) {
+            System.err.println("Bundle stability isn't reached after 500 tries");
+            throw new IllegalStateException("Cannot reach the bundle stability");
+        }
+
+        boolean serviceStability = false;
+        count = 0;
+        int count1 = 0;
+        int count2 = 0;
+        while (! serviceStability && count < 500) {
+            try {
+                ServiceReference[] refs = context.getServiceReferences((String) null, null);
+                count1 = refs.length;
+                Thread.sleep(500);
+                refs = context.getServiceReferences((String) null, null);
+                count2 = refs.length;
+                serviceStability = count1 == count2;
+            } catch (Exception e) {
+                System.err.println(e);
+                serviceStability = false;
+                // Nothing to do, while recheck the condition
+            }
+            count++;
+        }
+
+        if (count == 500) {
+            System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
+            throw new IllegalStateException("Cannot reach the service stability");
+        }
+    }
+
+    /**
+     * Are bundle stables.
+     * @param bc the bundle context
+     * @return <code>true</code> if every bundles are activated.
+     */
+    private boolean getBundleStability(BundleContext bc) {
+        boolean stability = true;
+        Bundle[] bundles = bc.getBundles();
+        for (int i = 0; i < bundles.length; i++) {
+            stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
+        }
+        return stability;
+    }
+
 }

Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java Wed Mar  6 15:44:12 2013
@@ -18,8 +18,10 @@ import org.ops4j.pax.exam.spi.reactors.P
 import org.ops4j.pax.exam.spi.reactors.PerMethod;
 import org.ops4j.pax.tinybundles.core.TinyBundle;
 import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.ow2.chameleon.testing.helpers.IPOJOHelper;
 import org.ow2.chameleon.testing.helpers.OSGiHelper;
 import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
@@ -126,6 +128,8 @@ public class Common {
         }
         String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
         System.out.println("OSGi Framework : " + vendor + " - " + version);
+
+        waitForStability(bc);
     }
 
     @After
@@ -212,5 +216,75 @@ public class Common {
         fail("Assertion failed : " + s);
     }
 
+    /**
+     * Waits for stability:
+     * <ul>
+     * <li>all bundles are activated
+     * <li>service count is stable
+     * </ul>
+     * If the stability can't be reached after a specified time,
+     * the method throws a {@link IllegalStateException}.
+     * @param context the bundle context
+     * @throws IllegalStateException when the stability can't be reach after a several attempts.
+     */
+    private void waitForStability(BundleContext context) throws IllegalStateException {
+        // Wait for bundle initialization.
+        boolean bundleStability = getBundleStability(context);
+        int count = 0;
+        while (!bundleStability && count < 500) {
+            try {
+                Thread.sleep(5);
+            } catch (InterruptedException e) {
+                // Interrupted
+            }
+            count++;
+            bundleStability = getBundleStability(context);
+        }
+
+        if (count == 500) {
+            System.err.println("Bundle stability isn't reached after 500 tries");
+            throw new IllegalStateException("Cannot reach the bundle stability");
+        }
+
+        boolean serviceStability = false;
+        count = 0;
+        int count1 = 0;
+        int count2 = 0;
+        while (! serviceStability && count < 500) {
+            try {
+                ServiceReference[] refs = context.getServiceReferences((String) null, null);
+                count1 = refs.length;
+                Thread.sleep(500);
+                refs = context.getServiceReferences((String) null, null);
+                count2 = refs.length;
+                serviceStability = count1 == count2;
+            } catch (Exception e) {
+                System.err.println(e);
+                serviceStability = false;
+                // Nothing to do, while recheck the condition
+            }
+            count++;
+        }
+
+        if (count == 500) {
+            System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
+            throw new IllegalStateException("Cannot reach the service stability");
+        }
+    }
+
+    /**
+     * Are bundle stables.
+     * @param bc the bundle context
+     * @return <code>true</code> if every bundles are activated.
+     */
+    private boolean getBundleStability(BundleContext bc) {
+        boolean stability = true;
+        Bundle[] bundles = bc.getBundles();
+        for (int i = 0; i < bundles.length; i++) {
+            stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
+        }
+        return stability;
+    }
+
 
 }

Modified: felix/trunk/ipojo/runtime/core/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/pom.xml?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/pom.xml (original)
+++ felix/trunk/ipojo/runtime/core/pom.xml Wed Mar  6 15:44:12 2013
@@ -84,15 +84,24 @@
                 </exclusion>
             </exclusions>
         </dependency>
+      <dependency>
+        <groupId>org.mockito</groupId>
+        <artifactId>mockito-all</artifactId>
+        <version>1.9.5</version>
+        <scope>test</scope>
+      </dependency>
     </dependencies>
     <build>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.0</version>
                 <configuration>
                     <target>1.5</target>
                     <source>1.5</source>
+                    <testTarget>1.5</testTarget>
+                    <testSource>1.5</testSource>
                 </configuration>
             </plugin>
             <plugin>
@@ -106,8 +115,7 @@
                         <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
                         <Bundle-SymbolicName>org.apache.felix.ipojo;singleton:=true</Bundle-SymbolicName>
                         <Bundle-Description>iPOJO Core Framework</Bundle-Description>
-                        <Bundle-Activator>org.apache.felix.ipojo.Extender
-                        </Bundle-Activator>
+                        <Bundle-Activator>org.apache.felix.ipojo.extender.internal.Extender</Bundle-Activator>
                         <Bundle-DocURL>
                             http://felix.apache.org/site/apache-felix-ipojo.html
                         </Bundle-DocURL>
@@ -119,6 +127,7 @@
                             org.osgi.framework;version=1.3, <!-- To support KF 2 -->
                             org.osgi.service.cm,
                             org.osgi.service.log,
+                            org.osgi.util.tracker;version=1.3,
                             !sun.io,
                             !net.sourceforge.cobertura.*, <!--  To support code coverage -->
 
@@ -136,6 +145,7 @@
                             org.apache.felix.ipojo.handlers.architecture,
                             org.apache.felix.ipojo.handlers.lifecycle.callback,
                             org.apache.felix.ipojo.handlers.lifecycle.controller,
+                            org.apache.felix.ipojo.extender.internal*,
                             META-INF.services.*,
                             <!-- ASM (Manipulator dependencies) -->
                             org.objectweb.asm.commons,
@@ -147,6 +157,9 @@
                             org.apache.felix.ipojo; version="${ipojo.package.version}",
                             org.apache.felix.ipojo.metadata; version="${ipojo.package.version}",
                             org.apache.felix.ipojo.architecture; version="${ipojo.package.version}",
+                            org.apache.felix.ipojo.extender; version="${ipojo.package.version}",
+                            org.apache.felix.ipojo.extender.builder; version="${ipojo.package.version}",
+                            org.apache.felix.ipojo.extender.queue; version="${ipojo.package.version}",
                             org.apache.felix.ipojo.parser; version="${ipojo.package.version}",
                             org.apache.felix.ipojo.util; version="${ipojo.package.version}",
                             org.apache.felix.ipojo.handlers.dependency; version="${ipojo.package.version}",

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/Factory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/Factory.java?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/Factory.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/Factory.java Wed Mar  6 15:44:12 2013
@@ -44,6 +44,17 @@ public interface Factory {
      */
     int INVALID = 0;
 
+
+    /**
+     * Instance configuration can set the instance name using this property.
+     */
+    String INSTANCE_NAME_PROPERTY = "instance.name";
+
+    /**
+     * Instance configuration can set the factory version they target using this property.
+     */
+    String FACTORY_VERSION_PROPERTY = "factory.version";
+
     /**
      * Creates an instance manager (i.e. component type instance).
      * @param configuration the configuration properties for this component.

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java Wed Mar  6 15:44:12 2013
@@ -18,18 +18,9 @@
  */
 package org.apache.felix.ipojo;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
 import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
 import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.extender.internal.Extender;
 import org.apache.felix.ipojo.metadata.Element;
 import org.apache.felix.ipojo.util.Logger;
 import org.apache.felix.ipojo.util.SecurityHelper;
@@ -39,6 +30,8 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.ManagedServiceFactory;
 
+import java.util.*;
+
 /**
  * This class defines common mechanisms of iPOJO component factories
  * (i.e. component type).
@@ -276,12 +269,12 @@ public abstract class IPojoFactory imple
 
         // Find name in the configuration
         String name;
-        if (configuration.get("instance.name") == null && configuration.get("name") == null) {
+        if (configuration.get(Factory.INSTANCE_NAME_PROPERTY) == null && configuration.get("name") == null) {
             // No name provided
             name = null;
         } else {
             // Support both instance.name & name
-            name = (String) configuration.get("instance.name");
+            name = (String) configuration.get(Factory.INSTANCE_NAME_PROPERTY);
             if (name == null) {
                 name = (String) configuration.get("name");
                 getLogger().log(Logger.WARNING, "The 'name' (" + name + ") attribute, used as the instance name, is deprecated, please use the 'instance.name' attribute");
@@ -292,9 +285,9 @@ public abstract class IPojoFactory imple
         // Generate a unique name if required and verify uniqueness
         // We extract the version from the configuration because it may help to compute a unique name by appending
         // the version to the given name.
-        String version = (String) configuration.get("factory.version");
+        String version = (String) configuration.get(Factory.FACTORY_VERSION_PROPERTY);
         name = m_generator.generate(name, version);
-        configuration.put("instance.name", name);
+        configuration.put(Factory.INSTANCE_NAME_PROPERTY, name);
 
         // Here we are sure to be valid until the end of the method.
         HandlerManager[] handlers = new HandlerManager[m_requiredHandlers.size()];
@@ -478,11 +471,11 @@ public abstract class IPojoFactory imple
      * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
      */
     public synchronized void reconfigure(Dictionary properties) throws UnacceptableConfiguration, MissingHandlerException {
-        if (properties == null || (properties.get("instance.name") == null && properties.get("name") == null)) { // Support both instance.name and name
+        if (properties == null || (properties.get(Factory.INSTANCE_NAME_PROPERTY) == null && properties.get("name") == null)) { // Support both instance.name and name
             throw new UnacceptableConfiguration("The configuration does not contains the \"instance.name\" property");
         }
 
-        String name = (String) properties.get("instance.name");
+        String name = (String) properties.get(Factory.INSTANCE_NAME_PROPERTY);
         if (name == null) {
             name = (String) properties.get("name");
         }
@@ -653,7 +646,7 @@ public abstract class IPojoFactory imple
 
         if (instance == null) {
             try {
-                properties.put("instance.name", name); // Add the name in the configuration
+                properties.put(Factory.INSTANCE_NAME_PROPERTY, name); // Add the name in the configuration
                 // If an instance with this name was created before, this creation will failed.
                 createComponentInstance(properties);
             } catch (UnacceptableConfiguration e) {
@@ -668,7 +661,7 @@ public abstract class IPojoFactory imple
             }
         } else {
             try {
-                properties.put("instance.name", name); // Add the name in the configuration
+                properties.put(Factory.INSTANCE_NAME_PROPERTY, name); // Add the name in the configuration
                 reconfigure(properties); // re-configure the component
             } catch (UnacceptableConfiguration e) {
                 m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java Wed Mar  6 15:44:12 2013
@@ -186,7 +186,7 @@ public class InstanceManager implements 
         m_className = metadata.getAttribute("classname");
 
         // Add the name
-        m_name = (String) configuration.get("instance.name");
+        m_name = (String) configuration.get(Factory.INSTANCE_NAME_PROPERTY);
 
         // Check if an object is injected in the instance
         Object obj = configuration.get("instance.object");

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java?rev=1453391&r1=1453390&r2=1453391&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java Wed Mar  6 15:44:12 2013
@@ -214,7 +214,7 @@ public class ComponentTypeDescription {
         // Add the version if set
         String v = getVersion();
         if (v != null) {
-            props.put("factory.version", v);
+            props.put(Factory.FACTORY_VERSION_PROPERTY, v);
         }
 
         props.put("component.providedServiceSpecifications", m_providedServiceSpecification);

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Declaration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Declaration.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Declaration.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Declaration.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender;
+
+/**
+ * A declaration is a creation instruction of an entity (Component type, Factory, Instance...).
+ * All declarations are exposed as services. <em>Processors</em> are tracking the adequate declaration type and create
+ * the entity.
+ * <p/>
+ * Declaration can be <em>bound</em> or <em>unbound</em> whether they are fulfilled. When they are unbound,
+ * a message or/and an error can be set.
+ */
+public interface Declaration {
+    /**
+     * Gets the declaration status.
+     *
+     * @return the current status. As Status are immutable, it returns a new object every time.
+     */
+    Status getStatus();
+
+    /**
+     * Marks the declaration bound.
+     */
+    void bind();
+
+    /**
+     * Unbinds the declaration.
+     *
+     * @param message an explanation
+     */
+    void unbind(String message);
+
+    /**
+     * Unbinds the declaration
+     *
+     * @param message   an explanation
+     * @param throwable an error
+     */
+    void unbind(String message, Throwable throwable);
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/ExtensionDeclaration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/ExtensionDeclaration.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/ExtensionDeclaration.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/ExtensionDeclaration.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender;
+
+import org.apache.felix.ipojo.extender.builder.FactoryBuilder;
+
+/**
+ * iPOJO's extension declaration.
+ * This service interface is published to instruct the extender to create a new iPOJO extension (like composite or
+ * handler).
+ */
+public interface ExtensionDeclaration extends Declaration {
+    /**
+     * The service property specifying the extension name.
+     */
+    String EXTENSION_NAME_PROPERTY = "ipojo.extension.name";
+
+    /**
+     * Gets the factory builder to use to create the factories bound to this extension.
+     *
+     * @return the factory builder.
+     */
+    FactoryBuilder getFactoryBuilder();
+
+    /**
+     * Gets the extension name. This name must be unique.
+     *
+     * @return the extension name.
+     */
+    String getExtensionName();
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender;
+
+import java.util.Dictionary;
+
+/**
+ * Service published to instruct an instance creation.
+ */
+public interface InstanceDeclaration extends Declaration {
+    /**
+     * Service property specifying the component type's name.
+     */
+    String COMPONENT_NAME_PROPERTY = "ipojo.component.name";
+
+    /**
+     * Service property specifying the component type's version.
+     */
+    String COMPONENT_VERSION_PROPERTY = "ipojo.component.version";
+
+    /**
+     * Service property specifying the instance name.
+     */
+    String INSTANCE_NAME = "ipojo.instance.name";
+
+    /**
+     * Value used when an instance configuration does not declare its name.
+     */
+    String UNNAMED_INSTANCE = "unnamed";
+
+    /**
+     * The instance configuration.
+     *
+     * @return the instance configuration
+     */
+    Dictionary<String, Object> getConfiguration();
+
+    /**
+     * @return the component type's name.
+     */
+    String getComponentName();
+
+    /**
+     * @return the component type's version, {@literal null} if not set.
+     */
+    String getComponentVersion();
+
+    /**
+     * Gets the instance name.
+     *
+     * @return the instance name, {@literal unnamed} if not specified.
+     */
+    String getInstanceName();
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Status.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Status.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Status.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/Status.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender;
+
+/**
+ * The declaration status.
+ * A declaration may be fulfilled or not (bound or not).
+ * When the declaration is unbound, a message can be given to explain the reason.
+ * Implementation are immutable.
+ */
+public interface Status {
+    /**
+     * Is the declaration fulfilled ?
+     *
+     * @return {@literal true} if the declaration is bound, {@literal false} otherwise.
+     */
+    boolean isBound();
+
+    /**
+     * Gets the unbound message if any.
+     *
+     * @return the unbound message, <code>null</code> if no message.
+     */
+    String getMessage();
+
+    /**
+     * Gets the unbound error if any.
+     *
+     * @return the unbound error, <code>null</code> if no error were set.
+     */
+    Throwable getThrowable();
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/TypeDeclaration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/TypeDeclaration.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/TypeDeclaration.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/TypeDeclaration.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender;
+
+import org.apache.felix.ipojo.metadata.Element;
+
+/**
+ * Service exposed to instruct a factory creation.
+ */
+public interface TypeDeclaration extends Declaration {
+
+    /**
+     * Get the component metadata description.
+     *
+     * @return the component metadata description.
+     */
+    Element getComponentMetadata();
+
+    /**
+     * Returns {@literal true} if the type is public
+     *
+     * @return {@literal true} if the type is public
+     */
+    boolean isPublic();
+
+    /**
+     * Gets the component type's name.
+     *
+     * @return the component type's name.
+     */
+    String getComponentName();
+
+    /**
+     * Gets the component type's version.
+     *
+     * @return the component type's version
+     */
+    String getComponentVersion();
+
+    /**
+     * Gets the targeted iPOJO Extension (primitive, composite, handler...)
+     *
+     * @return the targeted extension
+     */
+    String getExtension();
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilder.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilder.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilder.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender.builder;
+
+import org.apache.felix.ipojo.IPojoFactory;
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Interface defining the method used to build {@link IPojoFactory} instances.
+ * As each type of iPOJO factories can be different, factory builder are the common facade of all those types.
+ */
+public interface FactoryBuilder {
+
+    /**
+     * Creates an iPOJO Factory.
+     *
+     * @param bundleContext the bundle context of the bundle declaring the component type
+     * @param metadata      the metadata of the component type (<code>component</code> element).
+     * @return the iPOJO Factory instance.
+     * @throws FactoryBuilderException if the factory cannot be created.
+     */
+    IPojoFactory build(BundleContext bundleContext, Element metadata) throws FactoryBuilderException;
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilderException.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilderException.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilderException.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/builder/FactoryBuilderException.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender.builder;
+
+/**
+ * Exception thrown by {@link FactoryBuilder} when a {@link org.apache.felix.ipojo.IPojoFactory} instance cannot be
+ * created correctly.
+ */
+public class FactoryBuilderException extends Exception {
+
+    /**
+     * Creates the exception instance with the given message.
+     *
+     * @param message the message
+     */
+    public FactoryBuilderException(String message) {
+        super(message);
+    }
+
+    /**
+     * Creates the exception instance with the given message and cause.
+     *
+     * @param message the message
+     * @param cause   the cause
+     */
+    public FactoryBuilderException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender.internal;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import java.util.Dictionary;
+
+/**
+ * Common code wrapping an OSGi service.
+ */
+public abstract class AbstractService implements Lifecycle {
+
+    /**
+     * The bundle context.
+     */
+    private final BundleContext m_bundleContext;
+
+    /**
+     * The service specification.
+     */
+    private final Class<?> m_type;
+
+    /**
+     * The service registration.
+     */
+    private ServiceRegistration<?> m_registration;
+
+
+    /**
+     * Constructor.
+     * This constructor checks that the current class and the service specification are compatible.
+     *
+     * @param bundleContext the bundle context
+     * @param type          the specification
+     */
+    protected AbstractService(BundleContext bundleContext, Class<?> type) {
+        m_bundleContext = bundleContext;
+        if (!type.isAssignableFrom(getClass())) {
+            throw new IllegalArgumentException("This object is not an instance of " + type.getName());
+        }
+        m_type = type;
+    }
+
+    /**
+     * On start, registers the service.
+     */
+    public void start() {
+        m_registration = m_bundleContext.registerService(m_type.getName(), this, getServiceProperties());
+    }
+
+    /**
+     * On stop, un-registers the service.
+     */
+    public void stop() {
+        if (m_registration != null) {
+            m_registration.unregister();
+            m_registration = null;
+        }
+    }
+
+    /**
+     * @return the service properties, {@literal null} by default.
+     */
+    protected Dictionary<String, ?> getServiceProperties() {
+        return null;
+    }
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/BundleProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/BundleProcessor.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/BundleProcessor.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/BundleProcessor.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender.internal;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * Main Processor interface.
+ * A bundle processor is an extender fragment, it analyzes the bundle content and creates the entities.
+ * <p/>
+ * Notice the difference between the <code>activate / deactivate </code> methods called when a bundle is starting
+ * and stopping, and <code>start / stop</code> called when the iPOJO bundle is started and stopped.
+ */
+public interface BundleProcessor extends Lifecycle {
+    /**
+     * A bundle is started.
+     *
+     * @param bundle the bundle
+     */
+    void activate(Bundle bundle);
+
+    /**
+     * A bundle is stopping. This call is made during the stopping phase.
+     *
+     * @param bundle the bundle
+     */
+    void deactivate(Bundle bundle);
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,292 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender.internal;
+
+import org.apache.felix.ipojo.EventDispatcher;
+import org.apache.felix.ipojo.extender.internal.linker.DeclarationLinker;
+import org.apache.felix.ipojo.extender.internal.processor.ChainedBundleProcessor;
+import org.apache.felix.ipojo.extender.internal.processor.ComponentsBundleProcessor;
+import org.apache.felix.ipojo.extender.internal.processor.ExtensionBundleProcessor;
+import org.apache.felix.ipojo.extender.internal.processor.QueuingActivationProcessor;
+import org.apache.felix.ipojo.extender.internal.queue.ExecutorQueueService;
+import org.apache.felix.ipojo.extender.internal.queue.PrefixedThreadFactory;
+import org.apache.felix.ipojo.extender.internal.queue.SynchronousQueueService;
+import org.apache.felix.ipojo.extender.internal.queue.pref.HeaderPreferenceSelection;
+import org.apache.felix.ipojo.extender.internal.queue.pref.Preference;
+import org.apache.felix.ipojo.extender.internal.queue.pref.PreferenceQueueService;
+import org.apache.felix.ipojo.extender.internal.queue.pref.enforce.EnforcedQueueService;
+import org.apache.felix.ipojo.util.Logger;
+import org.osgi.framework.*;
+
+/**
+ * iPOJO main activator.
+ */
+public class Extender implements BundleActivator, SynchronousBundleListener {
+    /**
+     * Enables the iPOJO internal dispatcher.
+     * This internal dispatcher helps the OSGi framework to support large
+     * scale applications. The internal dispatcher is disabled by default.
+     */
+    static boolean DISPATCHER_ENABLED = true;
+
+    /**
+     * Disables the iPOJO asynchronous processing.
+     * When set to false, the bundles are processed in the listener thread
+     * making iPOJO usable on Google App Engine. By default, the processing
+     * is asynchronous.
+     */
+    static boolean SYNCHRONOUS_PROCESSING_ENABLED = false;
+
+    /**
+     * Property allowing to set if the internal dispatcher is enabled or disabled.
+     * Possible value are either {@literal true} or {@literal false}.
+     */
+    private static final String ENABLING_DISPATCHER = "ipojo.internal.dispatcher";
+
+    /**
+     * Property allowing to disable the asynchronous process (and so enables the
+     * synchronous processing).
+     * Possible value are either {@literal true} or {@literal false}.
+     */
+    private static final String SYNCHRONOUS_PROCESSING = "ipojo.processing.synchronous";
+
+    /**
+     * The Bundle Context of the iPOJO Core bundle.
+     */
+    private static BundleContext m_context;
+
+    /**
+     * The iPOJO Extender logger.
+     */
+    private Logger m_logger;
+
+    /**
+     * The iPOJO Bundle.
+     */
+    private Bundle m_bundle;
+
+    /**
+     * The chained processor containing all the true bundle processor.
+     */
+    private ChainedBundleProcessor m_processor;
+
+    /**
+     * Binds Instances to Factories to Extensions.
+     */
+    private DeclarationLinker m_linker;
+
+    private LifecycleQueueService m_queueService;
+
+    /**
+     * The iPOJO bundle is starting.
+     * This method configures the iPOJO system (internal dispatcher and bundle processing). Then it initiates the
+     * bundle processing.
+     * <p/>
+     * To optimize the processing, we process the iPOJO bundle first.
+     *
+     * @param context the iPOJO's bundle bundle context
+     * @throws Exception something terrible happen during startup
+     */
+    public void start(BundleContext context) throws Exception {
+        m_context = context;
+        m_bundle = context.getBundle();
+
+        m_logger = new Logger(m_context, "IPOJO-Main-Extender");
+
+        enablingDispatcher(context, m_logger);
+        enablingSynchronousProcessing(context, m_logger);
+
+        // Create the dispatcher only if required.
+        if (DISPATCHER_ENABLED) {
+            EventDispatcher.create(context);
+        }
+
+        BundleProcessor extensionBundleProcessor = new ExtensionBundleProcessor(m_logger);
+        BundleProcessor componentsProcessor = new ComponentsBundleProcessor(m_logger);
+        if (SYNCHRONOUS_PROCESSING_ENABLED) {
+            m_queueService = new EnforcedQueueService(
+                    new HeaderPreferenceSelection(),
+                    new SynchronousQueueService(context),
+                    Preference.SYNC,
+                    m_logger);
+        } else {
+            SynchronousQueueService sync = new SynchronousQueueService(context);
+            ExecutorQueueService async = new ExecutorQueueService(context, 1, new PrefixedThreadFactory("[iPOJO] "));
+            m_queueService = new PreferenceQueueService(new HeaderPreferenceSelection(), sync, async);
+
+            extensionBundleProcessor = new QueuingActivationProcessor(extensionBundleProcessor, m_queueService);
+            componentsProcessor = new QueuingActivationProcessor(componentsProcessor, m_queueService);
+        }
+        m_queueService.start();
+
+        // Start linking
+        m_linker = new DeclarationLinker(context, m_queueService);
+        m_linker.start();
+
+        m_processor = ChainedBundleProcessor.create(extensionBundleProcessor, componentsProcessor);
+
+        m_processor.start();
+
+        // Begin by initializing core handlers
+        m_processor.activate(m_bundle);
+
+        synchronized (this) {
+            // listen to any changes in bundles.
+            m_context.addBundleListener(this);
+            // compute already started bundles.
+            for (int i = 0; i < context.getBundles().length; i++) {
+                if (context.getBundles()[i].getState() == Bundle.ACTIVE) {
+                    m_processor.activate(context.getBundles()[i]);
+                }
+            }
+        }
+
+        m_logger.log(Logger.INFO, "iPOJO Main Extender started");
+    }
+
+    /**
+     * The iPOJO bundle is stopping.
+     *
+     * @param context the bundle context
+     * @throws Exception something terrible happen
+     */
+    public void stop(BundleContext context) throws Exception {
+        context.removeBundleListener(this);
+
+        m_processor.stop();
+
+        if (DISPATCHER_ENABLED) {
+            EventDispatcher.dispose();
+        }
+
+        m_linker.stop();
+        m_queueService.stop();
+
+        m_logger.log(Logger.INFO, "iPOJO Main Extender stopped");
+        m_context = null;
+    }
+
+    /**
+     * A bundle event was caught.
+     *
+     * @param event the event
+     */
+    public void bundleChanged(BundleEvent event) {
+        if (m_bundle.getBundleId() != (event.getBundle().getBundleId())) {
+            // Do not process our-self (already done)
+            switch (event.getType()) {
+                case BundleEvent.STARTED:
+                    // Put the bundle in the queue
+                    m_processor.activate(event.getBundle());
+                    break;
+                case BundleEvent.STOPPING:
+                    m_processor.deactivate(event.getBundle());
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+
+    /**
+     * Gets iPOJO bundle context.
+     *
+     * @return the iPOJO Bundle Context
+     */
+    public static BundleContext getIPOJOBundleContext() {
+        return m_context;
+    }
+
+    /**
+     * Enables or disables the internal dispatcher, so sets the
+     * {@link Extender#DISPATCHER_ENABLED} flag.
+     * This method checks if the {@link Extender#ENABLING_DISPATCHER}
+     * property is set to {@literal true}. Otherwise, the internal
+     * dispatcher is disabled. The property can be set as a system
+     * property ({@literal ipojo.internal.dispatcher}) or inside the
+     * iPOJO bundle manifest ({@literal ipojo-internal-dispatcher}).
+     *
+     * @param context the bundle context.
+     * @param logger  the logger to indicates if the internal dispatcher is set.
+     */
+    private static void enablingDispatcher(BundleContext context, Logger logger) {
+        // First check in the framework and in the system properties
+        String flag = context.getProperty(ENABLING_DISPATCHER);
+
+        // If null, look in bundle manifest
+        if (flag == null) {
+            String key = ENABLING_DISPATCHER.replace('.', '-');
+            flag = (String) context.getBundle().getHeaders().get(key);
+        }
+
+        if (flag != null) {
+            if (flag.equalsIgnoreCase("true")) {
+                Extender.DISPATCHER_ENABLED = true;
+                logger.log(Logger.INFO, "iPOJO Internal Event Dispatcher enables");
+                return;
+            }
+        }
+
+        // Either l is null, or the specified value was false
+        Extender.DISPATCHER_ENABLED = false;
+        logger.log(Logger.INFO, "iPOJO Internal Event Dispatcher disables");
+
+    }
+
+    /**
+     * Enables or disables the asynchronous processing, so sets the
+     * {@link Extender#SYNCHRONOUS_PROCESSING_ENABLED} flag.
+     * Disabling asynchronous processing avoids iPOJO to create a new
+     * thread to process bundles. So, iPOJO can be used on the
+     * Google App Engine.
+     * This method checks if the {@link Extender#SYNCHRONOUS_PROCESSING}
+     * property is set to {@literal true}. Otherwise, asynchronous processing
+     * is used (default). The property can be set as a system
+     * property ({@literal ipojo.processing.synchronous}) or inside the
+     * iPOJO bundle manifest.
+     *
+     * @param context the bundle context.
+     * @param logger  the logger to indicates if the internal dispatcher is set.
+     */
+    private static void enablingSynchronousProcessing(BundleContext context, Logger logger) {
+        String flag = context.getProperty(SYNCHRONOUS_PROCESSING);
+
+        // If null, look in bundle manifest
+        if (flag == null) {
+            String key = SYNCHRONOUS_PROCESSING.replace('.', '-');
+            flag = (String) context.getBundle().getHeaders().get(key);
+        }
+
+        if (flag != null) {
+            if (flag.equalsIgnoreCase("true")) {
+                Extender.SYNCHRONOUS_PROCESSING_ENABLED = true;
+                logger.log(Logger.INFO, "iPOJO Asynchronous processing disabled");
+                return;
+            }
+        }
+
+        // Either l is null, or the specified value was false
+        Extender.SYNCHRONOUS_PROCESSING_ENABLED = false;
+        logger.log(Logger.INFO, "iPOJO synchronous processing disabled");
+
+    }
+
+
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Lifecycle.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Lifecycle.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Lifecycle.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Lifecycle.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender.internal;
+
+/**
+ * Simple start/stop interface.
+ */
+public interface Lifecycle {
+
+    /**
+     * Start the service.
+     */
+    void start();
+
+    /**
+     * Stop the service.
+     */
+    void stop();
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/LifecycleQueueService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/LifecycleQueueService.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/LifecycleQueueService.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/LifecycleQueueService.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender.internal;
+
+import org.apache.felix.ipojo.extender.queue.QueueService;
+
+/**
+ * An interface composing {@link QueueService} and {@link Lifecycle}.
+ */
+public interface LifecycleQueueService extends QueueService, Lifecycle {
+
+}

Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java?rev=1453391&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java Wed Mar  6 15:44:12 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.ipojo.extender.internal;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleReference;
+
+import java.util.concurrent.Callable;
+
+/**
+ * A callable object implementing Bundle Reference.
+ * It makes the Bundle object accessible by the processing job.
+ * This class is intended to be extended.
+ */
+public abstract class ReferenceableCallable<T> implements Callable<T>, BundleReference {
+    /**
+     * The bundle object.
+     */
+    private final Bundle m_bundle;
+
+    /**
+     * Creates the ReferenceableCallable instance.
+     *
+     * @param bundle the associated bundle
+     */
+    protected ReferenceableCallable(Bundle bundle) {
+        m_bundle = bundle;
+    }
+
+    /**
+     * Gets the bundle object.
+     *
+     * @return the bundle
+     */
+    public Bundle getBundle() {
+        return m_bundle;
+    }
+
+}



Mime
View raw message