[FELIX-4467] Reduce churn when a configuration for DS is supplied and the global extender property is not changed

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1634911 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
index 8350ff4..e9389d3 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -117,6 +117,7 @@
         }
         if ( m_packageAdmin != null )
         {
+            log( LogService.LOG_INFO, m_bundle, "Stopping to restart with new globalExtender setting: " + globalExtender, null );
             //this really is a restart, not the initial start
             try
             {
@@ -129,6 +130,7 @@
         }
         try
         {
+            log( LogService.LOG_INFO, m_bundle, "Starting with globalExtender setting: " + globalExtender, null );
             super.start( context );
         }
         catch ( Exception e )
@@ -381,12 +383,14 @@
 
     @Override
     protected void debug(Bundle bundle, String msg) {
-        log( LogService.LOG_DEBUG, bundle, msg, null );
+        final String message = MessageFormat.format( msg + " bundle: {0}/{1}", bundle.getSymbolicName(), bundle.getBundleId() );
+        log( LogService.LOG_DEBUG, bundle, message, null );
     }
 
     @Override
     protected void warn(Bundle bundle, String msg, Throwable t) {
-        log( LogService.LOG_WARNING, bundle, msg, t );
+        final String message = MessageFormat.format( msg + " bundle: {0}/{1}", bundle.getSymbolicName(), bundle.getBundleId() );
+        log( LogService.LOG_WARNING, bundle, message, t );
     }
 
     @Override
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
index 1db5b0b..d7994d3 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
@@ -130,11 +130,8 @@
         managedService = ( ServiceRegistration<ManagedService> ) bundleContext.registerService("org.osgi.service.cm.ManagedService", new ScrManagedServiceServiceFactory(this),
             props);
         
-        if ( globalExtender == null)  //no config admin or no configuration
-        {
-            // configure from bundle context properties
-            configure( null );            
-        }
+        // configure from bundle context properties
+        configure( null, false );            
     }
 
     public void stop() {
@@ -153,51 +150,64 @@
     }
 
     // Called from the ScrManagedService.updated method to reconfigure
-    void configure( Dictionary<String, ?> config )
+    void configure( Dictionary<String, ?> config, boolean fromConfig )
     {
-        Boolean oldGlobalExtender = globalExtender;
-        if ( config == null )
+        Boolean newGlobalExtender;
+        Boolean oldGlobalExtender;
+        synchronized (this)
         {
-            if ( this.bundleContext == null )
+            if ( config == null )
             {
-                logLevel = LogService.LOG_ERROR;
-                factoryEnabled = false;
-                keepInstances = false;
-                infoAsService = false;
-                lockTimeout = DEFAULT_LOCK_TIMEOUT_MILLISECONDS;
-                stopTimeout = DEFAULT_STOP_TIMEOUT_MILLISECONDS;
-                globalExtender = false;
+                if (!fromConfig)
+                {
+                    if (this.bundleContext == null)
+                    {
+                        logLevel = LogService.LOG_ERROR;
+                        factoryEnabled = false;
+                        keepInstances = false;
+                        infoAsService = false;
+                        lockTimeout = DEFAULT_LOCK_TIMEOUT_MILLISECONDS;
+                        stopTimeout = DEFAULT_STOP_TIMEOUT_MILLISECONDS;
+                        newGlobalExtender = false;
+                    }
+                    else
+                    {
+                        logLevel = getDefaultLogLevel();
+                        factoryEnabled = getDefaultFactoryEnabled();
+                        keepInstances = getDefaultKeepInstances();
+                        infoAsService = getDefaultInfoAsService();
+                        lockTimeout = getDefaultLockTimeout();
+                        stopTimeout = getDefaultStopTimeout();
+                        newGlobalExtender = getDefaultGlobalExtender();
+                    }
+                }
+                else
+                {
+                    newGlobalExtender = this.globalExtender;
+                }
             }
             else
             {
-                logLevel = getDefaultLogLevel();
-                factoryEnabled = getDefaultFactoryEnabled();
-                keepInstances = getDefaultKeepInstances();
-                infoAsService = getDefaultInfoAsService();
-                lockTimeout = getDefaultLockTimeout();
-                stopTimeout = getDefaultStopTimeout();
-                globalExtender = getDefaultGlobalExtender();
+                logLevel = getLogLevel( config.get( PROP_LOGLEVEL ) );
+                factoryEnabled = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_FACTORY_ENABLED ) ) );
+                keepInstances = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_DELAYED_KEEP_INSTANCES ) ) );
+                infoAsService = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_INFO_SERVICE) ) );
+                Long timeout = ( Long ) config.get( PROP_LOCK_TIMEOUT );
+                lockTimeout = timeout == null? DEFAULT_LOCK_TIMEOUT_MILLISECONDS: timeout;
+                timeout = ( Long ) config.get( PROP_STOP_TIMEOUT );
+                stopTimeout = timeout == null? DEFAULT_STOP_TIMEOUT_MILLISECONDS: timeout;
+                newGlobalExtender = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_GLOBAL_EXTENDER) ) );
             }
+            if ( scrCommand != null )
+            {
+                scrCommand.update( infoAsService() );
+            }
+            oldGlobalExtender = this.globalExtender;
+            this.globalExtender = newGlobalExtender;
         }
-        else
+        if ( newGlobalExtender != oldGlobalExtender )
         {
-            logLevel = getLogLevel( config.get( PROP_LOGLEVEL ) );
-            factoryEnabled = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_FACTORY_ENABLED ) ) );
-            keepInstances = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_DELAYED_KEEP_INSTANCES ) ) );
-            infoAsService = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_INFO_SERVICE) ) );
-            Long timeout = ( Long ) config.get( PROP_LOCK_TIMEOUT );
-            lockTimeout = timeout == null? DEFAULT_LOCK_TIMEOUT_MILLISECONDS: timeout;
-            timeout = ( Long ) config.get( PROP_STOP_TIMEOUT );
-            stopTimeout = timeout == null? DEFAULT_STOP_TIMEOUT_MILLISECONDS: timeout;
-            globalExtender = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_GLOBAL_EXTENDER) ) );
-        }
-        if ( scrCommand != null )
-        {
-            scrCommand.update( infoAsService() );
-        }
-        if ( globalExtender != oldGlobalExtender )
-        {
-            activator.restart( globalExtender );
+            activator.restart( newGlobalExtender );
         }
     }
 
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedService.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedService.java
index d2973c9..de876d0 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedService.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedService.java
@@ -52,6 +52,6 @@
 
     public void updated(Dictionary<String, ?> properties) throws ConfigurationException
     {
-        this.scrConfiguration.configure(properties);
+        this.scrConfiguration.configure(properties, true);
     }
 }