Obsidian/Recognition/zzz.resources/MainController.java

932 lines
27 KiB
Java
Raw Normal View History

2023-08-14 16:19:25 +00:00
package kr.gmtc.filter.controller;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Resource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import gmt.common.type.LogLevelType;
import gmt.common.util.GmtUtils;
import gmt.common.vo.MonitorInfoVO;
import gmt.common.vo.MsgObjVO;
import gmt.common.vo.SystemInfoVO;
import gmt.controller.GmtController;
import gmt.io.client.event.GmtClientEventListener;
import gmt.io.client.vo.ClientInfoVO;
import gmt.io.server.event.GmtServerEventListener;
import gmt.io.server.vo.ServerInfoVO;
import gmt.io.server.vo.ServiceClientVO;
import gmt.logger.GmtLogManager;
import gmt.logger.event.IGmtLogSendHandler;
import gmt.proj.gw_filter.analysis.TargetAnalysis;
import gmt.proj.gw_filter.analysis.point.PointInPolygon.Point;
import gmt.proj.gw_filter.rest.vo.InOutVO;
import gmt.proj.gw_filter.thread.ThreadManager;
import gmt.proj.gw_filter.vo.OptionVO;
import gmt.status.GmtSTAManager;
import gmt.status.event.IGmtHeartBeatHandler;
import gmt.status.event.IGmtServicesStatusHandler;
import gmt.status.event.IGmtSysStatusHandler;
import kr.gmtc.filter.controller.vo.AreaVO;
import kr.gmtc.filter.fso.GeofenceFilter;
import kr.gmtc.filter.rest.RestManager;
import kr.gmtc.filter.scheduler.vo.CountVO;
import kr.gmtc.filter.scheduler.vo.ResourceVO;
@Component("controller")
public class MainController extends GmtController{
private String startTime;
private String delimiter;
private SystemInfoVO systemInfo;
private GmtSTAManager statusManager;
private IGmtSysStatusHandler statusHandler;
private IGmtHeartBeatHandler gmsHandler;
private IGmtServicesStatusHandler serviceHandler;
private IGmtLogSendHandler logHandler;
private TargetAnalysis targetAnalysis = new TargetAnalysis();
private ThreadManager thrManager = new ThreadManager();
private boolean isRunning;
private Thread SendPakcetThread;
@Resource(name = "rvo")
ResourceVO rvo;
@Resource(name = "countVO")
CountVO countVO;
@Autowired
private RestManager restManager;
@Autowired
private GeofenceFilter geofenceFilter;
private String rootPath = "";
@Value("${dmfhf.port}")
private int dmfhfPort;
@Value("${fso.port}")
private int fsoPort;
@Value("${fso.relay.port}")
private int fsoRelayPort;
@Value("${tgw.ip}")
private String tgwIp;
@Value("${tgw.serverPort}")
private int tgwPort;
private LocalDateTime sosSendDT = LocalDateTime.now();
private LocalDateTime posSendDT = LocalDateTime.now();
public List<AreaVO> AreaList = new ArrayList<AreaVO>();
private List<String> TGWConnectList = new ArrayList<String>();
public List<MsgObjVO> FsoRelayList = new ArrayList<MsgObjVO>();
public List<MsgObjVO> DmfhfList = new ArrayList<MsgObjVO>();
public List<MsgObjVO> FSOList = new ArrayList<MsgObjVO>();
protected MainController(@Value("${root}") String path) {
super(path);
GmtLogManager.setpath(path);
startTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
delimiter = ",";
systemInfo = new SystemInfoVO();
rootPath = path;
logger = GmtLogManager.getInstance();
logger.writeLevelLog("[GmtLogManager] PATH : " + path, LogLevelType.LOG_INFO, "AllLog");
logHandler = new IGmtLogSendHandler() {
@Override
public void sendlLog(String msg, String name, LogLevelType loglevel) {
sendLog(msg, name, loglevel);
}
};
logger.setLogSendHandler(logHandler);
statusHandler = new IGmtSysStatusHandler() {
@Override
public void sendStatus() {
String systemMsg = getSystemStatus();
rvo.setSystem(systemMsg);
sendSTA(systemMsg);
// logger.writeLevelLog("[SEND STATUS] " + systemMsg, LogLevelType.LOG_INFO, "FileLog", false);
String clientMsg = getClientStatus();
rvo.setClient(clientMsg);
sendSTA(clientMsg);
// logger.writeLevelLog("[SEND STATUS] " + clientMsg, LogLevelType.LOG_INFO, "FileLog", false);
String serverMsg = getServerStatus();
rvo.setServer(serverMsg);
sendSTA(serverMsg);
// logger.writeLevelLog("[SEND STATUS] " + serverMsg, LogLevelType.LOG_INFO, "FileLog", false);
if(!systemInfo.getStatSend()) {
return;
}
}
};
statusManager = new GmtSTAManager(statusHandler, gmsHandler, serviceHandler);
initSystemFromXml(path);
initAreaFromXml(path);
SendPakcetThread = new Thread(new Runnable() {
@Override
public void run() {
while (isRunning) {
try {
SendFsoRelayPacket();
SendFsoPacket();
SendDmfhfPacket();
} finally {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
});
}
public void start() {
super.start();
thrManager.optionThread(rootPath);
thrManager.xmlThread(rootPath);
thrManager.start();
statusManager.start();
restManager.start();
isRunning = true;
SendPakcetThread.start();
}
private void SendFsoRelayPacket() {
try {
List<MsgObjVO> tempList = new ArrayList<MsgObjVO>();
tempList.addAll(FsoRelayList);
FsoRelayList.clear();
for (int i=0;i<tempList.size();i++) {
broadcastServer(fsoRelayPort, tempList.get(i));
}
} catch (Exception e) {
logger.writeLevelLog("[SendFsoRelayPacket] " + e.getMessage(), LogLevelType.LOG_ERROR, "AllLog", false);
}
}
private void SendFsoPacket() {
try {
List<MsgObjVO> tempList = new ArrayList<MsgObjVO>();
tempList.addAll(FSOList);
FSOList.clear();
for (int i=0;i<tempList.size();i++) {
broadcastServer(fsoPort, tempList.get(i));
}
} catch (Exception e) {
logger.writeLevelLog("[SendFsoPacket] " + e.getMessage(), LogLevelType.LOG_ERROR, "AllLog", false);
}
}
private void SendDmfhfPacket() {
try {
List<MsgObjVO> tempList = new ArrayList<MsgObjVO>();
tempList.addAll(DmfhfList);
DmfhfList.clear();
for (int i=0;i<tempList.size();i++) {
broadcastServer(dmfhfPort, tempList.get(i));
}
} catch (Exception e) {
logger.writeLevelLog("[SendDmfhfPacket] " + e.getMessage(), LogLevelType.LOG_ERROR, "AllLog", false);
}
}
@Override
protected void clientDataIn(MsgObjVO vo) {
int count = 0;
MsgObjVO encVO = vo.getClone();
String msgs = new String(vo.getMsg());
if(msgs.substring(0,3).equals("$92") && (encVO.getRecvPort() == 8031)) { //DMFHF
logger.writeLevelLog(msgs, LogLevelType.LOG_INFO, "PacketLog", false);
if ( (restManager.getShipVO_SlotNO(msgs.substring(4,16).trim()) == null) ) {
logger.writeLevelLog("[clientDataIn] 존재하지 않는 SLOT : " + msgs, LogLevelType.LOG_INFO, "PacketLog_Filter", false);
return;
}
//SOS bypass
if (msgs.substring(3,4).equals("4")) {
logger.writeLevelLog("[Send SOS] " + msgs, LogLevelType.LOG_INFO, "SendLog", false);
//연계상태 갱신
if (TGWConnectList.size() > 0) {
sosSendDT = LocalDateTime.now();
}
//D-MFHF -> FSO 연계
broadcastServer(fsoRelayPort, encVO);
FsoRelayList.add(encVO);
} else if (msgs.substring(3,4).equals("5")) {
//D-MFHF -> FSO 연계
count = countVO.getFso();
countVO.setFso(++count);
logger.writeLevelLog("[Send Packet (D-MFHF -> FSO)] " + msgs, LogLevelType.LOG_INFO, "SendLog", false);
// broadcastServer(fsoRelayPort, encVO);
FsoRelayList.add(encVO);
//연계상태 갱신
if (TGWConnectList.size() > 0) {
posSendDT = LocalDateTime.now();
}
OptionVO option = thrManager.getOptions();
if (option == null) {
logger.writeLevelLog("[Send Packet] Area is null" + msgs, LogLevelType.LOG_INFO, "AllLog", false);
return;
}
if(!targetAnalysis.AreaAnalysis(msgs, option.getArea())) {
MsgObjVO mvo = encVO.getClone();
byte[] header = "!1".getBytes();
count = countVO.getFilter1();
countVO.setFilter1(++count);
mvo.setMsg(addArray(header, encVO.getMsg()));
logger.writeLevelLog("[Send Packet] 위경도 입력범위 초과 : " + msgs, LogLevelType.LOG_INFO, "SendLog", false);
DmfhfList.add(mvo);
// broadcastServer(dmfhfPort, encVO);
} else {
ConcurrentHashMap<String, List<Point>> districtMap = restManager.getDistrictList();
if (districtMap == null) {
logger.writeLevelLog("[Send Packet] DistrictMap is null" + msgs, LogLevelType.LOG_INFO, "AllLog", false);
return;
}
if(!targetAnalysis.DistrictAnalysis(msgs, districtMap)) {
MsgObjVO mvo = encVO.getClone();
byte[] header = "!2".getBytes();
count = countVO.getFilter2();
countVO.setFilter2(++count);
mvo.setMsg(addArray(header, encVO.getMsg()));
logger.writeLevelLog("[Send Packet] 조업자제구역 : " + msgs, LogLevelType.LOG_INFO, "SendLog", false);
DmfhfList.add(mvo);
// broadcastServer(dmfhfPort, mvo);
} else {
String slot = msgs.substring(4, 16);
InOutVO inout = restManager.getInOutList().get(slot.trim());
if (inout == null) {
logger.writeLevelLog("[Send Packet] InOut is null" + msgs, LogLevelType.LOG_INFO, "AllLog", false);
return;
}
if(!targetAnalysis.InOutAnalysis(msgs, inout.getInout_part())) {
MsgObjVO mvo = encVO.getClone();
byte[] header = "!3".getBytes();
count = countVO.getFilter3();
countVO.setFilter3(++count);
mvo.setMsg(addArray(header, encVO.getMsg()));
logger.writeLevelLog("[Send Packet] 입항상태 : " + msgs, LogLevelType.LOG_INFO, "SendLog", false);
DmfhfList.add(mvo);
// broadcastServer(dmfhfPort, encVO);
}
}
}
}
} else if(msgs.substring(0,3).equals("$11")) { //AIS
if ( (restManager.getShipVO_MMSI(msgs.substring(4,16).trim()) == null) ) {
return;
}
FSOList.add(encVO);
// broadcastServer(fsoPort, encVO);
} else if(msgs.substring(0,3).equals("$90")) { //VPASS
if ( (restManager.getShipVO_RFID(msgs.substring(4,16).trim()) == null) ) {
return;
}
FSOList.add(encVO);
// broadcastServer(fsoPort, encVO);
} else if(msgs.substring(0,3).equals("$19")) { //VHF-DSC
if ( (restManager.getShipVO_MMSI(msgs.substring(4,16).trim()) == null) ) {
return;
}
FSOList.add(encVO);
// broadcastServer(fsoPort, encVO);
} else if(msgs.substring(0,4).equals("$FSO")) { //Geofence 알람
try {
if (geofenceFilter.CheckGeofence(msgs) ) {
FSOList.add(encVO);
// broadcastServer(fsoPort, encVO);
}
} catch (Exception e) {
logger.writeLevelLog("[Geofence 알람 패킷 분석 실패] " + msgs, LogLevelType.LOG_ERROR, "AllLog", false);
}
}
}
private byte[] addArray(byte[] tmp, byte[] tmp2) {
byte[] resultArray = new byte[tmp.length + tmp2.length];
System.arraycopy(tmp, 0, resultArray, 0, tmp.length);
System.arraycopy(tmp2, 0, resultArray, tmp.length, tmp2.length);
return resultArray;
}
@Override
protected GmtClientEventListener createClientEventListener() {
GmtClientEventListener listener = new GmtClientEventListener() {
@Override
public void readyToSend() {
}
@Override
public void error(String ip, int port, int errorCode, String description) {
}
@Override
public void disconnected(String ip, int port, int statusCode, String description) {
String msg = "[Client Disconnect : IP[" + ip + "] / PORT [" + String.valueOf(port) + "] ";
logger.writeLevelLog(msg, LogLevelType.LOG_INFO, "AllLog");
}
@Override
public void dataIn() {
}
@Override
public void connectionStatus(String ip, int port, String connEvent, int statusCode, String description) {
}
@Override
public void connected(String ip, int port, int statusCode, String description) {
String msg = "[Client Connect : IP[" + ip + "] / PORT [" + String.valueOf(port) + "] ";
logger.writeLevelLog(msg, LogLevelType.LOG_INFO, "AllLog");
}
@Override
public void SSLStatus() {
}
@Override
public void SSLServerAuthentication() {
}
};
return listener;
}
@Override
protected GmtServerEventListener createServerEventListener() {
GmtServerEventListener listener = new GmtServerEventListener() {
@Override
public void readyToSend(int port) {
}
@Override
public void error(int serverPort, String remoteHost, int remotePort, int errorCode, String description) {
}
@Override
public void disconnected(int serverPort, String remoteHost, int remotePort) {
String msg = "[SERVER " + String.valueOf(serverPort) + "] SC Disconnected.. IP : " + remoteHost
+ " PORT : " + String.valueOf(remotePort);
logger.writeLevelLog(msg, LogLevelType.LOG_INFO, "AllLog");
if ( (serverPort == tgwPort) && remoteHost.equals(tgwIp) ) {
TGWConnectList.remove(remoteHost);
}
}
@Override
public void dataIn(int serverPort, String remoteHost, int remotePort, String msg) {
}
@Override
public void connected(int serverPort, String remoteHost, int remotePort) {
String msg = "[SERVER " + String.valueOf(serverPort) + "] SC Connected.. IP : " + remoteHost
+ " PORT : " + String.valueOf(remotePort);
logger.writeLevelLog(msg, LogLevelType.LOG_INFO, "AllLog");
if ((serverPort == tgwPort) && remoteHost.equals(tgwIp) ) {
TGWConnectList.add(remoteHost);
}
}
@Override
public void SSLClientAuthentication(int serverPort) {
}
};
return listener;
}
@Override
protected void serialDataIn(MsgObjVO vo) {
}
@Override
protected void serverDataIn(MsgObjVO vo) {
}
private void sendLog(String msg, String name, LogLevelType Loglevel) {
LocalDateTime dt = LocalDateTime.now();
String currentTime = dt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
MsgObjVO vo = new MsgObjVO();
switch (Loglevel.ordinal()) {
case 0:
msg = "[" + currentTime + "] " + ":" + " TRACE " + ": " + msg;
break;
case 1:
msg = "[" + currentTime + "] " + ":" + " DEBUG " + ": " + msg;
break;
case 2:
msg = "[" + currentTime + "] " + ":" + " INFO " + ": " + msg;
break;
case 3:
msg = "[" + currentTime + "] " + ":" + " WARN " + ": " + msg;
break;
case 4:
msg = "[" + currentTime + "] " + ":" + " ERROR " + ": " + msg;
break;
case 5:
msg = "[" + currentTime + "] " + ":" + " FATAL " + ": " + msg;
break;
}
try {
vo.setMsg(msg.getBytes("EUC-KR"));
} catch (UnsupportedEncodingException e) {
logger.writeLevelLog(GmtUtils.getStatckTrace(e), LogLevelType.LOG_ERROR, "fileLog");
e.printStackTrace();
}
broadcastServer(systemInfo.getLogPort(), vo);
}
@SuppressWarnings("unchecked")
public String getSystemStatus() {
JSONObject data = new JSONObject();
data.put("RecvBuffer", getRcvBuffer());
data.put("SendBuffer", getSndBuffer());
data.put("Start", startTime);
return makeSTA(0, 1, data);
}
@SuppressWarnings("unchecked")
public String getClientStatus() {
JSONArray data = new JSONArray();
for (int i = 0; i < clientInfoList.size(); i++) {
ClientInfoVO civo = clientInfoList.get(i);
MonitorInfoVO cimvo = civo.getMonitorInfo();
if (!civo.isiSUse()) {
continue;
}
JSONObject jo1 = new JSONObject();
jo1.put("ID", civo.getId());
jo1.put("ClientName", civo.getName());
switch (civo.getActive().getName()) {
case "PRIMARY":
jo1.put("Active", 0);
jo1.put("IP", civo.getIp());
break;
case "SECONDARY":
jo1.put("Active", 1);
jo1.put("IP", civo.getsIp());
break;
}
jo1.put("Port", civo.getPort());
jo1.put("SendBuffer", cimvo.getSendQCount());
jo1.put("Connect", cimvo.isConnected());
data.add(jo1);
}
return makeSTA(0, 4, data);
}
@SuppressWarnings("unchecked")
public String getServerStatus() {
JSONArray data = new JSONArray();
for (int i = 0; i < serverInfoList.size(); i++) {
ServerInfoVO sivo = serverInfoList.get(i);
MonitorInfoVO mvo = sivo.getMonitorInfo();
JSONObject jo2 = new JSONObject();
jo2.put("ID", sivo.getId());
jo2.put("ServerName", sivo.getName());
jo2.put("ServerPort", sivo.getPort());
jo2.put("SCCount", sivo.getServiceClientCount());
jo2.put("SendBuffer", mvo.getSendQCount());
jo2.put("Use", sivo.isUseFlag());
int sport = sivo.getPort();
JSONArray ja1 = new JSONArray();
if (sivo.getServiceClientCount() != 0) {
Object[] keys = serverScInfoList.keySet().toArray();
for (int j = 0; j < keys.length; j++) {
ServiceClientVO scvo = serverScInfoList.get(keys[j]);
MonitorInfoVO mvo2 = scvo.getMonitorInfoVO();
JSONObject jo1 = new JSONObject();
int scport = scvo.getServerPort();
if (sport == scport) {
jo1.put("ID", scvo.getId());
jo1.put("ServiceName", scvo.getName());
jo1.put("ServiceIP", scvo.getIp());
jo1.put("ServicePort", scvo.getServicePort());
jo1.put("SendBuffer", scvo.getReSendQ().size());
jo1.put("Connect", mvo2.isConnected());
ja1.add(jo1);
}
}
}
jo2.put("SC", ja1);
data.add(jo2);
}
return makeSTA(0, 3, data);
}
@SuppressWarnings("unchecked")
private String makeSTA(int msgGroup, int msgId, JSONObject data) {
JSONObject header = new JSONObject();
String sendDT = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
header.put("SendDT", sendDT);
header.put("MsgGroup", msgGroup);
header.put("MsgID", msgId);
JSONObject response = new JSONObject();
response.put("Header", header);
response.put("Data", data);
JSONArray array = new JSONArray();
array.add(response);
JSONObject result = new JSONObject();
result.put("result", array);
return result.toString();
}
@SuppressWarnings("unchecked")
private String makeSTA(int msgGroup, int msgId, JSONArray data) {
JSONObject header = new JSONObject();
String sendDT = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
header.put("SendDT", sendDT);
header.put("MsgGroup", msgGroup);
header.put("MsgID", msgId);
JSONObject response = new JSONObject();
response.put("Header", header);
response.put("Data", data);
JSONArray array = new JSONArray();
array.add(response);
JSONObject result = new JSONObject();
result.put("result", array);
return result.toString();
}
public String makeHeader() {
String headers = "";
String packetId = "$STA01"+delimiter;
String sendTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))+delimiter;
String sourceProcessNm = "TGW"+delimiter; // 패킷생성 Process
String sourceIp = "";
try {
sourceIp = InetAddress.getLocalHost().getHostAddress()+delimiter;//출발지 IP (자기 IP)
} catch (UnknownHostException e) {
e.printStackTrace();
}
String destProcessNm = ""+delimiter; //수신 Process 명
String destIP = ""+delimiter; //목적지 IP
headers = packetId
+sendTime
+sourceProcessNm
+sourceIp
+destProcessNm
+destIP;
return headers;
}
/*gicoms add*/
private void sendSTA(String msg) {
try {
if (msg.equals("") || msg == null) {
return;
}
MsgObjVO vo = new MsgObjVO();
vo.setMsg(msg.getBytes("EUC-KR"));
int port = systemInfo.getStatPort();
broadcastServer(port, vo);
} catch (Exception e) {
logger.writeLevelLog("[SEND STATUS] " + GmtUtils.getStatckTrace(e), LogLevelType.LOG_INFO, "FileLog", false);
}
}
private void initAreaFromXml(String dirpath) {
try {
String rpath = "";
if (dirpath.equals("")) {
String root = System.getProperty("user.dir");
rpath = root + "/cfg/Area.xml";
} else {
rpath = dirpath + "/cfg/Area.xml";
}
File file = new File(rpath);
boolean isExists = file.exists();
if (!isExists) {
logger.writeLevelLog("The file does not exist in the directory. [" + rpath + "]",
LogLevelType.LOG_ERROR, "AllLog");
return;
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes = doc.getElementsByTagName("AREA");
for (int i = 0; i < nodes.getLength(); i++) {
Node clientNode = nodes.item(i);
for (Node child = clientNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
AreaVO avo = new AreaVO();
Element childElement = (Element) child;
if (childElement.getNodeName().equals("Zone")) {
avo.setZone_id(childElement.getAttribute("Id"));
avo.setZone_nm(childElement.getAttribute("Name"));
avo.setZone_cd(childElement.getAttribute("Code"));
}
AreaList.add(avo);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void initSystemFromXml(String dirpath) {
try {
String rpath = "";
if (dirpath.equals("")) {
String root = System.getProperty("user.dir");
rpath = root + "/cfg/system.xml";
} else {
rpath = dirpath + "/cfg/system.xml";
}
File file = new File(rpath);
boolean isExists = file.exists();
if (!isExists) {
logger.writeLevelLog("The file does not exist in the directory. [" + rpath + "]",
LogLevelType.LOG_ERROR, "AllLog");
return;
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes = doc.getElementsByTagName("System");
for (int i = 0; i < nodes.getLength(); i++) {
Node clientNode = nodes.item(i);
for (Node child = clientNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element childElement = (Element) child;
if (childElement.getNodeName().equals("Info")) {
systemInfo.setName(childElement.getAttribute("Name"));
systemInfo.setIp(childElement.getAttribute("IP"));
systemInfo.setHa(GmtUtils.strToIntDef(childElement.getAttribute("HA"), -1));
} else if (child.getNodeName().equals("Option")) {
systemInfo.setBufSize(GmtUtils.strToIntDef(childElement.getAttribute("BufSize"), -1));
} else if (child.getNodeName().equals("Log")) {
systemInfo.setLogLevel(GmtUtils.strToIntDef(childElement.getAttribute("Level"), -1));
systemInfo.setLogPort(GmtUtils.strToIntDef(childElement.getAttribute("Port"), -1));
} else if (child.getNodeName().equals("Stat")) {
systemInfo.setStatChktime(GmtUtils.strToIntDef(childElement.getAttribute("CheckTime"), -1));
systemInfo.setUpdateTime(GmtUtils.strToIntDef(childElement.getAttribute("UpdateTime"), -1));
systemInfo.setStatSendTime(GmtUtils.strToIntDef(childElement.getAttribute("SndTime"), -1));
systemInfo.setStatSend(Boolean.parseBoolean(childElement.getAttribute("IsSend")));
systemInfo.setStatPort(GmtUtils.strToIntDef(childElement.getAttribute("Port"), -1));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public SystemInfoVO getSystemInfo() {
return systemInfo;
}
public void setSystemInfo(SystemInfoVO systemInfo) {
this.systemInfo = systemInfo;
}
//Monitoring
@SuppressWarnings("unchecked")
@GetMapping(value = "/rest/serverStatus")
public JSONArray loadServerStatusInfo() throws Exception{
JSONArray data = new JSONArray();
for (int i = 0; i < serverInfoList.size(); i++) {
ServerInfoVO sivo = serverInfoList.get(i);
MonitorInfoVO mvo = sivo.getMonitorInfo();
JSONObject jo2 = new JSONObject();
jo2.put("ID", sivo.getId());
jo2.put("ServerName", sivo.getName());
jo2.put("ServerPort", sivo.getPort());
jo2.put("SCCount", sivo.getServiceClientCount());
jo2.put("SendBuffer", mvo.getSendQCount());
jo2.put("Use", sivo.isUseFlag());
int sport = sivo.getPort();
JSONArray ja1 = new JSONArray();
if (sivo.getServiceClientCount() != 0) {
Object[] keys = serverScInfoList.keySet().toArray();
for (int j = 0; j < keys.length; j++) {
ServiceClientVO scvo = serverScInfoList.get(keys[j]);
MonitorInfoVO mvo2 = scvo.getMonitorInfoVO();
JSONObject jo1 = new JSONObject();
int scport = scvo.getServerPort();
if (sport == scport) {
jo1.put("ID", scvo.getId());
jo1.put("ServiceName", scvo.getName());
jo1.put("ServiceIP", scvo.getIp());
jo1.put("ServicePort", scvo.getServicePort());
jo1.put("SendBuffer", scvo.getReSendQ().size());
jo1.put("Connect", mvo2.isConnected());
ja1.add(jo1);
}
}
}
jo2.put("SC", ja1);
data.add(jo2);
}
return data;
}
@SuppressWarnings("unchecked")
@GetMapping(value = "/rest/clientStatus")
public JSONArray loadClientStatusInfo() throws Exception{
JSONArray data = new JSONArray();
for (int i = 0; i < clientInfoList.size(); i++) {
ClientInfoVO civo = clientInfoList.get(i);
MonitorInfoVO cimvo = civo.getMonitorInfo();
if (!civo.isiSUse()) {
continue;
}
JSONObject jo1 = new JSONObject();
jo1.put("ID", civo.getId());
jo1.put("ClientName", civo.getName());
switch (civo.getActive().getName()) {
case "PRIMARY":
jo1.put("Active", 0);
jo1.put("IP", civo.getIp());
break;
case "SECONDARY":
jo1.put("Active", 1);
jo1.put("IP", civo.getsIp());
break;
}
jo1.put("Port", civo.getPort());
jo1.put("SendBuffer", cimvo.getSendQCount());
jo1.put("RecvBuffer", cimvo.getRecvQCount());
jo1.put("Connect", cimvo.isConnected());
data.add(jo1);
}
return data;
}
@SuppressWarnings("unchecked")
@GetMapping(value = "/rest/systemStatus")
public JSONObject loadSystemStatusInfo() throws Exception{
JSONObject data = new JSONObject();
data.put("RecvBuffer", getRcvBuffer());
data.put("SendBuffer", getSndBuffer());
data.put("Start", startTime);
return data;
}
public LocalDateTime getSosSendDT() {
return this.sosSendDT;
}
public LocalDateTime getPosSendDT() {
return this.posSendDT;
}
}