Search in sources :

Example 1 with ShellMsg

use of backtype.storm.multilang.ShellMsg in project jstorm by alibaba.

the class ShellSpout method querySubprocess.

private void querySubprocess() {
    try {
        _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) {
                    _collector.emit(stream, tuple, messageId, new ShellEmitCb(shellMsg));
                } 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);
    }
}
Also used : ShellMsg(backtype.storm.multilang.ShellMsg) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) IOException(java.io.IOException)

Example 2 with ShellMsg

use of backtype.storm.multilang.ShellMsg in project jstorm by alibaba.

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(backtype.storm.topology.ReportedFailedException) ShellMsg(backtype.storm.multilang.ShellMsg)

Aggregations

ShellMsg (backtype.storm.multilang.ShellMsg)2 ReportedFailedException (backtype.storm.topology.ReportedFailedException)1 IOException (java.io.IOException)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1