Obsidian/Recognition/zzz.resources/MainController 1.java

882 lines
26 KiB
Java
Raw Normal View History

2023-08-14 16:19:25 +00:00
package kr.gmtc.eyesvmsg.controller;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
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.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
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 kr.gmtc.eyesvmsg.send.call.CallController;
import kr.gmtc.eyesvmsg.send.call.CallService;
import kr.gmtc.eyesvmsg.send.chat.ChatController;
import kr.gmtc.eyesvmsg.send.dsast.DsastController;
import kr.gmtc.eyesvmsg.send.img.ImgController;
import kr.gmtc.eyesvmsg.send.img.ImgService;
import kr.gmtc.eyesvmsg.send.passivlc.CheckLastLcController;
import kr.gmtc.eyesvmsg.send.passivlc.PassivlcController;
import kr.gmtc.eyesvmsg.send.passivlc.PassivlcService;
import kr.gmtc.eyesvmsg.send.sms.SmsController;
import kr.gmtc.eyesvmsg.send.specialnews.SpecialNewsController;
import kr.gmtc.eyesvmsg.send.typhoon.TyphnController;
import kr.gmtc.eyesvmsg.send.typhoon.TyphnService;
import kr.gmtc.eyesvmsg.send.weather.WeatherController;
import kr.gmtc.eyesvmsg.send.weather.WeatherService;
import kr.gmtc.eyesvmsg.service.DbService;
@RestController
@Component("controller")
public class MainController extends GmtController {
@Resource(name = "packetMap")
public HashMap<String, ArrayList<String>> packetMap;
@Resource(name = "packetQ")
Queue<String> packetQ;
private SystemInfoVO systemInfo;
private IGmtLogSendHandler logHandler;
private GmtLogManager logger;
private String startTime;
public int TID = 1;
public String CLIENT_IP;
public int CLIENT_ID;
public int CLIENT_PORT;
public boolean flag = true;
@Resource(name = "dbController")
DbController dbController;
@Resource(name = "smsController")
SmsController smsController;
@Resource(name = "imgController")
ImgController imgController;
@Resource(name = "imgService")
ImgService imgService;
@Resource(name = "callController")
CallController callController;
@Resource(name = "callService")
CallService callService;
@Resource(name = "passivlcController")
PassivlcController passivlcController;
@Resource(name = "passivlcService")
PassivlcService passivlcService;
@Resource(name = "weatherController")
WeatherController weatherController;
@Resource(name = "weatherService")
WeatherService weatherService;
@Resource(name = "typhnController")
TyphnController typhnController;
@Resource(name = "typhnService")
TyphnService typhnService;
@Resource(name = "dsastController")
DsastController dsastController;
@Resource(name = "specialNewsController")
SpecialNewsController specialNewsController;
@Resource(name = "dbService")
DbService dbService;
@Resource(name = "chatController")
ChatController chatController;
@Resource(name = "checkLastLcController")
CheckLastLcController checkLastLcController;
private boolean checkLastLcRunning;
private Thread checkLastLcThread;
//스레드 선언
private boolean sendRunning;
private Thread sendThread;
private boolean hbRunning;
private Thread hbThread;
// 메시지 송신 간격
@Value("${msg.interval}")
private int sendIntvl = 5000;
// 메시지 별 송신 텀
@Value("${msg.term}")
private int msgTerm = 3000;
// 메시지 별 송신 텀
@Value("${msg.sndCnt}")
private int msgSndCnt = 2;
// 위치미수신 자동 송신 횟수(1회에 30분)
@Value("${msg.PassivLc.sndCnt}")
private int passivLcSndCnt = 2;
// 사이트별 송신 텀(단문자)
@Value("${site.sms}")
private int smsIntvl = 10000;
// 사이트별 송신 텀(이미지)
@Value("${site.img}")
private int imgIntvl = 10000;
// 이미지 송신 블럭사이즈 별 텀
@Value("${site.imgSub}")
private int imgSubIntvl = 2500;
// 사이트별 송신 텀(기상예보)
@Value("${site.wether}")
private int wetherIntvl = 10000;
// 사이트별 송신 텀(태풍정보)
@Value("${site.typhn}")
private int typhnIntvl = 10000;
// 사이트별 송신 텀(수동위치요청)
@Value("${site.passivlc}")
private int passivlcIntvl = 10000;
// 사이트별 송신 텀(조난응답)
@Value("${site.dsast}")
private int dsastIntvl = 10000;
// 사이트별 송신 텀(개별호출,영역호출)
@Value("${site.call}")
private int callIntvl = 10000;
// 사이트별 송신 텀(기상특보)
@Value("${site.special}")
private int specialIntvl = 10000;
// 사이트별 송신 텀(채팅)
@Value("${site.chat}")
private int chatIntvl = 10000;
// Server LifePacket 송신 간격
@Value("${setting.hb}")
private int hbIntvl = 10;
@Value("${msg.order}")
private String msgArrayStr;
@Value("${patch.mode}")
private boolean patchMode = false;
// GW서버 접속 정보
@Value("${connect.ip}")
private String conIp = "138.252.11.111";
@Value("${connect.port}")
private Integer conPort = 8040;
public MainController(@Value("${root}") String path) {
super(path);
GmtLogManager.setpath(path);
startTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
systemInfo = new SystemInfoVO();
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);
initSystemFromXml(path);
// SendController sendController = new SendController();
sendThread = new Thread(new Runnable() {
@Override
public void run() {
LocalDateTime startTime = LocalDateTime.now();
while (sendRunning) {
// ALE : 시간 00분00초~01분00초 메세지 전송 안함
// ALE : 시간 30분00초~31분00초 메세지 전송 안함
LocalTime lt = LocalTime.now();
LocalTime min_0 = LocalTime.of(0, 0, 0);
LocalTime min_30 = LocalTime.of(0, 30, 0);
// 현재 시간값을 hour를 0으로 세팅해준후 비교
LocalTime tmpLt = LocalTime.of(0, lt.getMinute(), lt.getSecond());
if (tmpLt.isAfter(min_0.plusMinutes(1))&&tmpLt.isBefore(min_30)||tmpLt.isAfter(min_30.plusMinutes(1))) {
Duration duration = Duration.between(startTime, LocalDateTime.now());
if (duration.getSeconds() >= 1) {
startTime = LocalDateTime.now();
try {
// process 0:미처리, 3:일부실패재전송
int[] intArray = {0, 3};
// 1.조난응답(14), 2.개별/영역호출(16), 3.단문자(3), 4.수동위치요청(11), 4.기상특보(18), 5.기상예보(5), 7.태풍(6), 8.이미지(4), 6.채팅(30)
String[] msgOrder = msgArrayStr.replaceAll(" ", "").split(",");
int[] msgArray = Arrays.stream(msgOrder).mapToInt(Integer::parseInt).toArray();
for(int process : intArray) {
for(int msgArr : msgArray) {
send(msgArr, process);
}
}
} catch (Exception e) {
logger.writeLevelLog("[sendThread] " + GmtUtils.getStatckTrace(e), LogLevelType.LOG_ERROR, "AllLog");
} finally {
try {
Thread.sleep(sendIntvl);
} catch (InterruptedException e) {
logger.writeLevelLog("[sendThread] : " + GmtUtils.getStatckTrace(e), LogLevelType.LOG_ERROR, "AllLog");
}
}
}
}
}
}
});
checkLastLcThread = new Thread(new Runnable() {
@Override
public void run() {
while (checkLastLcRunning) {
try {
// 미수신 30분/60분
int min = 30;
// 수동위치 자동 송신 횟수 설정Cnt
for(int i = 0; i < passivLcSndCnt; i++) {
logger.writeLevelLog("[checkLastLcThread] passivLcSndCnt for cnt : " + i , LogLevelType.LOG_INFO, "PASSIVLC_AUTO");
checkLastLcController.CheckLastLc(min);
min = min + 30;
Thread.sleep(10000);
}
// STD 송신
List<String> stdList = new ArrayList<>();
stdList = checkLastLcController.SendSTD();
if(!stdList.isEmpty()) {
for(int i = 0; i < stdList.size(); i++) {
MsgObjVO msg = new MsgObjVO();
msg.setMsg(stdList.get(i).getBytes("EUC-KR"));
sendClient(clientInfoList.get(0).getIp(), clientInfoList.get(0).getPort(), msg);
logger.writeLevelLog("[checkLastLcThread] STD : " + stdList.get(i) , LogLevelType.LOG_INFO, "STDPacket");
}
}
} catch (Exception e) {
logger.writeLevelLog("[checkLastLcThread] " + GmtUtils.getStatckTrace(e), LogLevelType.LOG_ERROR, "AllLog");
} finally {
try {
Thread.sleep(40000);
} catch (InterruptedException e) {
logger.writeLevelLog("[checkLastLcThread] : " + GmtUtils.getStatckTrace(e), LogLevelType.LOG_ERROR, "AllLog");
}
}
}
}
});
hbThread = new Thread(new Runnable() {
@Override
public void run() {
LocalDateTime startTime = LocalDateTime.now();
while (hbRunning) {
Duration duration = Duration.between(startTime, LocalDateTime.now());
if (duration.getSeconds() >= hbIntvl) {
startTime = LocalDateTime.now();
try {
if (ConnectCheck()) {
String hb = "$HB";
MsgObjVO msg = new MsgObjVO();
msg.setMsg(hb.getBytes("EUC-KR"));
for(ClientInfoVO ciVO : clientInfoList) {
sendClient(ciVO.getIp(), ciVO.getPort(), msg);
}
}
} catch (Exception e) {
logger.writeLevelLog("[hbThread] " + GmtUtils.getStatckTrace(e), LogLevelType.LOG_ERROR, "AllLog");
} finally {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.writeLevelLog("[hbThread] : " + GmtUtils.getStatckTrace(e), LogLevelType.LOG_ERROR, "AllLog");
}
}
}
}
}
});
}
public void send(int msgId, int process) {
try {
loop:
for(int repeat = 0; repeat < msgSndCnt; repeat++) {
int cnt = 0;
Queue<String> sendQue = new LinkedList<String>();
String sender = "";
int sleepThread = 20000;
switch (msgId) {
case 3: // 단문자
if(!dbController.repeatSnd(msgId)&&repeat == 0)
break loop;
sendQue = smsController.getSendSms(process, repeat);
sender = "Sms";
sleepThread = smsIntvl;
break;
case 4: // 이미지
if(!dbController.repeatSnd(msgId)&&repeat == 0)
break loop;
sendQue = imgController.getSendImg(process, repeat);
sender = "Image";
if(sendQue != null && sendQue.size() != 0) {
String[] data = sendQue.peek().split("\\|");
String[] headData = data[0].split(",");
String totalBlCnt = headData[6];
int totBlCnt = Integer.parseInt(totalBlCnt);
int subIntvl = (int)(Math.ceil((double)totBlCnt/(double)5)) * imgSubIntvl ;
int intvl = subIntvl + imgIntvl;
sleepThread = intvl;
}
break;
case 5: // 기상예보
if(!dbController.repeatSnd(msgId)&&repeat == 0)
break loop;
if(patchMode){
sendQue = weatherController.getSendWeatherPatch(process, repeat);
}else{
sendQue = weatherController.getSendWeather(process, repeat);
}
sender = "Weather";
sleepThread = wetherIntvl;
break;
case 6: // 태풍정보
if(!dbController.repeatSnd(msgId)&&repeat == 0)
break loop;
sendQue = typhnController.getSendTyphn(process, repeat);
sender = "Typhoon";
sleepThread = typhnIntvl;
break;
case 11: // 수동위치요청
if(!dbController.repeatSnd(msgId)&&repeat == 0)
break loop;
sendQue = passivlcController.getPassivlcRequst(process, repeat);
sender = "Passivlc Request";
sleepThread = passivlcIntvl;
break;
case 14: // 조난응답
sendQue = dsastController.getRspnsDsast(process, repeat);
sender = "Dsast Response";
sleepThread = dsastIntvl;
break;
case 16: // 개별호출, 영역호출
if(!dbController.repeatSnd(msgId)&&repeat == 0)
break loop;
sendQue = callController.getCallRequst(process, repeat);
sender = "Call Request";
sleepThread = callIntvl;
break;
case 18: // 기상특보
if(!dbController.repeatSnd(msgId)&&repeat == 0)
break loop;
sendQue = specialNewsController.getSpecialNews(process, repeat);
sender = "SpecialNews";
sleepThread = specialIntvl;
break;
case 30: // 채팅
if(!dbController.repeatSnd(msgId)&&repeat == 0)
break loop;
sendQue = chatController.getSendChat(process, repeat);
sender = "Chat";
sleepThread = chatIntvl;
break;
}
if (ConnectCheck()) {
int queueSize = sendQue.size();
boolean swich = true;
boolean swich2 = true;
if (queueSize != 0) {
for (int z = 0; z < queueSize; z++) {
if(sendQue.peek().substring(10,15).substring(2, 3).equals("0")) {
// 인천
}else if(sendQue.peek().substring(10,15).substring(2, 3).equals("1")) {
// 포항
if(swich) {
Thread.sleep(sleepThread);
swich = false;
}
}else if(sendQue.peek().substring(10,15).substring(2, 3).equals("2")) {
// 고흥
if(swich2) {
Thread.sleep(sleepThread);
swich2 = false;
}
}
MsgObjVO msg = new MsgObjVO();
GmtLogManager.getInstance().writeLevelLog(sendQue.peek(), LogLevelType.LOG_INFO, "SendPacket");
msg.setMsg(sendQue.poll().getBytes("EUC-KR"));
// 패킷 전송
sendClient(clientInfoList.get(0).getIp(), clientInfoList.get(0).getPort(), msg);
cnt++;
// 메시지간 10milliSec 텀
Thread.sleep(10);
}
GmtLogManager.getInstance().writeLevelLog(
"[MainController.send] - Send " + sender + " [ SUCCESS CNT : " + cnt + " ] ", LogLevelType.LOG_INFO, "SendPacket");
// 메세지 송신 횟수 == 현재 반복횟수가 동일 할 시 sleep 수정
if((msgSndCnt-1) == repeat) {
Thread.sleep(msgTerm);
}else {
Thread.sleep(sleepThread);
}
}
} else {
int queueSize = sendQue.size();
if (queueSize != 0) {
GmtLogManager.getInstance().writeLevelLog("[MainController.send " + sender + "(No clients connected)]", LogLevelType.LOG_INFO, "FailPacket");
for (int z = 0; z < queueSize; z++) {
GmtLogManager.getInstance().writeLevelLog(sendQue.poll(), LogLevelType.LOG_ERROR, "FailPacket");
cnt++;
}
GmtLogManager.getInstance().writeLevelLog(
"[MainController.send(No clients connected)] - Send " + sender + " Log [ FAIL CNT : " + cnt + " ] ", LogLevelType.LOG_ERROR, "FailPacket");
}
}
}
} catch (Exception e) {
GmtLogManager.getInstance().writeLevelLog("[MainController.send] " + e.getMessage(), LogLevelType.LOG_ERROR, "FailPacket");
e.printStackTrace();
}
}
// 실패 패킷 재전송
public void packetReSend(String packet) {
try {
if (ConnectCheck()) {
if (!packet.equals("")) {
MsgObjVO msg = new MsgObjVO();
msg.setMsg(packet.getBytes("EUC-KR"));
sendClient(clientInfoList.get(0).getIp(), clientInfoList.get(0).getPort(), msg);
}
} else {
if (!packet.equals("")) {
GmtLogManager.getInstance().writeLevelLog("[MainController.packetReSend(No clients connected)]" + packet, LogLevelType.LOG_INFO, "FailPacket");
}
}
} catch (Exception e) {
GmtLogManager.getInstance().writeLevelLog("[MainController.packetReSend] " + e.getMessage(), LogLevelType.LOG_ERROR, "FailPacket");
e.printStackTrace();
}
}
public boolean ConnectCheck() {
// 통합게이트웨이 8040포트에 붙었을경우에만 패킷 송신
String sendGwIp = conIp;
int sendGwPort = conPort;
boolean connectFlag = false;
for (int i = 0; i < clientInfoList.size(); i++) {
ClientInfoVO civo = clientInfoList.get(i);
MonitorInfoVO cimvo = civo.getMonitorInfo();
if (civo.getIp().equals(sendGwIp) && civo.getPort() == sendGwPort) {
connectFlag = cimvo.isConnected();
}
}
return connectFlag;
}
@Override
protected void serialDataIn(MsgObjVO vo) {
}
@Override
protected void serverDataIn(MsgObjVO vo) {
}
@Override
protected void clientDataIn(MsgObjVO vo) {
String msg = "";
try {
String checkMsg = new String(vo.getMsg());
String[] msgArray = checkMsg.split(",");
if(msgArray[1].equals("30") || msgArray[1].equals("32")) {
if (clientManager.getClientLineMode(vo.getRecvID())) {
msg = new String(vo.getMsg(), "EUC-KR");
logger.writeLevelLog("[MainController - clientDataIn] Receive Packet : " + msg, LogLevelType.LOG_INFO, "ReceivePacket");
} else {
msg = GmtUtils.byteArrayToHexString(vo.getMsg());
logger.writeLevelLog("[MainController - clientDataIn] Receive Packet : " + msg, LogLevelType.LOG_INFO, "ReceivePacket");
}
packetQ.add(msg);
}
} catch (UnsupportedEncodingException e) {
logger.writeLevelLog("[MainController - clientDataIn] : " + e.getMessage(), LogLevelType.LOG_ERROR, "AllLog");
}
}
@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 dataIn(int serverPort, String remoteHost, int remotePort, String msg) {
}
@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");
}
@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");
}
@Override
public void SSLClientAuthentication(int serverPort) {
}
};
return listener;
}
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);
}
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 void start() {
try {
super.start();
// Msg Send Start
sendRunning = true;
sendThread.start();
// Life Packet
hbRunning = true;
hbThread.start();
// 선박 수동위치 송신 스레드
checkLastLcRunning = true;
checkLastLcThread.start();
} catch (Exception e) {
logger.writeLevelLog("[MainController.start] " + GmtUtils.getStatckTrace(e), LogLevelType.LOG_ERROR, "AllLog");
System.exit(0);
}
}
public SystemInfoVO getSystemInfo() {
return systemInfo;
}
public void setSystemInfo(SystemInfoVO systemInfo) {
this.systemInfo = systemInfo;
}
public void sendResponse(MsgObjVO vo) {
broadcastAllServer(vo);
}
// 모니터링 상태 소스
@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;
}
}