Removing the batched get of flowfiles to utilize the framework provided batching support

This commit is contained in:
Aldrin Piri 2015-02-20 16:05:16 -05:00
parent 2862771235
commit 81234f3a6d
1 changed files with 55 additions and 60 deletions

View File

@ -151,8 +151,8 @@ public class EvaluateJsonPath extends AbstractProcessor {
@Override
public void onTrigger(ProcessContext processContext, final ProcessSession processSession) throws ProcessException {
List<FlowFile> flowFiles = processSession.get(50);
if (flowFiles.isEmpty()) {
FlowFile flowFile = processSession.get();
if (flowFile == null) {
return;
}
@ -175,15 +175,12 @@ public class EvaluateJsonPath extends AbstractProcessor {
returnType = destination.equals(DESTINATION_CONTENT) ? RETURN_TYPE_JSON : RETURN_TYPE_SCALAR;
}
flowFileLoop:
for (FlowFile flowFile : flowFiles) {
final DocumentContext documentContext = JsonUtils.validateAndEstablishJsonContext(processSession, flowFile);
if (documentContext == null) {
logger.error("FlowFile {} did not have valid JSON content.", new Object[]{flowFile});
processSession.transfer(flowFile, REL_FAILURE);
continue flowFileLoop;
return;
}
final Map<String, String> jsonPathResults = new HashMap<>();
@ -201,7 +198,7 @@ public class EvaluateJsonPath extends AbstractProcessor {
logger.error("Unable to return a scalar value for the expression {} for FlowFile {}. Evaluated value was {}. Transferring to {}.",
new Object[]{jsonPathExp.getPath(), flowFile.getId(), result.toString(), REL_FAILURE.getName()});
processSession.transfer(flowFile, REL_FAILURE);
continue flowFileLoop;
return;
}
resultHolder.set(result);
} catch (PathNotFoundException e) {
@ -211,7 +208,7 @@ public class EvaluateJsonPath extends AbstractProcessor {
continue jsonPathEvalLoop;
} else {
processSession.transfer(flowFile, REL_NO_MATCH);
continue flowFileLoop;
return;
}
}
@ -219,7 +216,6 @@ public class EvaluateJsonPath extends AbstractProcessor {
switch (destination) {
case DESTINATION_ATTRIBUTE:
jsonPathResults.put(jsonPathAttrKey, resultRepresentation);
break;
case DESTINATION_CONTENT:
flowFile = processSession.write(flowFile, new OutputStreamCallback() {
@Override
@ -235,6 +231,5 @@ public class EvaluateJsonPath extends AbstractProcessor {
flowFile = processSession.putAllAttributes(flowFile, jsonPathResults);
processSession.transfer(flowFile, REL_MATCH);
}
}
}