本文整理汇总了Java中org.springframework.shell.core.JLineShell.executeCommand方法的典型用法代码示例。如果您正苦于以下问题:Java JLineShell.executeCommand方法的具体用法?Java JLineShell.executeCommand怎么用?Java JLineShell.executeCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.shell.core.JLineShell
的用法示例。
在下文中一共展示了JLineShell.executeCommand方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HandleHelp
import org.springframework.shell.core.JLineShell; //导入方法依赖的package包/类
private InterpreterResult HandleHelp(JLineShell shell, String st) {
java.util.logging.StreamHandler sh = null;
java.util.logging.Logger springLogger = null;
java.util.logging.Formatter formatter = new java.util.logging.Formatter() {
public String format(java.util.logging.LogRecord record) {
return record.getMessage();
}
};
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
sh = new java.util.logging.StreamHandler(baos, formatter);
springLogger = HandlerUtils.getLogger(org.springframework.shell.core.SimpleParser.class);
springLogger.addHandler(sh);
shell.executeCommand(st);
} catch (Exception e) {
s_logger.error(e.getMessage(), e);
return new InterpreterResult(Code.ERROR, e.getMessage());
}
finally {
sh.flush();
springLogger.removeHandler(sh);
sh.close();
}
return new InterpreterResult(Code.SUCCESS, baos.toString());
}
示例2: interpret
import org.springframework.shell.core.JLineShell; //导入方法依赖的package包/类
@Override
public InterpreterResult interpret(String input, InterpreterContext context) {
if (input == null || input.length() == 0) {
return new InterpreterResult(Code.ERROR, "no command submitted");
}
String st = input.replaceAll("\\n", " ");
s_logger.info("LensInterpreter command: " + st);
Bootstrap bs = createBootstrap();
JLineShell shell = getJLineShell(bs);
CommandResult res = null;
LensClient lensClient = null;
String qh = null;
if (st.trim().startsWith("help")) {
return HandleHelp(shell, st);
}
try {
lensClient = createAndSetLensClient(bs);
s_clientMap.put(lensClient, true);
String lensCommand = modifyQueryStatement(st);
s_logger.info("executing command : " + lensCommand);
res = shell.executeCommand(lensCommand);
if (!lensCommand.equals(st) && res != null
&& res.getResult() != null
&& res.getResult().toString().trim().matches("[a-z0-9-]+")) {
// setup query progress tracking
qh = res.getResult().toString();
s_paraToQH.put(context.getParagraphId(),
new ExecutionDetail(qh, lensClient, shell));
String getResultsCmd = "query results --async false " + qh;
s_logger.info("executing query results command : " + context.getParagraphId()
+ " : " + getResultsCmd);
res = shell.executeCommand(getResultsCmd);
s_paraToQH.remove(context.getParagraphId());
}
} catch (Exception ex) {
s_logger.error("error in interpret", ex);
return new InterpreterResult(Code.ERROR, ex.getMessage());
}
finally {
if (shell != null) {
closeShell(shell);
}
if (lensClient != null) {
closeLensClient(lensClient);
s_clientMap.remove(lensClient);
}
if (qh != null) {
s_paraToQH.remove(context.getParagraphId());
}
}
return new InterpreterResult(Code.SUCCESS, formatResult(st, res));
}
示例3: getProgress
import org.springframework.shell.core.JLineShell; //导入方法依赖的package包/类
@Override
public int getProgress(InterpreterContext context) {
if (s_paraToQH.containsKey(context.getParagraphId())) {
s_logger.info("number of items for which progress can be reported :" + s_paraToQH.size());
s_logger.info("number of open lensclient :" + s_clientMap.size());
Bootstrap bs = createBootstrap();
JLineShell shell = getJLineShell(bs);
LensClient lensClient = null;
String qh = s_paraToQH.get(context.getParagraphId()).getQueryHandle();
try {
s_logger.info("fetch query status for : (" + context.getParagraphId() + ") :" + qh);
lensClient = createAndSetLensClient(bs);
s_clientMap.put(lensClient, true);
CommandResult res = shell.executeCommand("query status " + qh);
s_logger.info(context.getParagraphId() + " --> " + res.getResult().toString());
//change to debug
Pattern pattern = Pattern.compile(".*(Progress : (\\d\\.\\d)).*");
Matcher matcher = pattern.matcher(res.getResult().toString().replaceAll("\\n", " "));
if (matcher.find(2)) {
Double d = Double.parseDouble(matcher.group(2)) * 100;
if (d.intValue() == 100) {
s_paraToQH.remove(context.getParagraphId());
}
return d.intValue();
} else {
return 1;
}
}
catch (Exception e) {
s_logger.error("unable to get progress for (" + context.getParagraphId() + ") :" + qh, e);
s_paraToQH.remove(context.getParagraphId());
return 0;
} finally {
if (lensClient != null) {
closeLensClient(lensClient);
s_clientMap.remove(lensClient);
}
if (shell != null) {
closeShell(shell);
}
}
}
return 0;
}