felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r883652 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Date Tue, 24 Nov 2009 11:19:09 GMT
Author: fmeschbe
Date: Tue Nov 24 11:19:06 2009
New Revision: 883652

URL: http://svn.apache.org/viewvc?rev=883652&view=rev
Log:
FELIX-1841 Prevent updating the service registration if service properties did not change
as of the configuration update (this may be the case if the configuration update only contains
modified private properties not propagated to service registration properties) (Thanks Pierre
de Rop for providing the patch)

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java?rev=883652&r1=883651&r2=883652&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Tue Nov 24 11:19:06 2009
@@ -20,6 +20,7 @@
 
 
 import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 
@@ -468,8 +469,12 @@
         {
             try
             {
+                // Don't propagate if service properties did not change.
                 final Dictionary regProps = getServiceProperties();
-                sr.setProperties( regProps );
+                if ( !servicePropertiesMatches( sr, regProps ) )
+                {
+                    sr.setProperties( regProps );
+                }
             }
             catch ( IllegalStateException ise )
             {
@@ -491,4 +496,31 @@
         // 7. everything set and done, the component has been udpated
         return true;
     }
+
+
+    /**
+     * Checks if the given service registration properties matches another set
+     * of properties.
+     *
+     * @param reg the service registration whose service properties will be
+     *      compared to the props parameter
+     * @param props the properties to be compared with the registration
+     *      service properties.
+     * @return <code>true</code> if the registration service properties equals
+     *      the prop properties, false if not.
+     */
+    private boolean servicePropertiesMatches( ServiceRegistration reg, Dictionary props )
+    {
+        Dictionary regProps = new Hashtable();
+        String[] keys = reg.getReference().getPropertyKeys();
+        for ( int i = 0; keys != null && i < keys.length; i++ )
+        {
+            if ( !keys[i].equals( org.osgi.framework.Constants.OBJECTCLASS )
+                && !keys[i].equals( org.osgi.framework.Constants.SERVICE_ID ) )
+            {
+                regProps.put( keys[i], reg.getReference().getProperty( keys[i] ) );
+            }
+        }
+        return regProps.equals( props );
+    }
 }



Mime
View raw message