use of com.hortonworks.streamline.streams.common.utils.ProcessorMsg in project streamline by hortonworks.
the class MultiLangProcessorRuntime method createProcessorMessage.
private ProcessorMsg createProcessorMessage(StreamlineEvent event) {
ProcessorMsg processorMsg = new ProcessorMsg();
processorMsg.setId(event.getId());
processorMsg.setSourceId(event.getDataSourceId());
processorMsg.setSourceStream(event.getSourceStream());
processorMsg.setFieldsAndValues(event);
return processorMsg;
}
use of com.hortonworks.streamline.streams.common.utils.ProcessorMsg 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