테이블 검증조건 수정, 클라이언트 종료조건, 로깅관련 수정

This commit is contained in:
dsjang 2024-09-12 09:27:55 +09:00
parent d157fbb5d6
commit c38fbfa1ff
14 changed files with 221 additions and 111 deletions

View File

@ -47,7 +47,7 @@ dependencies {
// https://mvnrepository.com/artifact/org.apache.commons/commons-configuration2 // https://mvnrepository.com/artifact/org.apache.commons/commons-configuration2
implementation 'org.apache.commons:commons-configuration2:2.10.1' implementation 'org.apache.commons:commons-configuration2:2.10.1'
// https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client // https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '3.4.1' implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '3.1.4'
// https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc11 // https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc11
implementation group: 'com.oracle.database.jdbc', name: 'ojdbc11', version: '23.5.0.24.07' implementation group: 'com.oracle.database.jdbc', name: 'ojdbc11', version: '23.5.0.24.07'
// https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc // https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc

View File

@ -1,5 +1,6 @@
package com.munjaon.client.config; package com.munjaon.client.config;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -39,14 +40,38 @@ public class DataSourceConfig {
System.out.println("MARIADB.URL : " + serverConfig.getString(dbms + ".URL")); System.out.println("MARIADB.URL : " + serverConfig.getString(dbms + ".URL"));
System.out.println("MARIADB.USER : " + serverConfig.getString(dbms + ".USER")); System.out.println("MARIADB.USER : " + serverConfig.getString(dbms + ".USER"));
System.out.println("MARIADB.PASSWORD : " + serverConfig.getString(dbms + ".PASSWORD")); System.out.println("MARIADB.PASSWORD : " + serverConfig.getString(dbms + ".PASSWORD"));
return DataSourceBuilder.create().type(HikariDataSource.class)
.driverClassName(serverConfig.getString(dbms + ".DRIVER")) HikariConfig hikariConfig = new HikariConfig();
.url(serverConfig.getString(dbms + ".URL")) hikariConfig.setDriverClassName(serverConfig.getString(dbms + ".DRIVER"));
.username(serverConfig.getString(dbms + ".USER")) hikariConfig.setJdbcUrl(serverConfig.getString(dbms + ".URL"));
.password(serverConfig.getString(dbms + ".PASSWORD")) hikariConfig.setUsername(serverConfig.getString(dbms + ".USER"));
.build(); hikariConfig.setPassword(serverConfig.getString(dbms + ".PASSWORD"));
hikariConfig.setMaximumPoolSize(10);
if ("ORACLE".equalsIgnoreCase(dbms) || "TIBERO".equalsIgnoreCase(dbms)) {
hikariConfig.setConnectionTestQuery("SELECT 1 FROM DUAL");
} else {
hikariConfig.setConnectionTestQuery("SELECT 1");
}
return new HikariDataSource(hikariConfig);
} }
// @Primary
// @Bean(name = "datasource")
// public DataSource dataSource() throws ConfigurationException {
// String dbms = serverConfig.getString("DB.DBMS");
// System.out.println("MARIADB.DRIVER : " + serverConfig.getString(dbms + ".DRIVER"));
// System.out.println("MARIADB.URL : " + serverConfig.getString(dbms + ".URL"));
// System.out.println("MARIADB.USER : " + serverConfig.getString(dbms + ".USER"));
// System.out.println("MARIADB.PASSWORD : " + serverConfig.getString(dbms + ".PASSWORD"));
// return DataSourceBuilder.create().type(HikariDataSource.class)
// .driverClassName(serverConfig.getString(dbms + ".DRIVER"))
// .url(serverConfig.getString(dbms + ".URL"))
// .username(serverConfig.getString(dbms + ".USER"))
// .password(serverConfig.getString(dbms + ".PASSWORD"))
// .build();
// }
@Primary @Primary
@Bean(name = "factory") @Bean(name = "factory")
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {

View File

@ -20,7 +20,7 @@ public class CubridService {
try { try {
int msgCount = deliverBMapper.checkTableForMessage(); int msgCount = deliverBMapper.checkTableForMessage();
int logCount = deliverBMapper.checkTableForLog(); int logCount = deliverBMapper.checkTableForLog();
if (msgCount >= 0 && logCount >= 0) { if (msgCount > 0 && logCount > 0) {
isExist = true; isExist = true;
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -20,7 +20,7 @@ public class MariaDBService {
try { try {
int msgCount = deliverBMapper.checkTableForMessage(); int msgCount = deliverBMapper.checkTableForMessage();
int logCount = deliverBMapper.checkTableForLog(); int logCount = deliverBMapper.checkTableForLog();
if (msgCount >= 0 && logCount >= 0) { if (msgCount > 0 && logCount > 0) {
isExist = true; isExist = true;
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -20,7 +20,7 @@ public class MssqlService {
try { try {
int msgCount = deliverBMapper.checkTableForMessage(); int msgCount = deliverBMapper.checkTableForMessage();
int logCount = deliverBMapper.checkTableForLog(); int logCount = deliverBMapper.checkTableForLog();
if (msgCount >= 0 && logCount >= 0) { if (msgCount > 0 && logCount > 0) {
isExist = true; isExist = true;
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -20,7 +20,7 @@ public class MysqlService {
try { try {
int msgCount = deliverBMapper.checkTableForMessage(); int msgCount = deliverBMapper.checkTableForMessage();
int logCount = deliverBMapper.checkTableForLog(); int logCount = deliverBMapper.checkTableForLog();
if (msgCount >= 0 && logCount >= 0) { if (msgCount > 0 && logCount > 0) {
isExist = true; isExist = true;
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -20,7 +20,7 @@ public class OracleService {
try { try {
int msgCount = deliverBMapper.checkTableForMessage(); int msgCount = deliverBMapper.checkTableForMessage();
int logCount = deliverBMapper.checkTableForLog(); int logCount = deliverBMapper.checkTableForLog();
if (msgCount >= 0 && logCount >= 0) { if (msgCount > 0 && logCount > 0) {
isExist = true; isExist = true;
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -20,7 +20,7 @@ public class PostgresqlService {
try { try {
int msgCount = deliverBMapper.checkTableForMessage(); int msgCount = deliverBMapper.checkTableForMessage();
int logCount = deliverBMapper.checkTableForLog(); int logCount = deliverBMapper.checkTableForLog();
if (msgCount >= 0 && logCount >= 0) { if (msgCount > 0 && logCount > 0) {
isExist = true; isExist = true;
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -5,6 +5,10 @@ import java.nio.ByteBuffer;
public final class Packet { public final class Packet {
public static final byte SET_DEFAULT_BYTE = (byte) 0x00; public static final byte SET_DEFAULT_BYTE = (byte) 0x00;
public static final long LINK_CHECK_CYCLE = 10000L; public static final long LINK_CHECK_CYCLE = 10000L;
/* 패킷 만료 시간 체크 */
public static final long LIMIT_PACKET_TIMEOUT = 25000L;
/* 패킷을 보내고 수신시까지 타임아웃 체크시간 */
public static final long LIMIT_PACKET_SEND_TIMEOUT = 30000L;
// public static final long LINK_CHECK_CYCLE = 30000L; // public static final long LINK_CHECK_CYCLE = 30000L;
public static void setDefaultByte(ByteBuffer buffer) { public static void setDefaultByte(ByteBuffer buffer) {

View File

@ -80,12 +80,19 @@ public class CollectClientService extends Service {
} }
} }
private boolean checkTimeOut() {
return System.currentTimeMillis() - lastPacketSendTime >= Packet.LIMIT_PACKET_TIMEOUT;
}
@Override @Override
public void doService() { public void doService() {
bind(); bind();
while (isRun()) { while (isRun()) {
try { try {
// saveSystemLog("Root Path : " + System.getProperty("ROOTPATH")); if (checkTimeOut()) {
saveSystemLog("[checkTimeOut : Expired ... ... ... ... ... ... ...]");
break;
};
messageService(); messageService();
linkCheckService(); linkCheckService();
} catch (Exception e) { } catch (Exception e) {
@ -103,7 +110,12 @@ public class CollectClientService extends Service {
try { try {
saveSystemLog("[BIND REQUEST] [IP : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]"); saveSystemLog("[BIND REQUEST] [IP : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
socketChannel.write(sendBuffer); socketChannel.write(sendBuffer);
long BIND_SEND_TIME = System.currentTimeMillis();
while (true) { while (true) {
if (System.currentTimeMillis() - BIND_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
saveSystemLog("[bindTimeOut : Expired ... ... ... ... ... ... ...]");
throw new RuntimeException("bindTimeOut : Expired ... ... ... ... ... ... ...");
}
int recvCount = socketChannel.read(recvBuffer); int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) { if (recvCount == -1) {
saveSystemLog("[BIND ERROR] [CONNECTION CLOSED]"); saveSystemLog("[BIND ERROR] [CONNECTION CLOSED]");
@ -172,17 +184,24 @@ public class CollectClientService extends Service {
return; return;
} }
for (MunjaonMsg data : list) { try {
switch (this.serviceType) { for (MunjaonMsg data : list) {
case "SMS": smsMessageService(data); break; switch (this.serviceType) {
case "LMS": lmsMessageService(data); break; case "SMS": smsMessageService(data); break;
case "MMS": mmsMessageService(data); break; case "LMS": lmsMessageService(data); break;
case "KAT": katMessageService(data); break; case "MMS": mmsMessageService(data); break;
case "KFT": kftMessageService(data); break; case "KAT": katMessageService(data); break;
default:break; case "KFT": kftMessageService(data); break;
default:break;
}
} }
} catch (Exception e) {
saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
} }
if (this.deliverList != null && this.deliverList.size() > 0) {
if (this.deliverList != null && !this.deliverList.isEmpty()) {
worker.updateDeliverForList(this.deliverList); worker.updateDeliverForList(this.deliverList);
this.deliverList = null; // NULL로 초기화 this.deliverList = null; // NULL로 초기화
} }
@ -218,7 +237,12 @@ public class CollectClientService extends Service {
saveSystemLog("[MESSAGE SEND] [... ...]"); saveSystemLog("[MESSAGE SEND] [... ...]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]"); saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
socketChannel.write(sendBuffer); socketChannel.write(sendBuffer);
long MSG_SEND_TIME = System.currentTimeMillis();
while (true) { while (true) {
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
saveSystemLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
}
int recvCount = socketChannel.read(recvBuffer); int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) { if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]"); saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
@ -232,8 +256,10 @@ public class CollectClientService extends Service {
} }
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); saveSystemLog("ERROR [" + e.getMessage() + "]");
// throw new RuntimeException(e); saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e);
} }
} }
@ -267,27 +293,44 @@ public class CollectClientService extends Service {
saveSystemLog("[MESSAGE SEND] [... ...]"); saveSystemLog("[MESSAGE SEND] [... ...]");
saveSystemLog("[MESSAGE DATA : " + data.toString() + "]"); saveSystemLog("[MESSAGE DATA : " + data.toString() + "]");
socketChannel.write(sendBuffer); socketChannel.write(sendBuffer);
long MSG_SEND_TIME = System.currentTimeMillis();
while (true) { while (true) {
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
saveSystemLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
}
int recvCount = socketChannel.read(recvBuffer); int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) { if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]"); saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("DELIVER ERROR"); throw new RuntimeException("DELIVER ERROR");
} else if (recvCount > 0) { } else if (recvCount > 0) {
worker.updateToDeliver(data.getMsgId()); setDeliverMsgId(data.getMsgId());
// worker.updateToDeliver(data.getMsgId());
saveSystemLog("[MESSAGE SEND] [SUCCESS]"); saveSystemLog("[MESSAGE SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis(); lastPacketSendTime = System.currentTimeMillis();
break; break;
} }
} }
} catch (IOException e) { } catch (IOException e) {
saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private void mmsMessageService(MunjaonMsg data) { private void mmsMessageService(MunjaonMsg data) {
try { try {
/* 이미지 경로 디폴트 경로 사용 여부 */
String defaultYn = getProp("MMS", "DEFAULT_PATH_YN");
/* MMS Image 저장 경로 */ /* MMS Image 저장 경로 */
String path = System.getProperty("ROOTPATH") + File.separator + "mmsfile" + File.separator; String path = null;
if ("Y".equals(defaultYn)) {
path = System.getProperty("ROOTPATH") + File.separator + "mmsfile" + File.separator;
} else {
path = getProp("MMS", "FILEPATH") + File.separator;
}
/* 공통 메시지 유효성 체크 */ /* 공통 메시지 유효성 체크 */
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data); int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
int checkMsgCode = MessageCheckUtil.validateMessageForMedia(data); int checkMsgCode = MessageCheckUtil.validateMessageForMedia(data);
@ -363,29 +406,43 @@ public class CollectClientService extends Service {
} }
socketChannel.write(byteBuffers); socketChannel.write(byteBuffers);
long MSG_SEND_TIME = System.currentTimeMillis();
while (true) { while (true) {
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
saveSystemLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
}
int recvCount = socketChannel.read(recvBuffer); int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) { if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]"); saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("DELIVER ERROR"); throw new RuntimeException("DELIVER ERROR");
} else if (recvCount > 0) { } else if (recvCount > 0) {
worker.updateToDeliver(data.getMsgId()); setDeliverMsgId(data.getMsgId());
// worker.updateToDeliver(data.getMsgId());
saveSystemLog("[MESSAGE SEND] [SUCCESS]"); saveSystemLog("[MESSAGE SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis(); lastPacketSendTime = System.currentTimeMillis();
break; break;
} }
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private void katMessageService(MunjaonMsg data) { private void katMessageService(MunjaonMsg data) {
try { try {
/* 이미지 경로 디폴트 경로 사용 여부 */
String defaultYn = getProp("KAKAO", "DEFAULT_PATH_YN");
/* Kakao Json 저장 경로 */ /* Kakao Json 저장 경로 */
String path = System.getProperty("ROOTPATH") + File.separator + "kakaofile" + File.separator; String path = null;
if ("Y".equals(defaultYn)) {
path = System.getProperty("ROOTPATH") + File.separator + "kakaofile" + File.separator;
} else {
path = getProp("KAKAO", "FILEPATH") + File.separator;
}
/* 공통 메시지 유효성 체크 */ /* 공통 메시지 유효성 체크 */
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data); int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
int checkMsgCode = MessageCheckUtil.validateMessageForKakao(data); int checkMsgCode = MessageCheckUtil.validateMessageForKakao(data);
@ -426,29 +483,43 @@ public class CollectClientService extends Service {
byteBuffers[1] = fileBuffer; byteBuffers[1] = fileBuffer;
socketChannel.write(byteBuffers); socketChannel.write(byteBuffers);
long MSG_SEND_TIME = System.currentTimeMillis();
while (true) { while (true) {
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
saveSystemLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
}
int recvCount = socketChannel.read(recvBuffer); int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) { if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]"); saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("DELIVER ERROR"); throw new RuntimeException("DELIVER ERROR");
} else if (recvCount > 0) { } else if (recvCount > 0) {
worker.updateToDeliver(data.getMsgId()); setDeliverMsgId(data.getMsgId());
// worker.updateToDeliver(data.getMsgId());
saveSystemLog("[MESSAGE SEND] [SUCCESS]"); saveSystemLog("[MESSAGE SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis(); lastPacketSendTime = System.currentTimeMillis();
break; break;
} }
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private void kftMessageService(MunjaonMsg data) { private void kftMessageService(MunjaonMsg data) {
try { try {
/* 이미지 경로 디폴트 경로 사용 여부 */
String defaultYn = getProp("KAKAO", "DEFAULT_PATH_YN");
/* Kakao Json 저장 경로 */ /* Kakao Json 저장 경로 */
String path = System.getProperty("ROOTPATH") + File.separator + "kakaofile" + File.separator; String path = null;
if ("Y".equals(defaultYn)) {
path = System.getProperty("ROOTPATH") + File.separator + "kakaofile" + File.separator;
} else {
path = getProp("KAKAO", "FILEPATH") + File.separator;
}
/* 공통 메시지 유효성 체크 */ /* 공통 메시지 유효성 체크 */
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data); int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
int checkMsgCode = MessageCheckUtil.validateMessageForKakao(data); int checkMsgCode = MessageCheckUtil.validateMessageForKakao(data);
@ -488,21 +559,28 @@ public class CollectClientService extends Service {
byteBuffers[1] = fileBuffer; byteBuffers[1] = fileBuffer;
socketChannel.write(byteBuffers); socketChannel.write(byteBuffers);
long MSG_SEND_TIME = System.currentTimeMillis();
while (true) { while (true) {
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
saveSystemLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
}
int recvCount = socketChannel.read(recvBuffer); int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) { if (recvCount == -1) {
saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]"); saveSystemLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
throw new RuntimeException("DELIVER ERROR"); throw new RuntimeException("DELIVER ERROR");
} else if (recvCount > 0) { } else if (recvCount > 0) {
worker.updateToDeliver(data.getMsgId()); setDeliverMsgId(data.getMsgId());
// worker.updateToDeliver(data.getMsgId());
saveSystemLog("[MESSAGE SEND] [SUCCESS]"); saveSystemLog("[MESSAGE SEND] [SUCCESS]");
lastPacketSendTime = System.currentTimeMillis(); lastPacketSendTime = System.currentTimeMillis();
break; break;
} }
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -517,7 +595,12 @@ public class CollectClientService extends Service {
try { try {
saveSystemLog("[LINK_CHECK SEND] [... ...]"); saveSystemLog("[LINK_CHECK SEND] [... ...]");
socketChannel.write(LinkCheck.makeLinkCheckBuffer()); socketChannel.write(LinkCheck.makeLinkCheckBuffer());
long LINK_SEND_TIME = System.currentTimeMillis();
while (true) { while (true) {
if (System.currentTimeMillis() - LINK_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
saveSystemLog("[LinkcheckTimeOut : Expired ... ... ... ... ... ... ...]");
throw new RuntimeException("LinkcheckTimeOut : Expired ... ... ... ... ... ... ...");
}
int recvCount = socketChannel.read(recvBuffer); int recvCount = socketChannel.read(recvBuffer);
if (recvCount == -1) { if (recvCount == -1) {
saveSystemLog("[LINK_CHECK SEND] [FAIL] [SOCKET IS CLOSED]"); saveSystemLog("[LINK_CHECK SEND] [FAIL] [SOCKET IS CLOSED]");
@ -529,6 +612,9 @@ public class CollectClientService extends Service {
} }
} }
} catch (Exception e) { } catch (Exception e) {
saveSystemLog("ERROR [" + e.getMessage() + "]");
saveSystemLog("ERROR DETAIL");
saveSystemLog(e.toString());
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

View File

@ -78,11 +78,19 @@ public class ReportClientService extends Service {
} }
} }
private boolean checkTimeOut() {
return System.currentTimeMillis() - lastPacketSendTime >= Packet.LIMIT_PACKET_TIMEOUT;
}
@Override @Override
public void doService() { public void doService() {
bind(); bind();
while (isRun()) { while (isRun()) {
try { try {
if (checkTimeOut()) {
saveSystemLog("[checkTimeOut : Expired ... ... ... ... ... ... ...]");
break;
};
messageService(); messageService();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -94,8 +102,9 @@ public class ReportClientService extends Service {
ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd); ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH); ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
try { try {
saveSystemLog("sendBuffer " + sendBuffer.position() + ":" + sendBuffer.limit()); // saveSystemLog("sendBuffer " + sendBuffer.position() + ":" + sendBuffer.limit());
saveSystemLog("Bind Try Connect to " + this.address + ":" + this.port); saveSystemLog("Bind Try Connect to " + this.address + ":" + this.port);
Thread.sleep(300);
socketChannel.write(sendBuffer); socketChannel.write(sendBuffer);
saveSystemLog("Bind Read to " + this.address + ":" + this.port); saveSystemLog("Bind Read to " + this.address + ":" + this.port);
while (true) { while (true) {
@ -173,6 +182,7 @@ public class ReportClientService extends Service {
saveSystemLog("Report : " + data.toString()); saveSystemLog("Report : " + data.toString());
worker.updateToReport(data); worker.updateToReport(data);
socketChannel.write(Report.makeReportAckBuffer()); socketChannel.write(Report.makeReportAckBuffer());
lastPacketSendTime = System.currentTimeMillis();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -184,6 +194,7 @@ public class ReportClientService extends Service {
try { try {
saveSystemLog("LinkCheck Received"); saveSystemLog("LinkCheck Received");
socketChannel.write(LinkCheck.makeLinkCheckAckBuffer()); socketChannel.write(LinkCheck.makeLinkCheckAckBuffer());
lastPacketSendTime = System.currentTimeMillis();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -131,6 +131,8 @@ public abstract class Service extends Thread {
} }
} finally { } finally {
if(logger != null) { logger.close(); logger = null; } if(logger != null) { logger.close(); logger = null; }
/* Exception 발생 대비 자원 해제 */
releaseResources();
} }
} }
} }

View File

@ -4,6 +4,10 @@ spring:
profiles: profiles:
default: local default: local
logging:
level:
root: info
agent: agent:
root-path: ${SERVICE_HOME} root-path: ${SERVICE_HOME}
server-property-file: ${SERVICE_HOME}/config/munjaonAgent.conf server-property-file: ${SERVICE_HOME}/config/munjaonAgent.conf

View File

@ -1,80 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<timestamp key="BY_DATE" datePattern="yyyy-MM-dd"/> <property name="CONSOLE_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %magenta([%thread]) %highlight([%-3level]) %logger{5} - %msg %n" />
<property name="LOG_PATTERN" <property name="ROLLING_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %logger{5} - %msg %n" />
value="[%d{yyyy-MM-dd HH:mm:ss}:%-4relative] %green([%thread]) %highlight(%-5level) %boldWhite([%C.%M:%yellow(%L)]) - %msg%n%ex"/> <property name="FILE_NAME" value="../logs/agent/munjaonClient.log" />
<property name="LOG_NAME_PATTERN" value="../logs/agent/backup/munjaonClient-%d{yyyy-MM-dd-HH-mm}.%i.log" />
<property name="MAX_FILE_SIZE" value="100MB" />
<property name="TOTAL_SIZE" value="3GB" />
<property name="MAX_HISTORY" value="30" />
<springProfile name="local">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<logger name="com.munjaon.client" level="DEBUG" />
<root level="ERROR">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<springProfile name="prod|dev"> <!-- Console appender 설정 -->
<appender name="FILE-INFO" class="ch.qos.logback.core.rolling.RollingFileAppender"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<file>./log/info/info-${BY_DATE}.log</file> <encoder>
<filter class = "ch.qos.logback.classic.filter.LevelFilter"> <Pattern>${CONSOLE_PATTERN}</Pattern>
<level>INFO</level> </encoder>
<onMatch>ACCEPT</onMatch> </appender>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern> ./backup/info/info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="FILE-WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./log/warn/warn-${BY_DATE}.log</file>
<filter class = "ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern> ./backup/warn/warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="FILE-ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"> <appender name="ROLLING_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./log/error/error-${BY_DATE}.log</file> <encoder>
<filter class = "ch.qos.logback.classic.filter.LevelFilter"> <pattern>${ROLLING_PATTERN}</pattern>
<level>ERROR</level> </encoder>
<onMatch>ACCEPT</onMatch> <file>${FILE_NAME}</file>
<onMismatch>DENY</onMismatch> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
</filter> <fileNamePattern>${LOG_NAME_PATTERN}</fileNamePattern>
<encoder> <maxHistory>${MAX_HISTORY}</maxHistory>
<pattern>${LOG_PATTERN}</pattern> <maxFileSize>${MAX_FILE_SIZE}</maxFileSize>
</encoder> <totalSizeCap>${TOTAL_SIZE}</totalSizeCap>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> </rollingPolicy>
<fileNamePattern> ./backup/error/error-%d{yyyy-MM-dd}.%i.log</fileNamePattern> </appender>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
</appender>
<root level="INFO"> <logger name="jdbc" level="OFF" additive="false">
<appender-ref ref="FILE-INFO"/> <appender-ref ref="STDOUT"/>
<appender-ref ref="FILE-WARN"/> <appender-ref ref="ROLLING_LOG_FILE"/>
<appender-ref ref="FILE-ERROR"/> </logger>
</root> <logger name="jdbc.sqlonly" level="DEBUG" additive="false" >
</springProfile> <appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLING_LOG_FILE"/>
</logger>
<logger name="jdbc.sqltiming" level="OFF" additive="false" >
<appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLING_LOG_FILE"/>
</logger>
<logger name="org.hibernate.SQL" level="DEBUG" additive="false">
<appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLING_LOG_FILE"/>
</logger>
<logger name="com.munjaon.client" level="INFO" additive="true" >
<appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLING_LOG_FILE"/>
</logger>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLING_LOG_FILE"/>
</root>
</configuration> </configuration>