Skip to content

Commit

Permalink
vjtop 更好的失败原因输出 #78
Browse files Browse the repository at this point in the history
顺便包含quit时更好的输出
  • Loading branch information
calvin1978 committed Aug 13, 2018
1 parent 6de7b3b commit 254440f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private boolean checkState() {
return false;
}

if (vmInfo.state != VMInfoState.ATTACHED) {
if (vmInfo.state != VMInfo.VMInfoState.ATTACHED) {
System.out.println("ERROR: Could not attach to process. ");
exit();
return false;
Expand Down
27 changes: 4 additions & 23 deletions vjtop/src/main/java/com/vip/vjtools/vjtop/data/jmx/JmxClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
import com.sun.management.GarbageCollectorMXBean;
import com.sun.management.OperatingSystemMXBean;
import com.sun.management.ThreadMXBean;
import com.sun.tools.attach.AgentInitializationException;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;

@SuppressWarnings("restriction")
Expand Down Expand Up @@ -92,7 +89,7 @@ public void flush() {
}
}

public void connect() throws IOException {
public void connect() throws Exception {

// 如果jmx agent未启动,主动attach进JVM后加载
String address = attachToGetConnectorAddress();
Expand Down Expand Up @@ -231,17 +228,11 @@ public String toString() {
* 并向JMXClient提供连接地址地址样例:service:jmx:rmi://127.0
* .0.1/stub/rO0ABXN9AAAAAQAl...
*/
public String attachToGetConnectorAddress() throws IOException {
public String attachToGetConnectorAddress() throws Exception {
VirtualMachine vm = null;

// 1. attach vm
try {
vm = VirtualMachine.attach(pid);
} catch (AttachNotSupportedException x) {
IOException ioe = new IOException(x.getMessage());
ioe.initCause(x);
throw ioe;
}
vm = VirtualMachine.attach(pid);

try {
// 2. 检查smartAgent是否已启动
Expand Down Expand Up @@ -270,17 +261,7 @@ public String attachToGetConnectorAddress() throws IOException {
}

agentPath = f.getCanonicalPath();
try {
vm.loadAgent(agentPath, "com.sun.management.jmxremote");
} catch (AgentLoadException x) {
IOException ioe = new IOException(x.getMessage());
ioe.initCause(x);
throw ioe;
} catch (AgentInitializationException x) {
IOException ioe = new IOException(x.getMessage());
ioe.initCause(x);
throw ioe;
}
vm.loadAgent(agentPath, "com.sun.management.jmxremote");

// 4. 再次获取connector address
agentProps = vm.getAgentProperties();
Expand Down

0 comments on commit 254440f

Please sign in to comment.