Browse Source

Merge pull request #1162 in DESIGN/design from ~VITO/c-design:feature/10.0 to feature/10.0

* commit '11efe5ba934c8a6d5b357abe52a04d5438202b4e':
  REPORT-22377 收集jar版本信息&release部分代码传feature
research/11.0
vito 5 years ago
parent
commit
403bfdd3a9
  1. 62
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java
  2. 9
      designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartupMessageCollector.java

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

@ -30,6 +30,7 @@ import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLWriter; import com.fr.stable.xml.XMLWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException; import com.fr.third.javax.xml.stream.XMLStreamException;
import com.sun.management.OperatingSystemMXBean;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -43,11 +44,14 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.management.ManagementFactory;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -58,9 +62,12 @@ import java.util.concurrent.TimeUnit;
*/ */
public class InformationCollector implements XMLReadable, XMLWriter { public class InformationCollector implements XMLReadable, XMLWriter {
// 24小时上传一次 /**
* 24小时上传一次
*/
private static final long DELTA = 24 * 3600 * 1000L; private static final long DELTA = 24 * 3600 * 1000L;
private static final long SEND_DELAY = 300 * 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 FILE_NAME = "fr.info";
private static final String XML_START_STOP_LIST = "StartStopList"; private static final String XML_START_STOP_LIST = "StartStopList";
private static final String XML_START_STOP = "StartStop"; private static final String XML_START_STOP = "StartStop";
@ -73,12 +80,20 @@ public class InformationCollector implements XMLReadable, XMLWriter {
private static final String XML_UUID = "UUID"; private static final String XML_UUID = "UUID";
private static final String XML_KEY = "ActiveKey"; private static final String XML_KEY = "ActiveKey";
private static final String XML_OS = "OS"; 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 static InformationCollector collector;
//启动时间与关闭时间列表 /**
* 启动时间与关闭时间列表
*/
private List<StartStopTime> startStop = new ArrayList<StartStopTime>(); private List<StartStopTime> startStop = new ArrayList<StartStopTime>();
//上一次的发送时间
/**
* 上一次的发送时间
*/
private String lastTime; private String lastTime;
private StartStopTime current = new StartStopTime(); private StartStopTime current = new StartStopTime();
@ -130,7 +145,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
} }
try { try {
return DateUtils.string2Date(this.lastTime, true).getTime(); return Objects.requireNonNull(DateUtils.string2Date(this.lastTime, true)).getTime();
} catch (Exception e) { } catch (Exception e) {
return -1; return -1;
} }
@ -141,11 +156,12 @@ public class InformationCollector implements XMLReadable, XMLWriter {
JSONObject content = new JSONObject(); JSONObject content = new JSONObject();
JSONArray startStopArray = new JSONArray(); JSONArray startStopArray = new JSONArray();
for (int i = 0; i < startStop.size(); i++) { for (StartStopTime startStopTime : startStop) {
JSONObject jo = new JSONObject(); JSONObject jo = new JSONObject();
jo.put(ATTR_START, startStop.get(i).getStartDate()); jo.put(ATTR_START, startStopTime.getStartDate());
jo.put(ATTR_STOP, startStop.get(i).getStopDate()); jo.put(ATTR_STOP, startStopTime.getStopDate());
startStopArray.put(jo); startStopArray.put(jo);
}
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
content.put(XML_START_STOP, startStopArray); content.put(XML_START_STOP, startStopArray);
content.put(XML_UUID, envManager.getUUID()); content.put(XML_UUID, envManager.getUUID());
@ -154,12 +170,25 @@ public class InformationCollector implements XMLReadable, XMLWriter {
content.put(XML_USERNAME, MarketConfig.getInstance().getBbsUsername()); content.put(XML_USERNAME, MarketConfig.getInstance().getBbsUsername());
content.put(XML_KEY, envManager.getActivationKey()); content.put(XML_KEY, envManager.getActivationKey());
content.put(XML_OS, System.getProperty("os.name")); 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; return content;
} }
/**
* 获取物理内存单位GB
*
* @return 物理内存
*/
private static long getTotalPhysicalMemorySize() {
OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
return bean.getTotalPhysicalMemorySize() / BYTE_TO_MB;
}
private void sendUserInfo() { private void sendUserInfo() {
long currentTime = new Date().getTime(); long currentTime = System.currentTimeMillis();
long lastTime = getLastTimeMillis(); long lastTime = getLastTimeMillis();
if (currentTime - lastTime <= DELTA) { if (currentTime - lastTime <= DELTA) {
@ -196,7 +225,8 @@ public class InformationCollector implements XMLReadable, XMLWriter {
return; return;
} }
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("InformationCollector")); ScheduledExecutorService service = Executors
.newSingleThreadScheduledExecutor(new NamedThreadFactory("InformationCollector"));
service.schedule(new Runnable() { service.schedule(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -206,6 +236,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
ErrorInfoUploader.getInstance().sendErrorInfo(); ErrorInfoUploader.getInstance().sendErrorInfo();
} }
}, SEND_DELAY, TimeUnit.MILLISECONDS); }, SEND_DELAY, TimeUnit.MILLISECONDS);
service.shutdown();
} }
/** /**
@ -239,7 +270,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
XMLTools.writeOutputStreamXML(this, out); XMLTools.writeOutputStreamXML(this, out);
out.flush(); out.flush();
out.close(); 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); String encodeCotent = DesUtils.getEncString(fileContent);
writeEncodeContentToFile(encodeCotent, xmlFile); writeEncodeContentToFile(encodeCotent, xmlFile);
} catch (Exception e) { } catch (Exception e) {
@ -253,7 +284,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
*/ */
private static void writeEncodeContentToFile(String fileContent, File file) { private static void writeEncodeContentToFile(String fileContent, File file) {
try (FileOutputStream fos = new FileOutputStream(file); try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8); OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(osw)) { BufferedWriter bw = new BufferedWriter(osw)) {
bw.write(fileContent); bw.write(fileContent);
} catch (Exception e) { } catch (Exception e) {
@ -276,8 +307,8 @@ public class InformationCollector implements XMLReadable, XMLWriter {
private void writeStartStopList(XMLPrintWriter writer) { private void writeStartStopList(XMLPrintWriter writer) {
//启停 //启停
writer.startTAG(XML_START_STOP_LIST); writer.startTAG(XML_START_STOP_LIST);
for (int i = 0; i < startStop.size(); i++) { for (StartStopTime startStopTime : startStop) {
startStop.get(i).writeXML(writer); startStopTime.writeXML(writer);
} }
writer.end(); writer.end();
} }
@ -315,6 +346,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
startStop.clear(); startStop.clear();
reader.readXMLObject(new XMLReadable() { reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {
if (XML_START_STOP.equals(reader.getTagName())) { if (XML_START_STOP.equals(reader.getTagName())) {
StartStopTime startStopTime = new StartStopTime(); StartStopTime startStopTime = new StartStopTime();
@ -346,6 +378,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
this.stopDate = endDate; this.stopDate = endDate;
} }
@Override
public void writeXML(XMLPrintWriter writer) { public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_START_STOP); writer.startTAG(XML_START_STOP);
if (StringUtils.isNotEmpty(startDate)) { if (StringUtils.isNotEmpty(startDate)) {
@ -357,6 +390,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
writer.end(); writer.end();
} }
@Override
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {
this.startDate = reader.getAttrAsString(ATTR_START, StringUtils.EMPTY); this.startDate = reader.getAttrAsString(ATTR_START, StringUtils.EMPTY);
this.stopDate = reader.getAttrAsString(ATTR_STOP, StringUtils.EMPTY); this.stopDate = reader.getAttrAsString(ATTR_STOP, StringUtils.EMPTY);

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

@ -8,6 +8,7 @@ import com.fr.event.EventDispatcher;
import com.fr.event.Listener; import com.fr.event.Listener;
import com.fr.general.CloudCenter; import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils;
import com.fr.general.http.HttpToolbox; import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
@ -30,14 +31,15 @@ public class StartupMessageCollector {
private static final String XML_STARTUP_TIME = "t"; private static final String XML_STARTUP_TIME = "t";
private static final String XML_STARTUP_LOG = "startupLog"; private static final String XML_STARTUP_LOG = "startupLog";
private static final String XML_STARTUP_Memory = "designerMemory"; private static final String XML_STARTUP_MEMORY = "designerMemory";
private static final String XML_STARTUP_COST = "cost"; private static final String XML_STARTUP_COST = "cost";
private static final String XML_UUID = "UUID"; private static final String XML_UUID = "UUID";
private static final String XML_BUILD_NO = "buildNO";
private static final String STARTUP_URL_KEY = "user.info.v10.startup"; private static final String STARTUP_URL_KEY = "user.info.v10.startup";
private static final String LOG_TYPE = "single"; private static final String LOG_TYPE = "single";
private static final int BYTE_TO_MB = 1024 * 1024; private static final int BYTE_TO_MB = 1024 * 1024;
public static final StartupMessageCollector INSTANCE = new StartupMessageCollector(); private static final StartupMessageCollector INSTANCE = new StartupMessageCollector();
private StartupMessageCollector() { private StartupMessageCollector() {
} }
@ -67,10 +69,11 @@ public class StartupMessageCollector {
} }
JSONObject json = JSONObject.create() JSONObject json = JSONObject.create()
.put(XML_UUID, DesignerEnvManager.getEnvManager().getUUID()) .put(XML_UUID, DesignerEnvManager.getEnvManager().getUUID())
.put(XML_BUILD_NO, GeneralUtils.readBuildNO())
.put(XML_STARTUP_TIME, FineRuntime.getAppStartTime() + FineRuntime.getStartingTime()) .put(XML_STARTUP_TIME, FineRuntime.getAppStartTime() + FineRuntime.getStartingTime())
.put(XML_STARTUP_COST, FineRuntime.getStartingTime()) .put(XML_STARTUP_COST, FineRuntime.getStartingTime())
.put(XML_STARTUP_LOG, profile) .put(XML_STARTUP_LOG, profile)
.put(XML_STARTUP_Memory, Runtime.getRuntime().totalMemory() / BYTE_TO_MB); .put(XML_STARTUP_MEMORY, Runtime.getRuntime().maxMemory() / BYTE_TO_MB);
sendInfo(json, url + LOG_TYPE); sendInfo(json, url + LOG_TYPE);
} }
}); });

Loading…
Cancel
Save