Browse Source

Merge remote-tracking branch 'origin/release/10.0' into release/10.0

alex.sung 5 years ago
parent
commit
59389a0d85
  1. 65
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java
  2. 92
      designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartupMessageCollector.java
  3. 11
      designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

65
designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

@ -1,9 +1,7 @@
/**
*
*/
package com.fr.design.mainframe;
import com.fr.base.FRContext;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.config.MarketConfig;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.errorinfo.ErrorInfoUploader;
@ -30,6 +28,7 @@ import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLWriter;
import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException;
import com.sun.management.OperatingSystemMXBean;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
@ -43,6 +42,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.lang.management.ManagementFactory;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
@ -53,15 +54,19 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @author neil
* 设计器信息收集
*
* @author neil
* @date: 2015-4-8-下午5:11:46
*/
public class InformationCollector implements XMLReadable, XMLWriter {
// 24小时上传一次
/**
* 24小时上传一次
*/
private static final long DELTA = 24 * 3600 * 1000L;
private static final long SEND_DELAY = 300 * 1000L;
private static final int BYTE_TO_MB = 1024 * 1024;
private static final String FILE_NAME = "fr.info";
private static final String XML_START_STOP_LIST = "StartStopList";
private static final String XML_START_STOP = "StartStop";
@ -74,12 +79,19 @@ public class InformationCollector implements XMLReadable, XMLWriter {
private static final String XML_UUID = "UUID";
private static final String XML_KEY = "ActiveKey";
private static final String XML_OS = "OS";
private static final String XML_ARCH = "arch";
private static final String XML_AVAILABLE_PROCESSORS = "cpu";
private static final String XML_PHYSICAL_MEMORY = "systemMemory";
private static InformationCollector collector;
//启动时间与关闭时间列表
private List<StartStopTime> startStop = new ArrayList<StartStopTime>();
//上一次的发送时间
/**
* 启动时间与关闭时间列表
*/
private List<StartStopTime> startStop = new ArrayList<>();
/**
* 上一次的发送时间
*/
private String lastTime;
private StartStopTime current = new StartStopTime();
@ -142,11 +154,12 @@ public class InformationCollector implements XMLReadable, XMLWriter {
JSONObject content = new JSONObject();
JSONArray startStopArray = new JSONArray();
for (int i = 0; i < startStop.size(); i++) {
for (StartStopTime startStopTime : startStop) {
JSONObject jo = new JSONObject();
jo.put(ATTR_START, startStop.get(i).getStartDate());
jo.put(ATTR_STOP, startStop.get(i).getStopDate());
jo.put(ATTR_START, startStopTime.getStartDate());
jo.put(ATTR_STOP, startStopTime.getStopDate());
startStopArray.put(jo);
}
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
content.put(XML_START_STOP, startStopArray);
content.put(XML_UUID, envManager.getUUID());
@ -155,10 +168,22 @@ public class InformationCollector implements XMLReadable, XMLWriter {
content.put(XML_USERNAME, MarketConfig.getInstance().getBbsUsername());
content.put(XML_KEY, envManager.getActivationKey());
content.put(XML_OS, System.getProperty("os.name"));
}
content.put(XML_ARCH, System.getProperty("os.arch"));
content.put(XML_AVAILABLE_PROCESSORS, Runtime.getRuntime().availableProcessors());
content.put(XML_PHYSICAL_MEMORY, getTotalPhysicalMemorySize());
return content;
}
/**
* 获取物理内存单位GB
*
* @return 物理内存
*/
private static long getTotalPhysicalMemorySize() {
OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
return bean.getTotalPhysicalMemorySize() / BYTE_TO_MB;
}
private void sendUserInfo(){
long currentTime = new Date().getTime();
long lastTime = getLastTimeMillis();
@ -197,7 +222,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
return;
}
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("InformationCollector"));
service.schedule(new Runnable() {
@Override
public void run() {
@ -241,7 +266,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
XMLTools.writeOutputStreamXML(this, out);
out.flush();
out.close();
String fileContent = new String(out.toByteArray(), EncodeConstants.ENCODING_UTF_8);
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
String encodeCotent = DesUtils.getEncString(fileContent);
writeEncodeContentToFile(encodeCotent, xmlFile);
} catch (Exception e) {
@ -257,7 +282,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
BufferedWriter bw = null;
try {
FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8);
OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
bw = new BufferedWriter(osw);
bw.write(fileContent);
} catch (Exception e) {
@ -266,11 +291,10 @@ public class InformationCollector implements XMLReadable, XMLWriter {
if (bw != null) {
try {
bw.close();
} catch (IOException e) {
} catch (IOException ignore) {
}
}
}
}
@Override
@ -288,8 +312,8 @@ public class InformationCollector implements XMLReadable, XMLWriter {
private void writeStartStopList(XMLPrintWriter writer) {
//启停
writer.startTAG(XML_START_STOP_LIST);
for (int i = 0; i < startStop.size(); i++) {
startStop.get(i).writeXML(writer);
for (StartStopTime startStopTime : startStop) {
startStopTime.writeXML(writer);
}
writer.end();
}
@ -327,6 +351,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
startStop.clear();
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) {
if (XML_START_STOP.equals(reader.getTagName())) {
StartStopTime startStopTime = new StartStopTime();
@ -358,6 +383,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
this.stopDate = endDate;
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_START_STOP);
if (StringUtils.isNotEmpty(startDate)) {
@ -369,6 +395,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
writer.end();
}
@Override
public void readXML(XMLableReader reader) {
this.startDate = reader.getAttrAsString(ATTR_START, StringUtils.EMPTY);
this.stopDate = reader.getAttrAsString(ATTR_STOP, StringUtils.EMPTY);

92
designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartupMessageCollector.java

@ -0,0 +1,92 @@
package com.fr.design.mainframe.messagecollect;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.SiteCenterToken;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.module.ModuleContext;
import com.fr.module.engine.FineModule;
import com.fr.runtime.FineRuntime;
import com.fr.stable.StringUtils;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 启动信息收集
*
* @author vito
* @version 10.0
* Created by vito on 2019/9/4
*/
public class StartupMessageCollector {
private static final String XML_STARTUP_TIME = "t";
private static final String XML_STARTUP_LOG = "startupLog";
private static final String XML_STARTUP_Memory = "designerMemory";
private static final String XML_STARTUP_COST = "cost";
private static final String XML_UUID = "UUID";
private static final String STARTUP_URL_KEY = "user.info.v10.startup";
private static final String LOG_TYPE = "single";
private static final int BYTE_TO_MB = 1024 * 1024;
public static final StartupMessageCollector INSTANCE = new StartupMessageCollector();
private StartupMessageCollector() {
}
public static StartupMessageCollector getInstance() {
return INSTANCE;
}
public void recordStartupLog() {
EventDispatcher.listen(FineRuntime.ApplicationEvent.AFTER_START, new Listener<Long>() {
@Override
public void on(Event event, Long param) {
final String url = CloudCenter.getInstance().acquireUrlByKind(STARTUP_URL_KEY);
if (StringUtils.isEmpty(url)) {
return;
}
ExecutorService es = Executors.newSingleThreadExecutor(new NamedThreadFactory("StartupMessageCollector"));
es.submit(new Runnable() {
@Override
public void run() {
FineModule root = (FineModule) ModuleContext.getRoot().getRoot();
JSONObject profile = root.profile();
JSONObject json = JSONObject.create()
.put(XML_UUID, DesignerEnvManager.getEnvManager().getUUID())
.put(XML_STARTUP_TIME, FineRuntime.getAppStartTime() + FineRuntime.getStartingTime())
.put(XML_STARTUP_COST, FineRuntime.getStartingTime())
.put(XML_STARTUP_LOG, profile)
.put(XML_STARTUP_Memory, Runtime.getRuntime().totalMemory() / BYTE_TO_MB);
sendInfo(json, url + LOG_TYPE);
}
});
es.shutdown();
}
});
}
private boolean sendInfo(JSONObject content, String url) {
boolean success = false;
try {
HashMap<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
para.put("content", content);
String res = HttpToolbox.post(url, para);
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return success;
}
}

11
designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

@ -1,14 +1,15 @@
package com.fr.start.module;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.messagecollect.StartupMessageCollector;
import com.fr.event.Event;
import com.fr.event.Listener;
import com.fr.module.Activator;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.record.analyzer.Metrics;
import com.fr.runtime.FineRuntime;
import com.fr.start.Designer;
import com.fr.start.ServerStarter;
import com.fr.start.SplashContext;
@ -42,7 +43,7 @@ public class DesignerStartup extends Activator {
startSub(EnvBasedModule.class);
//designer模块启动好后,查看demo
browserDemo();
ExecutorService service = Executors.newFixedThreadPool(2);
ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("FineEmbedServerStart"));
service.submit(new Runnable() {
@Override
public void run() {
@ -67,7 +68,7 @@ public class DesignerStartup extends Activator {
DesignerContext.getDesignerFrame().getProgressDialog().setVisible(true);
startSub(StartFinishActivator.class);
FineRuntime.startFinish();
StartupMessageCollector.getInstance().recordStartupLog();
}
private void browserDemo() {
@ -87,7 +88,7 @@ public class DesignerStartup extends Activator {
@Override
public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).stop();
stopSub(EnvBasedModule.class);
}
});
/*切换环境后,重新启动所有相关模块,最先执行*/
@ -95,7 +96,7 @@ public class DesignerStartup extends Activator {
@Override
public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).start();
startSub(EnvBasedModule.class);
// 切换后的环境是本地环境才启动内置服务器
if (current.isLocal()) {
ExecutorService service = Executors.newSingleThreadExecutor();

Loading…
Cancel
Save