You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2016/12/29 07:10:11 UTC

svn commit: r1776378 - in /felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl: ConfigurationImpl.java ConfigurationManager.java

Author: cziegeler
Date: Thu Dec 29 07:10:11 2016
New Revision: 1776378

URL: http://svn.apache.org/viewvc?rev=1776378&view=rev
Log:
FELIX-5443 : Frequent Changes cause UpdateThread to ConcurrentModificationException. Apply patch from Fabian Lange

Modified:
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java?rev=1776378&r1=1776377&r2=1776378&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java Thu Dec 29 07:10:11 2016
@@ -484,19 +484,21 @@ public class ConfigurationImpl extends C
         if ( factoryPid != null )
         {
             Factory factory = getConfigurationManager().getOrCreateFactory( factoryPid );
-            if ( factory.addPID( getPidString() ) )
-            {
-                // only write back if the pid was not already registered
-                // with the factory
-                try
+            synchronized (factory) {
+                if ( factory.addPID( getPidString() ) )
                 {
-                    factory.store();
-                }
-                catch ( IOException ioe )
-                {
-                    Log.logger.log( LogService.LOG_ERROR,
-                        "Failure storing factory {0} with new configuration {1}", new Object[]
-                            { factoryPid, getPidString(), ioe } );
+                    // only write back if the pid was not already registered
+                    // with the factory
+                    try
+                    {
+                        factory.store();
+                    }
+                    catch ( IOException ioe )
+                    {
+                        Log.logger.log( LogService.LOG_ERROR,
+                            "Failure storing factory {0} with new configuration {1}", new Object[]
+                                { factoryPid, getPidString(), ioe } );
+                    }
                 }
             }
         }

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java?rev=1776378&r1=1776377&r2=1776378&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java Thu Dec 29 07:10:11 2016
@@ -1311,63 +1311,65 @@ public class ConfigurationManager implem
                     factories = getTargetedFactories( factoryPid, sr );
                     for ( Factory factory : factories )
                     {
-                        for ( Iterator pi = factory.getPIDs().iterator(); pi.hasNext(); )
-                        {
-                            final String pid = ( String ) pi.next();
-                            ConfigurationImpl cfg;
-                            try
-                            {
-                                cfg = getConfiguration( pid );
-                            }
-                            catch ( IOException ioe )
-                            {
-                                Log.logger.log( LogService.LOG_ERROR, "Error loading configuration for {0}", new Object[]
-                                    { pid, ioe } );
-                                continue;
-                            }
-
-                            // sanity check on the configuration
-                            if ( cfg == null )
+                        synchronized (factory) {
+                            for ( Iterator pi = factory.getPIDs().iterator(); pi.hasNext(); )
                             {
-                                Log.logger.log( LogService.LOG_ERROR,
-                                    "Configuration {0} referred to by factory {1} does not exist", new Object[]
-                                        { pid, factoryPid } );
-                                factory.removePID( pid );
-                                factory.storeSilently();
-                                continue;
-                            }
-                            else if ( cfg.isNew() )
-                            {
-                                // Configuration has just been created but not yet updated
-                                // we currently just ignore it and have the update mechanism
-                                // provide the configuration to the ManagedServiceFactory
-                                // As of FELIX-612 (not storing new factory configurations)
-                                // this should not happen. We keep this for added stability
-                                // but raise the logging level to error.
-                                Log.logger.log( LogService.LOG_ERROR, "Ignoring new configuration pid={0}", new Object[]
-                                    { pid } );
-                                continue;
-                            }
+                                final String pid = ( String ) pi.next();
+                                ConfigurationImpl cfg;
+                                try
+                                {
+                                    cfg = getConfiguration( pid );
+                                }
+                                catch ( IOException ioe )
+                                {
+                                    Log.logger.log( LogService.LOG_ERROR, "Error loading configuration for {0}", new Object[]
+                                        { pid, ioe } );
+                                    continue;
+                                }
+
+                                // sanity check on the configuration
+                                if ( cfg == null )
+                                {
+                                    Log.logger.log( LogService.LOG_ERROR,
+                                        "Configuration {0} referred to by factory {1} does not exist", new Object[]
+                                            { pid, factoryPid } );
+                                    factory.removePID( pid );
+                                    factory.storeSilently();
+                                    continue;
+                                }
+                                else if ( cfg.isNew() )
+                                {
+                                    // Configuration has just been created but not yet updated
+                                    // we currently just ignore it and have the update mechanism
+                                    // provide the configuration to the ManagedServiceFactory
+                                    // As of FELIX-612 (not storing new factory configurations)
+                                    // this should not happen. We keep this for added stability
+                                    // but raise the logging level to error.
+                                    Log.logger.log( LogService.LOG_ERROR, "Ignoring new configuration pid={0}", new Object[]
+                                        { pid } );
+                                    continue;
+                                }
+
+                                /*
+                                 * this code would catch targeted factory PIDs;
+                                 * since this is not expected any way, we can
+                                 * leave this out
+                                 */
+                                /*
+                                else if ( !factoryPid.equals( cfg.getFactoryPid() ) )
+                                {
+                                    log( LogService.LOG_ERROR,
+                                        "Configuration {0} referred to by factory {1} seems to belong to factory {2}",
+                                        new Object[]
+                                            { pid, factoryPid, cfg.getFactoryPid() } );
+                                    factory.removePID( pid );
+                                    factory.storeSilently();
+                                    continue;
+                                }
+                                */
 
-                            /*
-                             * this code would catch targeted factory PIDs;
-                             * since this is not expected any way, we can
-                             * leave this out
-                             */
-                            /*
-                            else if ( !factoryPid.equals( cfg.getFactoryPid() ) )
-                            {
-                                log( LogService.LOG_ERROR,
-                                    "Configuration {0} referred to by factory {1} seems to belong to factory {2}",
-                                    new Object[]
-                                        { pid, factoryPid, cfg.getFactoryPid() } );
-                                factory.removePID( pid );
-                                factory.storeSilently();
-                                continue;
+                                provide( factoryPid, cfg );
                             }
-                            */
-
-                            provide( factoryPid, cfg );
                         }
                     }
                 }
@@ -1674,8 +1676,10 @@ public class ConfigurationManager implem
                 try
                 {
                     Factory factory = getOrCreateFactory( factoryPid.toString() );
-                    factory.removePID( pid );
-                    factory.store();
+                    synchronized (factory) {
+                        factory.removePID( pid );
+                        factory.store();
+                    }
                 }
                 catch ( IOException ioe )
                 {