mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
dashboard/watch/monitor/tt/stack/trace support press Q to exit. close #410
This commit is contained in:
@@ -6,6 +6,7 @@ import com.taobao.arthas.core.command.Constants;
|
||||
import com.taobao.arthas.core.shell.command.AnnotatedCommand;
|
||||
import com.taobao.arthas.core.shell.command.CommandProcess;
|
||||
import com.taobao.arthas.core.shell.handlers.Handler;
|
||||
import com.taobao.arthas.core.shell.handlers.shell.QExitHandler;
|
||||
import com.taobao.arthas.core.shell.session.Session;
|
||||
import com.taobao.arthas.core.util.LogUtil;
|
||||
import com.taobao.arthas.core.util.NetUtils;
|
||||
@@ -63,7 +64,6 @@ public class DashboardCommand extends AnnotatedCommand {
|
||||
|
||||
private volatile long count = 0;
|
||||
private volatile Timer timer;
|
||||
private Boolean running = false;
|
||||
|
||||
@Option(shortName = "n", longName = "number-of-execution")
|
||||
@Description("The number of times this command will be executed.")
|
||||
@@ -113,9 +113,11 @@ public class DashboardCommand extends AnnotatedCommand {
|
||||
process.resumeHandler(restartHandler);
|
||||
process.endHandler(stopHandler);
|
||||
|
||||
// q exit support
|
||||
process.stdinHandler(new QExitHandler(process));
|
||||
|
||||
// start the timer
|
||||
timer.scheduleAtFixedRate(new DashboardTimerTask(process), 0, getInterval());
|
||||
running = true;
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.taobao.arthas.core.shell.cli.CompletionUtils;
|
||||
import com.taobao.arthas.core.shell.command.AnnotatedCommand;
|
||||
import com.taobao.arthas.core.shell.command.CommandProcess;
|
||||
import com.taobao.arthas.core.shell.handlers.command.CommandInterruptHandler;
|
||||
import com.taobao.arthas.core.shell.handlers.shell.QExitHandler;
|
||||
import com.taobao.arthas.core.shell.session.Session;
|
||||
import com.taobao.arthas.core.util.Constants;
|
||||
import com.taobao.arthas.core.util.LogUtil;
|
||||
@@ -58,6 +59,8 @@ public abstract class EnhancerCommand extends AnnotatedCommand {
|
||||
public void process(final CommandProcess process) {
|
||||
// ctrl-C support
|
||||
process.interruptHandler(new CommandInterruptHandler(process));
|
||||
// q exit support
|
||||
process.stdinHandler(new QExitHandler(process));
|
||||
|
||||
// start to enhance
|
||||
enhance(process);
|
||||
@@ -125,7 +128,7 @@ public abstract class EnhancerCommand extends AnnotatedCommand {
|
||||
// 注册通知监听器
|
||||
process.register(lock, listener);
|
||||
if (process.isForeground()) {
|
||||
process.echoTips(Constants.ABORT_MSG + "\n");
|
||||
process.echoTips(Constants.Q_OR_CTRL_C_ABORT_MSG + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +151,7 @@ public abstract class EnhancerCommand extends AnnotatedCommand {
|
||||
logger.error(null, message);
|
||||
process.write("cannot operate the current command, pls. check arthas.log\n");
|
||||
if (process.isForeground()) {
|
||||
process.echoTips(Constants.ABORT_MSG + "\n");
|
||||
process.echoTips(Constants.Q_OR_CTRL_C_ABORT_MSG + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.taobao.arthas.core.shell.command.CommandProcess;
|
||||
import com.taobao.arthas.core.advisor.Advice;
|
||||
import com.taobao.arthas.core.advisor.ArthasMethod;
|
||||
import com.taobao.arthas.core.shell.handlers.command.CommandInterruptHandler;
|
||||
import com.taobao.arthas.core.shell.handlers.shell.QExitHandler;
|
||||
import com.taobao.arthas.core.util.LogUtil;
|
||||
import com.taobao.arthas.core.util.SearchUtils;
|
||||
import com.taobao.arthas.core.util.StringUtils;
|
||||
@@ -241,6 +242,8 @@ public class TimeTunnelCommand extends EnhancerCommand {
|
||||
|
||||
// ctrl-C support
|
||||
process.interruptHandler(new CommandInterruptHandler(process));
|
||||
// q exit support
|
||||
process.stdinHandler(new QExitHandler(process));
|
||||
|
||||
if (isTimeTunnel) {
|
||||
enhance(process);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.taobao.arthas.core.shell.handlers.shell;
|
||||
|
||||
import com.taobao.arthas.core.shell.command.CommandProcess;
|
||||
import com.taobao.arthas.core.shell.handlers.Handler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hengyunabc 2019-02-09
|
||||
*
|
||||
*/
|
||||
public class QExitHandler implements Handler<String> {
|
||||
private CommandProcess process;
|
||||
|
||||
public QExitHandler(CommandProcess process) {
|
||||
this.process = process;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(String event) {
|
||||
if ("q".equalsIgnoreCase(event)) {
|
||||
process.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public interface Constants {
|
||||
/**
|
||||
* 中断提示
|
||||
*/
|
||||
String ABORT_MSG = "Press Ctrl+C to abort.";
|
||||
String Q_OR_CTRL_C_ABORT_MSG = "Press Q or Ctrl+C to abort.";
|
||||
|
||||
/**
|
||||
* 空字符串
|
||||
|
||||
Reference in New Issue
Block a user