processIn.writeBytes("\nend\n");
processIn.flush();
}
public ShellMsg readShellMsg() throws IOException, NoOutputException {
JSONObject msg = (JSONObject) readMessage();
ShellMsg shellMsg = new ShellMsg();
String command = (String) msg.get("command");
shellMsg.setCommand(command);
Object id = msg.get("id");
shellMsg.setId(id);
String log = (String) msg.get("msg");
shellMsg.setMsg(log);
String stream = (String) msg.get("stream");
if (stream == null)
stream = Utils.DEFAULT_STREAM_ID;
shellMsg.setStream(stream);
Object taskObj = msg.get("task");
if (taskObj != null) {
shellMsg.setTask((Long) taskObj);
} else {
shellMsg.setTask(0);
}
Object need_task_ids = msg.get("need_task_ids");
if (need_task_ids == null || ((Boolean) need_task_ids).booleanValue()) {
shellMsg.setNeedTaskIds(true);
} else {
shellMsg.setNeedTaskIds(false);
}
shellMsg.setTuple((List) msg.get("tuple"));
List<Tuple> anchors = new ArrayList<Tuple>();
Object anchorObj = msg.get("anchors");
if (anchorObj != null) {
if (anchorObj instanceof String) {
anchorObj = Arrays.asList(anchorObj);
}
for (Object o : (List) anchorObj) {
shellMsg.addAnchor((String) o);
}
}
Object nameObj = msg.get("name");
String metricName = null;
if (nameObj != null && nameObj instanceof String) {
metricName = (String) nameObj;
}
shellMsg.setMetricName(metricName);
Object paramsObj = msg.get("params");
shellMsg.setMetricParams(paramsObj);
if (command.equals("log")) {
Object logLevelObj = msg.get("level");
if (logLevelObj != null && logLevelObj instanceof Long) {
long logLevel = (Long)logLevelObj;
shellMsg.setLogLevel((int)logLevel);
}
}