mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-03 12:29:14 +08:00
commit
c780e3a9dd
@ -5,6 +5,7 @@ import cn.keepbx.jpom.system.ConfigBean;
|
||||
import cn.keepbx.jpom.util.JsonUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@ -35,8 +36,13 @@ public abstract class BaseDataService {
|
||||
protected void saveJson(String filename, JSONObject json) throws IOException {
|
||||
String key = json.getString("id");
|
||||
// 读取文件,如果存在记录,则抛出异常
|
||||
JSONObject allData = getJSONObject(filename);
|
||||
JSONObject data = allData.getJSONObject(key);
|
||||
JSONObject allData = new JSONObject();
|
||||
JSONObject data = null;
|
||||
try {
|
||||
allData = getJSONObject(filename);
|
||||
data = allData.getJSONObject(key);
|
||||
} catch (FileNotFoundException ignored) {
|
||||
}
|
||||
// 判断是否存在数据
|
||||
if (null != data && 0 < data.keySet().size()) {
|
||||
throw new RuntimeException("数据Id已经存在啦:" + filename + " :" + key);
|
||||
|
@ -8,6 +8,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.system.JavaRuntimeInfo;
|
||||
import cn.hutool.system.OsInfo;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
@ -15,9 +16,7 @@ import cn.keepbx.jpom.common.commander.impl.LinuxCommander;
|
||||
import cn.keepbx.jpom.common.commander.impl.WindowsCommander;
|
||||
import cn.keepbx.jpom.model.ProjectInfoModel;
|
||||
import cn.keepbx.jpom.service.manage.CommandService;
|
||||
import com.sun.tools.attach.AttachNotSupportedException;
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
import com.sun.tools.attach.VirtualMachineDescriptor;
|
||||
import com.sun.tools.attach.*;
|
||||
import sun.management.ConnectorAddressLink;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
@ -44,6 +43,7 @@ public abstract class AbstractCommander {
|
||||
private static AbstractCommander abstractCommander = null;
|
||||
protected Charset charset;
|
||||
public static final OsInfo OS_INFO = SystemUtil.getOsInfo();
|
||||
private static final JavaRuntimeInfo JAVA_RUNTIME_INFO = SystemUtil.getJavaRuntimeInfo();
|
||||
|
||||
protected AbstractCommander(Charset charset) {
|
||||
this.charset = charset;
|
||||
@ -205,7 +205,7 @@ public abstract class AbstractCommander {
|
||||
return null;
|
||||
}
|
||||
int pid = Convert.toInt(virtualMachine.id());
|
||||
JMXServiceURL jmxServiceURL = getLocalStubServiceURLFromPID(pid, virtualMachine);
|
||||
JMXServiceURL jmxServiceURL = getJMXServiceURL(pid, virtualMachine);
|
||||
if (jmxServiceURL == null) {
|
||||
return null;
|
||||
}
|
||||
@ -214,7 +214,7 @@ public abstract class AbstractCommander {
|
||||
return ManagementFactory.newPlatformMXBeanProxy(mBeanServerConnection, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
|
||||
}
|
||||
|
||||
private static JMXServiceURL getLocalStubServiceURLFromPID(int pid, VirtualMachine virtualMachine) throws IOException {
|
||||
private static JMXServiceURL getJMXServiceURL(int pid, VirtualMachine virtualMachine) throws IOException, AgentLoadException, AgentInitializationException {
|
||||
String address = virtualMachine.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress");
|
||||
if (address != null) {
|
||||
return new JMXServiceURL(address);
|
||||
@ -223,6 +223,12 @@ public abstract class AbstractCommander {
|
||||
if (address != null) {
|
||||
return new JMXServiceURL(address);
|
||||
}
|
||||
String agent = StrUtil.format("{}{}lib{}management-agent.jar", JAVA_RUNTIME_INFO.getHomeDir(), File.separator, File.separator);
|
||||
virtualMachine.loadAgent(agent);
|
||||
address = virtualMachine.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress");
|
||||
if (address != null) {
|
||||
return new JMXServiceURL(address);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -270,7 +276,7 @@ public abstract class AbstractCommander {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
} while (count++ < 10);
|
||||
} while (count++ < 20);
|
||||
}
|
||||
|
||||
public String execCommand(String command) throws Exception {
|
||||
@ -295,6 +301,14 @@ public abstract class AbstractCommander {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @param cmd 命令行
|
||||
* @return 结果
|
||||
* @throws IOException IO
|
||||
* @throws InterruptedException 等待超时
|
||||
*/
|
||||
private String exec(String[] cmd) throws IOException, InterruptedException {
|
||||
DefaultSystemLog.LOG().info(Arrays.toString(cmd));
|
||||
String result;
|
||||
|
@ -153,12 +153,12 @@
|
||||
});
|
||||
},
|
||||
success: function (data) {
|
||||
layer.msg(data.msg);
|
||||
if (200 == data.code) {
|
||||
autoClose();
|
||||
} else {
|
||||
layer.closeAll();
|
||||
}
|
||||
layer.msg(data.msg);
|
||||
},
|
||||
error: function (err) {
|
||||
layer.closeAll();
|
||||
|
23
src/test/java/TestJavaInfo.java
Normal file
23
src/test/java/TestJavaInfo.java
Normal file
@ -0,0 +1,23 @@
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import com.sun.tools.attach.AgentInitializationException;
|
||||
import com.sun.tools.attach.AgentLoadException;
|
||||
import com.sun.tools.attach.AttachNotSupportedException;
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
import sun.management.ConnectorAddressLink;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by jiangzeyin on 2019/3/20.
|
||||
*/
|
||||
public class TestJavaInfo {
|
||||
public static void main(String[] args) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException {
|
||||
System.out.println(SystemUtil.getJavaRuntimeInfo().getHomeDir());
|
||||
VirtualMachine virtualMachine = VirtualMachine.attach("16772");
|
||||
// String agent = StrUtil.format("{}{}lib{}management-agent.jar", SystemUtil.getJavaRuntimeInfo().getHomeDir(), File.separator, File.separator);
|
||||
// virtualMachine.loadAgent(agent);
|
||||
// virtualMachine.loadAgent(agent);
|
||||
ConnectorAddressLink.export(String.valueOf(12044));
|
||||
System.out.println(ConnectorAddressLink.importFrom(12044));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user