Search in sources :

Example 1 with ShellMsg

use of org.apache.storm.multilang.ShellMsg in project storm by apache.

the class ShellSpout method querySubprocess.

private void querySubprocess() {
    try {
        markWaitingSubprocess();
        _process.writeSpoutMsg(_spoutMsg);
        while (true) {
            ShellMsg shellMsg = _process.readShellMsg();
            String command = shellMsg.getCommand();
            if (command == null) {
                throw new IllegalArgumentException("Command not found in spout message: " + shellMsg);
            }
            setHeartbeat();
            if (command.equals("sync")) {
                return;
            } else if (command.equals("log")) {
                handleLog(shellMsg);
            } else if (command.equals("error")) {
                handleError(shellMsg.getMsg());
            } else if (command.equals("emit")) {
                String stream = shellMsg.getStream();
                Long task = shellMsg.getTask();
                List<Object> tuple = shellMsg.getTuple();
                Object messageId = shellMsg.getId();
                if (task == 0) {
                    List<Integer> outtasks = _collector.emit(stream, tuple, messageId);
                    if (shellMsg.areTaskIdsNeeded()) {
                        _process.writeTaskIds(outtasks);
                    }
                } else {
                    _collector.emitDirect((int) task.longValue(), stream, tuple, messageId);
                }
            } else if (command.equals("metrics")) {
                handleMetrics(shellMsg);
            } else {
                throw new RuntimeException("Unknown command received: " + command);
            }
        }
    } catch (Exception e) {
        String processInfo = _process.getProcessInfoString() + _process.getProcessTerminationInfoString();
        throw new RuntimeException(processInfo, e);
    } finally {
        completedWaitingSubprocess();
    }
}
Also used : ShellMsg(org.apache.storm.multilang.ShellMsg) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List)

Example 2 with ShellMsg

use of org.apache.storm.multilang.ShellMsg in project storm by apache.

the class ShellBolt method handleLog.

private void handleLog(ShellMsg shellMsg) {
    String msg = shellMsg.getMsg();
    msg = "ShellLog " + _process.getProcessInfoString() + " " + msg;
    ShellMsg.ShellLogLevel logLevel = shellMsg.getLogLevel();
    switch(logLevel) {
        case TRACE:
            LOG.trace(msg);
            break;
        case DEBUG:
            LOG.debug(msg);
            break;
        case INFO:
            LOG.info(msg);
            break;
        case WARN:
            LOG.warn(msg);
            break;
        case ERROR:
            LOG.error(msg);
            _collector.reportError(new ReportedFailedException(msg));
            break;
        default:
            LOG.info(msg);
            break;
    }
}
Also used : ReportedFailedException(org.apache.storm.topology.ReportedFailedException) ShellMsg(org.apache.storm.multilang.ShellMsg)

Aggregations

ShellMsg (org.apache.storm.multilang.ShellMsg)2 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ReportedFailedException (org.apache.storm.topology.ReportedFailedException)1