Search in sources :

Example 1 with ShellMsg

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;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Result(com.hortonworks.streamline.streams.Result) ProcessorMsg(com.hortonworks.streamline.streams.common.utils.ProcessorMsg) ShellMsg(com.hortonworks.streamline.streams.common.utils.ShellMsg) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException)

Aggregations

Result (com.hortonworks.streamline.streams.Result)1 ProcessorMsg (com.hortonworks.streamline.streams.common.utils.ProcessorMsg)1 ShellMsg (com.hortonworks.streamline.streams.common.utils.ShellMsg)1 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1