package com.its.dsrc; import com.its.app.AppUtils; import com.its.app.utils.OS; import com.its.app.utils.SysUtils; import com.its.dsrc.config.ProcessConfig; import com.its.dsrc.process.DbmsDataProcess; import com.its.dsrc.service.MultimediaService; import com.its.dsrc.service.RseCtlrService; import com.its.dsrc.service.RseSectService; import com.its.dsrc.service.UnitSystService; import com.its.dsrc.ui.JTextAreaOutputStream; import com.its.dsrc.ui.MainUI; import com.its.dsrc.xnettcp.dsrc.DsrcTcpCommServerService; import com.its.dsrc.xnettcp.dsrc.process.TcpServerDataProcess; 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.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.ContextClosedEvent; import org.springframework.core.io.ClassPathResource; import org.springframework.scheduling.annotation.EnableAsync; import javax.swing.*; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.net.URL; @Slf4j @EnableAsync @Configuration @SpringBootApplication @ComponentScan(basePackages = {"com.its.dsrc.config", "com.its.dsrc.dao.mapper", "com.its"}) //java -jar app.jar --spring.config.location=classpath:/another-location.properties //java -jar app.jar --spring.config.location=config/*/ //java -jar app.jar --property="value" //java -Dproperty.name="value" -jar app.jar //export name=value //java -jar app.jar //JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=prod" //@PropertySource("classpath:foo.properties") //@PropertySource("classpath:bar.properties") //@PropertySources({ // @PropertySource("classpath:foo.properties"), // @PropertySource("classpath:bar.properties") //}) //public class DsrcCommServerApplication implements CommandLineRunner, ApplicationListener, InitializingBean, DisposableBean { public class DsrcCommServerApplication implements CommandLineRunner, ApplicationListener, InitializingBean, DisposableBean { private static String applicationName = "dsrc-comm-server"; public static void main(String[] args) { File file1 = new File("./conf/" + applicationName + ".pid"); if (file1.exists()) { System.out.println(System.getProperty("Program Already Running.....")); log.error("Program Already Running....."); } if (!OS.isWindows()) { ApplicationContext context = new SpringApplicationBuilder(DsrcCommServerApplication.class) //.web(WebApplicationType.NONE) .listeners(new ApplicationPidFileWriter("./conf/" + applicationName + ".pid")) .headless(false) .bannerMode(Banner.Mode.OFF) .run(args); } else { SpringApplication application = new SpringApplicationBuilder() .sources(DsrcCommServerApplication.class) .listeners(new ApplicationPidFileWriter("./conf/" + applicationName + ".pid")) .build(); application.setBannerMode(Banner.Mode.OFF); application.run(args); } } @Override public void run(String... args) throws Exception { ProcessConfig processConfig = (ProcessConfig) AppUtils.getBean(ProcessConfig.class); log.info(""); log.info(""); log.info("************************************************************************************"); log.info("** **"); log.info("** Intelligent Traffic System **"); log.info("** DSRC(ASN.1) Communication Server Program. **"); log.info("** **"); log.info("** [ver.1.0] **"); log.info("** {}", processConfig.getId()); log.info("** startup: {}", processConfig.getBootingDateTime()); log.info("************************************************************************************"); // init application DbmsDataProcess dbmsDataProcess = (DbmsDataProcess)AppUtils.getBean(DbmsDataProcess.class); dbmsDataProcess.run(); TcpServerDataProcess tcpServerDataProcess = (TcpServerDataProcess)AppUtils.getBean(TcpServerDataProcess.class); tcpServerDataProcess.run(); UnitSystService unitSystService = (UnitSystService)AppUtils.getBean(UnitSystService.class); unitSystService.loadMaster(); unitSystService.updateUnitSystStts(true); RseCtlrService ctlrService = (RseCtlrService)AppUtils.getBean(RseCtlrService.class); ctlrService.loadDb(); ctlrService.updateCtlrStts(true); RseSectService rseSectService = (RseSectService)AppUtils.getBean(RseSectService.class); rseSectService.loadMaster(); MultimediaService multimediaService = (MultimediaService)AppUtils.getBean(MultimediaService.class); multimediaService.loadMaster(); DsrcTcpCommServerService dsrcTcpCommServerService = (DsrcTcpCommServerService)AppUtils.getBean(DsrcTcpCommServerService.class); dsrcTcpCommServerService.run(); // UdpServerCenterComm udpServerCenterComm = (UdpServerCenterComm)AppUtils.getBean(UdpServerCenterComm.class); // udpServerCenterComm.run(); // schedule enable processConfig.setStartSchedule(true); if (!OS.isWindows()) { SwingUtilities.invokeLater(() -> { String sysTime = SysUtils.getSysTimeStr(); //JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("DSRC 통신 서버 - [" + sysTime + "]"); MainUI UI = new MainUI(frame); try { ClassPathResource file = new ClassPathResource("static/image/application.png"); URL imgURL = file.getURL(); frame.setIconImage(new ImageIcon(imgURL).getImage()); } catch (IOException e) { log.error("Not found application icon image"); } frame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); frame.setContentPane(UI.getRootPanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (JOptionPane.showConfirmDialog(UI.getRootPanel(), "시스템을 종료 하시겠습니까?", "시스템 종료", 0) == 0) { System.exit(0); } else { frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); } } }); frame.pack(); frame.setBounds(100, 100, 1000, 800); frame.setLocationRelativeTo(null); frame.setVisible(true); JTextArea logArea = UI.getTaLog(); logArea.setText(null); JTextAreaOutputStream out = new JTextAreaOutputStream(logArea); System.setOut(new PrintStream(out)); UI.LoadControllerInfo(); }); } } public void terminateApplication() { UnitSystService unitSystService = (UnitSystService) AppUtils.getBean(UnitSystService.class); unitSystService.updateUnitSystStts(false); RseCtlrService ctlrService = (RseCtlrService) AppUtils.getBean(RseCtlrService.class); ctlrService.updateCtlrStts(false); DsrcTcpCommServerService dsrcTcpCommServerService = (DsrcTcpCommServerService)AppUtils.getBean(DsrcTcpCommServerService.class); dsrcTcpCommServerService.stop(); // UdpServerCenterComm udpServerCenterComm = (UdpServerCenterComm)AppUtils.getBean(UdpServerCenterComm.class); // udpServerCenterComm.getNioEventLoopGroup().shutdownGracefully(); } @Override public void onApplicationEvent(ContextClosedEvent event) { log.error("Application Terminated: {}", event.getTimestamp()); terminateApplication(); } @Override public void afterPropertiesSet() throws Exception { } @Override public void destroy() throws Exception { } }