X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fblueprint%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fblueprint%2Fext%2FComponentProcessor.java;h=2f0709f6af8fae04096bbb963c2baf5134d89134;hb=7ce039b3e55d153fc75bc88198c49536ab83befc;hp=5daa6e4f3882dd43eb43e4621d5fd869b22c8e8f;hpb=1ecaae69e61d9eca89b7521d542ca2ec4885c98d;p=controller.git diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java index 5daa6e4f38..2f0709f6af 100644 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java +++ b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java @@ -12,12 +12,15 @@ 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; import org.apache.aries.blueprint.mutable.MutableBeanMetadata; import org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata; import org.apache.aries.util.AriesFrameworkUtil; +import org.gaul.modernizer_maven_annotations.SuppressModernizer; import org.opendaylight.controller.blueprint.BlueprintContainerRestartService; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; @@ -47,44 +50,44 @@ 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; } public void destroy() { - for(ServiceRegistration reg: managedServiceRegs) { + for (ServiceRegistration reg: managedServiceRegs) { AriesFrameworkUtil.safeUnregisterService(reg); } } @Override - public void process(ComponentDefinitionRegistry registry) { + public void process(final ComponentDefinitionRegistry registry) { LOG.debug("{}: In process", logName()); - for(String name : registry.getComponentDefinitionNames()) { + for (String name : registry.getComponentDefinitionNames()) { ComponentMetadata component = registry.getComponentDefinition(name); - if(component instanceof MutableBeanMetadata) { - processMutableBeanMetadata((MutableBeanMetadata)component); - } else if(component instanceof MutableServiceReferenceMetadata) { + if (component instanceof MutableBeanMetadata) { + processMutableBeanMetadata((MutableBeanMetadata) component); + } else if (component instanceof MutableServiceReferenceMetadata) { processServiceReferenceMetadata((MutableServiceReferenceMetadata)component); } } } - private void processServiceReferenceMetadata(MutableServiceReferenceMetadata serviceRef) { - if(!useDefaultForReferenceTypes) { + private void processServiceReferenceMetadata(final MutableServiceReferenceMetadata serviceRef) { + if (!useDefaultForReferenceTypes) { return; } @@ -95,7 +98,7 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor LOG.debug("{}: processServiceReferenceMetadata for {}, filter: {}, ext filter: {}", logName(), serviceRef.getId(), filter, extFilter); - if(Strings.isNullOrEmpty(filter) && Strings.isNullOrEmpty(extFilter)) { + if (Strings.isNullOrEmpty(filter) && Strings.isNullOrEmpty(extFilter)) { serviceRef.setFilter(DEFAULT_TYPE_FILTER); LOG.debug("{}: processServiceReferenceMetadata for {} set filter to {}", logName(), @@ -103,15 +106,15 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor } } - private void processMutableBeanMetadata(MutableBeanMetadata bean) { - if(restartDependentsOnUpdates && bean.getRuntimeClass() != null && - AbstractPropertyPlaceholder.class.isAssignableFrom(bean.getRuntimeClass())) { + 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(), bean.getRuntimeClass()); - for(BeanProperty prop: bean.getProperties()) { - if(CM_PERSISTENT_ID_PROPERTY.equals(prop.getName())) { - if(prop.getValue() instanceof ValueMetadata) { + for (BeanProperty prop : bean.getProperties()) { + if (CM_PERSISTENT_ID_PROPERTY.equals(prop.getName())) { + if (prop.getValue() instanceof ValueMetadata) { ValueMetadata persistentId = (ValueMetadata)prop.getValue(); LOG.debug("{}: Found {} property, value : {}", logName(), @@ -129,25 +132,27 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor } } + @SuppressModernizer private void registerManagedService(final String persistentId) { // Register a ManagedService so we get updates from the ConfigAdmin when the cfg file corresponding // to the persistentId changes. - ManagedService managedService = new ManagedService() { - private volatile boolean initialUpdate = true; + final ManagedService managedService = new ManagedService() { + private final AtomicBoolean initialUpdate = new AtomicBoolean(true); + private volatile Dictionary previousProperties; @Override - public void updated(Dictionary properties) { + public void updated(final Dictionary 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; } }; @@ -155,8 +160,7 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor props.put(Constants.SERVICE_PID, persistentId); props.put(Constants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName()); props.put(Constants.BUNDLE_VERSION, bundle.getHeaders().get(Constants.BUNDLE_VERSION)); - managedServiceRegs.add(bundle.getBundleContext().registerService(ManagedService.class.getName(), - managedService, props)); + managedServiceRegs.add(bundle.getBundleContext().registerService(ManagedService.class, managedService, props)); } private String logName() {