Adjusting onRemoved methods for both JsonPath processors to clean up entries on exit.

This commit is contained in:
Aldrin Piri 2015-03-01 14:16:22 -05:00
parent 5a2a8fc6be
commit 484687a67b
3 changed files with 14 additions and 2 deletions

View File

@ -86,7 +86,7 @@ public abstract class AbstractJsonPathProcessor extends AbstractProcessor {
return JSON_PROVIDER.toJson(jsonPathResult); return JSON_PROVIDER.toJson(jsonPathResult);
} }
protected abstract static class JsonPathValidator implements Validator { abstract static class JsonPathValidator implements Validator {
@Override @Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) { public ValidationResult validate(final String subject, final String input, final ValidationContext context) {

View File

@ -182,7 +182,7 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor {
* isStale() * isStale()
*/ */
@OnRemoved @OnRemoved
public void onRemoved() { public void onRemoved(ProcessContext processContext) {
for (PropertyDescriptor propertyDescriptor : getPropertyDescriptors()) { for (PropertyDescriptor propertyDescriptor : getPropertyDescriptors()) {
if (propertyDescriptor.isDynamic()) { if (propertyDescriptor.isDynamic()) {
cachedJsonPathMap.remove(propertyDescriptor.getName()); cachedJsonPathMap.remove(propertyDescriptor.getName());

View File

@ -26,6 +26,7 @@ import org.apache.nifi.annotation.behavior.SideEffectFree;
import org.apache.nifi.annotation.behavior.SupportsBatching; import org.apache.nifi.annotation.behavior.SupportsBatching;
import org.apache.nifi.annotation.documentation.CapabilityDescription; import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags; import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.annotation.lifecycle.OnRemoved;
import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.logging.ProcessorLog; 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 @Override
public void onTrigger(final ProcessContext processContext, final ProcessSession processSession) { public void onTrigger(final ProcessContext processContext, final ProcessSession processSession) {
final FlowFile original = processSession.get(); final FlowFile original = processSession.get();