use of com.hortonworks.streamline.streams.common.utils.ShellMsg in project streamline by hortonworks.
the class MultiLangProcessorRuntime method processEvent.
private List<Result> processEvent(StreamlineEvent inputEvent) {
List<Result> results = new LinkedList<>();
try {
markWaitingSubprocess();
ProcessorMsg processorMsg = createProcessorMessage(inputEvent);
shellProcess.writeProcessorMsg(processorMsg);
ShellMsg errorMsg = null;
Map<String, List<ShellMsg>> emitMsgMap = new HashMap<>();
while (true) {
ShellMsg shellMsg = shellProcess.readShellMsg();
String command = shellMsg.getCommand();
if (command == null) {
throw new IllegalArgumentException("Command not found in shell message: " + shellMsg);
}
setHeartbeat();
if (command.equals("sync")) {
break;
} else if (command.equals("error")) {
errorMsg = shellMsg;
} else if (command.equals("emit")) {
String stream = shellMsg.getOutputStream();
List<ShellMsg> eventList = emitMsgMap.get(stream);
if (eventList == null) {
eventList = new LinkedList<>();
emitMsgMap.put(stream, eventList);
}
eventList.add(shellMsg);
} else {
throw new RuntimeException("Unknown command received: " + command);
}
}
if (errorMsg != null) {
LOG.error(errorMsg.getMsg());
throw new ProcessingException(errorMsg.getMsg());
}
for (Map.Entry<String, List<ShellMsg>> entry : emitMsgMap.entrySet()) {
results.add(convertShellMsg(entry.getKey(), entry.getValue(), inputEvent));
}
} catch (IOException | ProcessingException e) {
String processInfo = shellProcess.getProcessInfoString() + shellProcess.getProcessTerminationInfoString();
throw new RuntimeException(processInfo, e);
} finally {
completedWaitingSubprocess();
}
return results;
}
Aggregations