diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java index 63aa3e50d6..339317fdd9 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java @@ -47,6 +47,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Stack; +import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -61,7 +62,7 @@ public class StandardParameterContext implements ParameterContext { private final Authorizable parentAuthorizable; private String name; - private long version = 0L; + private AtomicLong version = new AtomicLong(0L); private final Map parameters = new LinkedHashMap<>(); private final List inheritedParameterContexts = new ArrayList<>(); private ParameterProvider parameterProvider; @@ -105,7 +106,7 @@ public class StandardParameterContext implements ParameterContext { public void setName(final String name) { writeLock.lock(); try { - this.version++; + this.version.incrementAndGet(); this.name = name; } finally { writeLock.unlock(); @@ -125,8 +126,9 @@ public class StandardParameterContext implements ParameterContext { @Override public void setParameters(final Map updatedParameters) { writeLock.lock(); + final Map parameterUpdates = new HashMap<>(); try { - this.version++; + this.version.incrementAndGet(); final Map currentEffectiveParameters = getEffectiveParameters(); final Map effectiveProposedParameters = getEffectiveParameters(getProposedParameters(updatedParameters)); @@ -139,12 +141,11 @@ public class StandardParameterContext implements ParameterContext { updateParameters(parameters, updatedParameters, true); // Get a list of all effective updates in order to alert referencing components - final Map parameterUpdates = new HashMap<>(updateParameters(currentEffectiveParameters, effectiveParameterUpdates, false)); - - alertReferencingComponents(parameterUpdates); + parameterUpdates.putAll(updateParameters(currentEffectiveParameters, effectiveParameterUpdates, false)); } finally { writeLock.unlock(); } + alertReferencingComponents(parameterUpdates); } private Map getProposedParameters(final Map proposedParameterUpdates) { @@ -270,12 +271,7 @@ public class StandardParameterContext implements ParameterContext { @Override public long getVersion() { - readLock.lock(); - try { - return version; - } finally { - readLock.unlock(); - } + return version.get(); } public Optional getParameter(final String parameterName) { @@ -597,7 +593,7 @@ public class StandardParameterContext implements ParameterContext { writeLock.lock(); try { - this.version++; + this.version.incrementAndGet(); final Map currentEffectiveParameters = getEffectiveParameters(); final Map effectiveProposedParameters = getEffectiveParameters(inheritedParameterContexts);