You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2012/02/09 14:26:16 UTC

svn commit: r1242319 - in /felix/trunk/ipojo: composite/src/main/java/org/apache/felix/ipojo/composite/ composite/src/main/java/org/apache/felix/ipojo/composite/instance/ core/src/main/java/org/apache/felix/ipojo/

Author: clement
Date: Thu Feb  9 13:26:16 2012
New Revision: 1242319

URL: http://svn.apache.org/viewvc?rev=1242319&view=rev
Log:
Fix FELIX-3323:
    Ipojo composite throw ClassCastException when configuration is updated thru ConfigAdmin
    
    Several issues:
    * A wrong cast
    * The reconfiguration was not propagated to instances

Modified:
    felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeFactory.java
    felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeManager.java
    felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java

Modified: felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeFactory.java?rev=1242319&r1=1242318&r2=1242319&view=diff
==============================================================================
--- felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeFactory.java (original)
+++ felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeFactory.java Thu Feb  9 13:26:16 2012
@@ -157,17 +157,20 @@ public class CompositeFactory extends Co
      * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
      */
     public synchronized void reconfigure(Dictionary properties) throws UnacceptableConfiguration, MissingHandlerException {
-        if (properties == null || properties.get("name") == null) {
-            throw new UnacceptableConfiguration("The configuration does not contains the \"name\" property");
+        if (properties == null || (properties.get("instance.name") == 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("name");
-        
-        ComponentInstance instance = (CompositeManager) m_componentInstances.get(name);
-        
-        if (instance == null) {
-            return; // The instance does not exist.
+
+        String name = (String) properties.get("instance.name");
+        if (name == null) {
+            name = (String) properties.get("name");
+        }
+
+        ComponentInstance instance = (ComponentInstance) m_componentInstances.get(name);
+        if (instance == null) { // The instance does not exists.
+            return;
         }
-        
+
         instance.reconfigure(properties); // re-configure the component
     }
 

Modified: felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeManager.java?rev=1242319&r1=1242318&r2=1242319&view=diff
==============================================================================
--- felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeManager.java (original)
+++ felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeManager.java Thu Feb  9 13:26:16 2012
@@ -33,6 +33,7 @@ import org.apache.felix.ipojo.InstanceSt
 import org.apache.felix.ipojo.ServiceContext;
 import org.apache.felix.ipojo.architecture.InstanceDescription;
 import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.util.Logger;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -85,6 +86,11 @@ public class CompositeManager implements
     private int m_state = STOPPED;
 
     /**
+     * Logger.
+     */
+    private Logger m_logger;
+
+    /**
      * Construct a new Component Manager.
      * @param factory : the factory managing the instance manager
      * @param context : the bundle context to give to the instance
@@ -97,6 +103,7 @@ public class CompositeManager implements
         m_internalContext = new CompositeServiceContext(m_context, this);
         m_handlers = handlers;
         m_description = new CompositeInstanceDescription(m_factory.getComponentDescription(), this);
+        m_logger = new Logger(m_context, this);
 
     }
 
@@ -279,8 +286,10 @@ public class CompositeManager implements
      * @see org.apache.felix.ipojo.ComponentInstance#reconfigure(java.util.Dictionary)
      */
     public void reconfigure(Dictionary configuration) {
+        m_logger.log(Logger.INFO, "Reconfiguring composite with " + configuration);
         for (int i = 0; i < m_handlers.length; i++) {
-            m_handlers[i].reconfigure(configuration);
+            m_logger.log(Logger.INFO, "Delegating reconfiguration to " + m_handlers[i].getClassName());
+            m_handlers[i].getHandler().reconfigure(configuration);
         }
     }
 

Modified: felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java?rev=1242319&r1=1242318&r2=1242319&view=diff
==============================================================================
--- felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java (original)
+++ felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java Thu Feb  9 13:26:16 2012
@@ -230,7 +230,7 @@ public class InstanceHandler extends Com
      * @param metadata : component type metadata.
      * @param configuration : instance configuration.
      * @throws ConfigurationException : occurs an instance cannot be parsed correctly.
-     * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+     * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
      */
     public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
         m_scope = getCompositeManager().getServiceContext();
@@ -323,7 +323,7 @@ public class InstanceHandler extends Com
 
     /**
      * Start method.
-     * @see org.apache.felix.ipojo.CompositeHandler#start()
+     * @see org.apache.felix.ipojo.Handler#start()
      */
     public void start() {
         for (int j = 0; j < m_factories.length; j++) {
@@ -403,7 +403,7 @@ public class InstanceHandler extends Com
     /**
      * Return the handler description, i.e. the state of created instances.
      * @return the handler description.
-     * @see org.apache.felix.ipojo.CompositeHandler#getDescription()
+     * @see org.apache.felix.ipojo.Handler#getDescription()
      */
     public HandlerDescription getDescription() {
         return m_description;
@@ -421,4 +421,18 @@ public class InstanceHandler extends Com
         return result;
     }
 
+    /**
+     * The composite is reconfigured, we check if we have a property to change.
+     * We reconfigure all contained instances.
+     * @param configuration the new instance configuration
+     */
+    public void reconfigure(Dictionary configuration) {
+        for (int i = 0; i < m_configurations.length; i++) {
+            if (m_configurations[i].getInstance() != null) {
+                info("Reconfiguring " + m_configurations[i].getInstance().getInstanceName());
+                m_configurations[i].getInstance().reconfigure(configuration);
+            }
+        }
+
+    }
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java?rev=1242319&r1=1242318&r2=1242319&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java Thu Feb  9 13:26:16 2012
@@ -631,9 +631,9 @@ public abstract class IPojoFactory imple
      * @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
      */
     public void updated(String name, Dictionary properties) throws org.osgi.service.cm.ConfigurationException {
-        InstanceManager instance;
+        ComponentInstance instance;
         synchronized (this) {
-            instance = (InstanceManager) m_componentInstances.get(name);
+            instance = (ComponentInstance) m_componentInstances.get(name);
         }
 
         if (instance == null) {