|
|
@@ -1,5 +1,6 @@
|
|
|
package com.tsi.comm.server;
|
|
|
|
|
|
+import com.tsi.comm.server.config.ApplicationConfig;
|
|
|
import com.tsi.comm.server.config.TsiCvimServerConfig;
|
|
|
import com.tsi.comm.server.kafka.KafkaConsumerService;
|
|
|
import com.tsi.comm.server.kafka.KafkaProducerService;
|
|
|
@@ -14,6 +15,7 @@ import com.tsi.comm.server.repository.TsiSessionManager;
|
|
|
import com.tsi.comm.server.tcp.TsiCvimServer;
|
|
|
import com.tsi.comm.server.vo.TsiAlarmConfigVo;
|
|
|
import com.tsi.common.spring.SpringUtils;
|
|
|
+import com.tsi.common.utils.ApplicationUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
|
@@ -28,6 +30,9 @@ import org.springframework.context.annotation.ComponentScan;
|
|
|
import org.springframework.context.event.ContextClosedEvent;
|
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
|
|
|
@@ -65,6 +70,9 @@ public class TsiCommServerApplication implements CommandLineRunner, ApplicationL
|
|
|
log.info("** startup: {}", sdfDate.format(new Date()));
|
|
|
log.info("************************************************************************************");
|
|
|
|
|
|
+ ApplicationConfig applicationConfig = SpringUtils.getBean(ApplicationConfig.class);
|
|
|
+ applicationConfig.setStartSchedule(false);
|
|
|
+
|
|
|
TsiCvimServerConfig config = SpringUtils.getBean(TsiCvimServerConfig.class);
|
|
|
|
|
|
applicationName = APPLICATION_NAME + "-" + config.getServerId();
|
|
|
@@ -109,70 +117,96 @@ public class TsiCommServerApplication implements CommandLineRunner, ApplicationL
|
|
|
catch(Exception e) {
|
|
|
// no logging
|
|
|
}
|
|
|
+
|
|
|
+ applicationConfig.setStartSchedule(true);
|
|
|
+
|
|
|
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
+ log.error("on shutdown hook.");
|
|
|
+ applicationConfig.setStartSchedule(false);
|
|
|
+ terminate();
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
|
|
|
+ public void terminate() {
|
|
|
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
+ log.error("************************************************************************************");
|
|
|
+ log.error("** Application Terminated: {}", sdfDate.format(new Date()));
|
|
|
int serverId = 0;
|
|
|
try {
|
|
|
TsiCvimServerConfig config = SpringUtils.getBean(TsiCvimServerConfig.class);
|
|
|
+ if (config != null) {
|
|
|
config.setStartup(false);
|
|
|
serverId = config.getServerId();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
- // no logging
|
|
|
+ log.error("** Application.terminate:config: {}", e.getMessage());
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
TsiSessionManager sessionManager = SpringUtils.getBean(TsiSessionManager.class);
|
|
|
- sessionManager.stop();
|
|
|
+ if (sessionManager != null) {
|
|
|
+ sessionManager.stop();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
- // no logging
|
|
|
+ log.error("** Application.terminate:sessionManager: {}", e.getMessage());
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
TsiCvimServer cvimServer = SpringUtils.getBean(TsiCvimServer.class);
|
|
|
- cvimServer.stop();
|
|
|
+ if (cvimServer != null) {
|
|
|
+ cvimServer.stop();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
- // no logging
|
|
|
+ log.error("** Application.terminate:cvimServer: {}", e.getMessage());
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
KafkaProducerService kafkaProducerService = SpringUtils.getBean(KafkaProducerService.class);
|
|
|
- kafkaProducerService.shutdown();
|
|
|
+ if (kafkaProducerService != null) {
|
|
|
+ kafkaProducerService.shutdown();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
- // no logging
|
|
|
+ log.error("** Application.terminate:kafkaProducerService: {}", e.getMessage());
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
KafkaConsumerService kafkaConsumerService = SpringUtils.getBean(KafkaConsumerService.class);
|
|
|
- kafkaConsumerService.shutdown();
|
|
|
+ if (kafkaConsumerService != null) {
|
|
|
+ kafkaConsumerService.shutdown();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
- // no logging
|
|
|
+ log.error("** Application.terminate:kafkaConsumerService: {}", e.getMessage());
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
TsiCommServerService tsiCommServerService = SpringUtils.getBean(TsiCommServerService.class);
|
|
|
// 노드 통신상태 Off 초기화
|
|
|
- tsiCommServerService.updateNodeStatusTerm(serverId);
|
|
|
-
|
|
|
- // 시스템 종료 알람 이력 저장
|
|
|
- AlarmOccrVo alarm = new AlarmOccrVo(AbstractDbmsVo.DBMS_ALARM_OCCR_HS);
|
|
|
- alarm.setAlarmCode(TsiAlarmConfigVo.SYS_00);
|
|
|
- alarm.setAlarmTarget(applicationName);
|
|
|
- alarm.setAlarmValue("Terminated");
|
|
|
- tsiCommServerService.insertAlarmOccrHs(alarm);
|
|
|
- tsiCommServerService.updateProcessState(2);
|
|
|
+ if (tsiCommServerService != null) {
|
|
|
+ tsiCommServerService.updateNodeStatusTerm(serverId);
|
|
|
+ // 시스템 종료 알람 이력 저장
|
|
|
+ AlarmOccrVo alarm = new AlarmOccrVo(AbstractDbmsVo.DBMS_ALARM_OCCR_HS);
|
|
|
+ alarm.setAlarmCode(TsiAlarmConfigVo.SYS_00);
|
|
|
+ alarm.setAlarmTarget(applicationName);
|
|
|
+ alarm.setAlarmValue("Terminated");
|
|
|
+ tsiCommServerService.insertAlarmOccrHs(alarm);
|
|
|
+ tsiCommServerService.updateProcessState(2);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
- // no logging
|
|
|
+ log.error("** Application.terminate:updateProcessState: {}", e.getMessage());
|
|
|
}
|
|
|
+ log.error("************************************************************************************");
|
|
|
+ }
|
|
|
|
|
|
- log.error("Application Terminated: {}, {}", sdfDate.format(new Date()), contextClosedEvent.toString());
|
|
|
+ @Override
|
|
|
+ public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
|
|
|
+ log.error("{}", contextClosedEvent);
|
|
|
+ terminate();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void destroy() throws Exception {
|
|
|
+ log.error("Application destroy.");
|
|
|
}
|
|
|
|
|
|
@Override
|