From 484687a67b12fb5fc13dabd7851f83a6e4a898be Mon Sep 17 00:00:00 2001 From: Aldrin Piri Date: Sun, 1 Mar 2015 14:16:22 -0500 Subject: [PATCH] Adjusting onRemoved methods for both JsonPath processors to clean up entries on exit. --- .../standard/AbstractJsonPathProcessor.java | 2 +- .../nifi/processors/standard/EvaluateJsonPath.java | 2 +- .../apache/nifi/processors/standard/SplitJson.java | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractJsonPathProcessor.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractJsonPathProcessor.java index baeef7b73b..febc3f8b66 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractJsonPathProcessor.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractJsonPathProcessor.java @@ -86,7 +86,7 @@ public abstract class AbstractJsonPathProcessor extends AbstractProcessor { return JSON_PROVIDER.toJson(jsonPathResult); } - protected abstract static class JsonPathValidator implements Validator { + abstract static class JsonPathValidator implements Validator { @Override public ValidationResult validate(final String subject, final String input, final ValidationContext context) { diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java index b40f6c6da5..81c9bbec27 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java @@ -182,7 +182,7 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { * isStale() */ @OnRemoved - public void onRemoved() { + public void onRemoved(ProcessContext processContext) { for (PropertyDescriptor propertyDescriptor : getPropertyDescriptors()) { if (propertyDescriptor.isDynamic()) { cachedJsonPathMap.remove(propertyDescriptor.getName()); diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitJson.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitJson.java index 59f4d71794..7bb8c4e12c 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitJson.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitJson.java @@ -26,6 +26,7 @@ import org.apache.nifi.annotation.behavior.SideEffectFree; import org.apache.nifi.annotation.behavior.SupportsBatching; import org.apache.nifi.annotation.documentation.CapabilityDescription; import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnRemoved; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.logging.ProcessorLog; @@ -111,6 +112,17 @@ public class SplitJson extends AbstractJsonPathProcessor { } } + /** + * Provides cleanup of the map for any JsonPath values that may have been created. This will remove common values + * shared between multiple instances, but will be regenerated when the next validation cycle occurs as a result of + * isStale() + */ + @OnRemoved + public void onRemoved(ProcessContext processContext) { + String jsonPathExpression = processContext.getProperty(ARRAY_JSON_PATH_EXPRESSION).getValue(); + JSON_PATH_MAP.remove(jsonPathExpression); + } + @Override public void onTrigger(final ProcessContext processContext, final ProcessSession processSession) { final FlowFile original = processSession.get();