| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- package com.utic.incident.molit.server;
- import com.utic.incident.common.spring.SpringUtils;
- import com.utic.incident.molit.server.config.ApplicationConfig;
- import com.utic.incident.molit.server.controller.IncidentMolitController;
- import com.utic.incident.molit.server.service.ProcessStateService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.DisposableBean;
- import org.springframework.beans.factory.InitializingBean;
- import org.springframework.boot.Banner;
- import org.springframework.boot.CommandLineRunner;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.boot.builder.SpringApplicationBuilder;
- import org.springframework.boot.context.ApplicationPidFileWriter;
- import org.springframework.context.ApplicationListener;
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.context.event.ContextClosedEvent;
- import org.springframework.transaction.annotation.EnableTransactionManagement;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- @Slf4j
- @SpringBootApplication
- @EnableTransactionManagement
- @ComponentScan(basePackages = {"com.utic.incident.common.spring", "com.utic.incident.molit.server.config", "com.utic.incident.molit", "com.utic.incident.common.aspect"})
- public class IncidentMolitServerApplication implements CommandLineRunner, ApplicationListener<ContextClosedEvent>, InitializingBean, DisposableBean {
- private static boolean isTerminal = false;
- public static final String APPLICATION_NAME = "utic-dwdb-server";
- public static void main(String[] args) {
- SpringApplication application = new SpringApplicationBuilder()
- .sources(IncidentMolitServerApplication.class)
- .listeners(new ApplicationPidFileWriter("./conf/" + APPLICATION_NAME + ".pid"))
- .build();
- application.setBannerMode(Banner.Mode.OFF);
- application.run(args);
- }
- @Override
- public void run(String... args) throws Exception {
- SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- log.info("");
- log.info("");
- log.info("************************************************************************************");
- log.info("** **");
- log.info("** Urban Traffic Information Center **");
- log.info("** MOLIT Incident and Event Information Collection System **");
- log.info("** **");
- log.info("** [ver.1.0] **");
- log.info("** startup: {}", sdfDate.format(new Date()));
- log.info("************************************************************************************");
- ApplicationConfig applicationConfig = SpringUtils.getBean(ApplicationConfig.class);
- applicationConfig.setStartSchedule(false);
- // 프로세스 상태 저장
- ProcessStateService processStateService = SpringUtils.getBean(ProcessStateService.class);
- processStateService.processStart();
- IncidentMolitController incidentMolitController = SpringUtils.getBean(IncidentMolitController.class);
- incidentMolitController.run();
- applicationConfig.setStartSchedule(true);
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- log.error("on shutdown hook.");
- terminate();
- }));
- }
- public void terminate() {
- if (!isTerminal) {
- isTerminal = true;
- SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- log.error("************************************************************************************");
- log.error("** Application Terminated: {}", sdfDate.format(new Date()));
- try {
- ApplicationConfig applicationConfig = SpringUtils.getBean(ApplicationConfig.class);
- applicationConfig.setStartSchedule(false);
- ProcessStateService processStateService = SpringUtils.getBean(ProcessStateService.class);
- processStateService.processStop();
- } catch (Exception e) {
- log.error("** Application Terminated: {}", e.getMessage());
- }
- log.error("************************************************************************************");
- }
- }
- @Override
- public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
- log.error("{}", contextClosedEvent);
- terminate();
- }
- @Override
- public void destroy() throws Exception {
- log.error("Application destroy");
- }
- @Override
- public void afterPropertiesSet() throws Exception {
- log.info("Application afterPropertiesSet");
- }
- }
|