CONTROLLER-1809: De-deplicate extraneous ManagedService updates
[controller.git] / opendaylight / blueprint / src / main / java / org / opendaylight / controller / blueprint / ext / ComponentProcessor.java
index 14b3c2b849f64c6d9c63db0b588a11bec5cdeb5f..84847a14b1687f87cc7b94bdb58fb4b4eff2f7be 100644 (file)
@@ -12,6 +12,8 @@ import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
 import org.apache.aries.blueprint.ComponentDefinitionRegistryProcessor;
 import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
@@ -47,19 +49,19 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor
     private boolean restartDependentsOnUpdates;
     private boolean useDefaultForReferenceTypes;
 
-    public void setBundle(Bundle bundle) {
+    public void setBundle(final Bundle bundle) {
         this.bundle = bundle;
     }
 
-    public void setBlueprintContainerRestartService(BlueprintContainerRestartService restartService) {
+    public void setBlueprintContainerRestartService(final BlueprintContainerRestartService restartService) {
         this.blueprintContainerRestartService = restartService;
     }
 
-    public void setRestartDependentsOnUpdates(boolean restartDependentsOnUpdates) {
+    public void setRestartDependentsOnUpdates(final boolean restartDependentsOnUpdates) {
         this.restartDependentsOnUpdates = restartDependentsOnUpdates;
     }
 
-    public void setUseDefaultForReferenceTypes(boolean useDefaultForReferenceTypes) {
+    public void setUseDefaultForReferenceTypes(final boolean useDefaultForReferenceTypes) {
         this.useDefaultForReferenceTypes = useDefaultForReferenceTypes;
     }
 
@@ -70,7 +72,7 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor
     }
 
     @Override
-    public void process(ComponentDefinitionRegistry registry) {
+    public void process(final ComponentDefinitionRegistry registry) {
         LOG.debug("{}: In process",  logName());
 
         for (String name : registry.getComponentDefinitionNames()) {
@@ -83,7 +85,7 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor
         }
     }
 
-    private void processServiceReferenceMetadata(MutableServiceReferenceMetadata serviceRef) {
+    private void processServiceReferenceMetadata(final MutableServiceReferenceMetadata serviceRef) {
         if (!useDefaultForReferenceTypes) {
             return;
         }
@@ -103,7 +105,7 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor
         }
     }
 
-    private void processMutableBeanMetadata(MutableBeanMetadata bean) {
+    private void processMutableBeanMetadata(final MutableBeanMetadata bean) {
         if (restartDependentsOnUpdates && bean.getRuntimeClass() != null
                 && AbstractPropertyPlaceholder.class.isAssignableFrom(bean.getRuntimeClass())) {
             LOG.debug("{}: Found PropertyPlaceholder bean: {}, runtime {}", logName(), bean.getId(),
@@ -133,21 +135,22 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor
         // Register a ManagedService so we get updates from the ConfigAdmin when the cfg file corresponding
         // to the persistentId changes.
         final ManagedService managedService = new ManagedService() {
-            private volatile boolean initialUpdate = true;
+            private final AtomicBoolean initialUpdate = new AtomicBoolean(true);
+            private volatile Dictionary<String, ?> previousProperties;
 
             @Override
-            public void updated(Dictionary<String, ?> properties) {
+            public void updated(final Dictionary<String, ?> properties) {
                 LOG.debug("{}: ManagedService updated for persistentId {}, properties: {}, initialUpdate: {}",
                         logName(), persistentId, properties, initialUpdate);
 
                 // The first update occurs when the service is registered so ignore it as we want subsequent
                 // updates when it changes. The ConfigAdmin will send an update even if the cfg file doesn't
                 // yet exist.
-                if (initialUpdate) {
-                    initialUpdate = false;
-                } else {
+                if (!initialUpdate.compareAndSet(true, false) && !Objects.equals(previousProperties, properties)) {
                     blueprintContainerRestartService.restartContainerAndDependents(bundle);
                 }
+
+                previousProperties = properties;
             }
         };