mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
improve print agentId in welcome message. #1575
This commit is contained in:
@@ -301,7 +301,6 @@ public class ArthasBootstrap {
|
||||
System.getProperty(ArthasConstants.SPRING_APPLICATION_NAME, null)));
|
||||
}
|
||||
|
||||
String agentId = null;
|
||||
try {
|
||||
if (configure.getTunnelServer() != null) {
|
||||
tunnelClient = new TunnelClient();
|
||||
@@ -311,9 +310,6 @@ public class ArthasBootstrap {
|
||||
tunnelClient.setVersion(ArthasBanner.version());
|
||||
ChannelFuture channelFuture = tunnelClient.start();
|
||||
channelFuture.await(10, TimeUnit.SECONDS);
|
||||
if(channelFuture.isSuccess()) {
|
||||
agentId = tunnelClient.getId();
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
logger().error("start tunnel client error", t);
|
||||
@@ -322,17 +318,12 @@ public class ArthasBootstrap {
|
||||
try {
|
||||
ShellServerOptions options = new ShellServerOptions()
|
||||
.setInstrumentation(instrumentation)
|
||||
.setPid(PidUtils.currentLongPid());
|
||||
.setPid(PidUtils.currentLongPid())
|
||||
.setWelcomeMessage(ArthasBanner.welcome());
|
||||
if (configure.getSessionTimeout() != null) {
|
||||
options.setSessionTimeout(configure.getSessionTimeout() * 1000);
|
||||
}
|
||||
|
||||
if (agentId != null) {
|
||||
Map<String, String> welcomeInfos = new HashMap<String, String>();
|
||||
welcomeInfos.put("id", agentId);
|
||||
options.setWelcomeMessage(ArthasBanner.welcome(welcomeInfos));
|
||||
}
|
||||
|
||||
shellServer = new ShellServerImpl(options);
|
||||
BuiltinCommandPack builtinCommands = new BuiltinCommandPack();
|
||||
List<CommandResolver> resolvers = new ArrayList<CommandResolver>();
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.taobao.arthas.core.shell.impl;
|
||||
|
||||
import com.alibaba.arthas.deps.org.slf4j.Logger;
|
||||
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
|
||||
import com.alibaba.arthas.tunnel.client.TunnelClient;
|
||||
import com.taobao.arthas.core.server.ArthasBootstrap;
|
||||
import com.taobao.arthas.core.shell.Shell;
|
||||
import com.taobao.arthas.core.shell.ShellServer;
|
||||
@@ -19,10 +20,12 @@ import com.taobao.arthas.core.shell.system.impl.InternalCommandManager;
|
||||
import com.taobao.arthas.core.shell.system.impl.JobControllerImpl;
|
||||
import com.taobao.arthas.core.shell.term.Term;
|
||||
import com.taobao.arthas.core.shell.term.TermServer;
|
||||
import com.taobao.arthas.core.util.ArthasBanner;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -93,6 +96,7 @@ public class ShellServerImpl extends ShellServer {
|
||||
}
|
||||
|
||||
ShellImpl session = createShell(term);
|
||||
tryUpdateWelcomeMessage();
|
||||
session.setWelcome(welcomeMessage);
|
||||
session.closedFuture.setHandler(new SessionClosedHandler(this, session));
|
||||
session.init();
|
||||
@@ -100,6 +104,18 @@ public class ShellServerImpl extends ShellServer {
|
||||
session.readline(); // Now readline
|
||||
}
|
||||
|
||||
private void tryUpdateWelcomeMessage() {
|
||||
TunnelClient tunnelClient = ArthasBootstrap.getInstance().getTunnelClient();
|
||||
if (tunnelClient != null) {
|
||||
String id = tunnelClient.getId();
|
||||
if (id != null) {
|
||||
Map<String, String> welcomeInfos = new HashMap<String, String>();
|
||||
welcomeInfos.put("id", id);
|
||||
this.welcomeMessage = ArthasBanner.welcome(welcomeInfos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShellServer listen(final Handler<Future<Void>> listenHandler) {
|
||||
final List<TermServer> toStart;
|
||||
|
||||
Reference in New Issue
Block a user