DsrcCommServerApplication.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package com.its.dsrc;
  2. import com.its.app.AppUtils;
  3. import com.its.app.utils.OS;
  4. import com.its.app.utils.SysUtils;
  5. import com.its.dsrc.config.ProcessConfig;
  6. import com.its.dsrc.process.DbmsDataProcess;
  7. import com.its.dsrc.service.MultimediaService;
  8. import com.its.dsrc.service.RseCtlrService;
  9. import com.its.dsrc.service.RseSectService;
  10. import com.its.dsrc.service.UnitSystService;
  11. import com.its.dsrc.ui.JTextAreaOutputStream;
  12. import com.its.dsrc.ui.MainUI;
  13. import com.its.dsrc.xnettcp.dsrc.DsrcTcpCommServerService;
  14. import com.its.dsrc.xnettcp.dsrc.process.TcpServerDataProcess;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.DisposableBean;
  17. import org.springframework.beans.factory.InitializingBean;
  18. import org.springframework.boot.Banner;
  19. import org.springframework.boot.CommandLineRunner;
  20. import org.springframework.boot.SpringApplication;
  21. import org.springframework.boot.autoconfigure.SpringBootApplication;
  22. import org.springframework.boot.builder.SpringApplicationBuilder;
  23. import org.springframework.boot.context.ApplicationPidFileWriter;
  24. import org.springframework.context.ApplicationContext;
  25. import org.springframework.context.ApplicationListener;
  26. import org.springframework.context.annotation.ComponentScan;
  27. import org.springframework.context.annotation.Configuration;
  28. import org.springframework.context.event.ContextClosedEvent;
  29. import org.springframework.core.io.ClassPathResource;
  30. import org.springframework.scheduling.annotation.EnableAsync;
  31. import javax.swing.*;
  32. import java.awt.*;
  33. import java.awt.event.WindowAdapter;
  34. import java.awt.event.WindowEvent;
  35. import java.io.File;
  36. import java.io.IOException;
  37. import java.io.PrintStream;
  38. import java.net.URL;
  39. @Slf4j
  40. @EnableAsync
  41. @Configuration
  42. @SpringBootApplication
  43. @ComponentScan(basePackages = {"com.its.dsrc.config", "com.its.dsrc.dao.mapper", "com.its"})
  44. //java -jar app.jar --spring.config.location=classpath:/another-location.properties
  45. //java -jar app.jar --spring.config.location=config/*/
  46. //java -jar app.jar --property="value"
  47. //java -Dproperty.name="value" -jar app.jar
  48. //export name=value
  49. //java -jar app.jar
  50. //JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=prod"
  51. //@PropertySource("classpath:foo.properties")
  52. //@PropertySource("classpath:bar.properties")
  53. //@PropertySources({
  54. // @PropertySource("classpath:foo.properties"),
  55. // @PropertySource("classpath:bar.properties")
  56. //})
  57. //public class DsrcCommServerApplication implements CommandLineRunner, ApplicationListener<ContextClosedEvent>, InitializingBean, DisposableBean {
  58. public class DsrcCommServerApplication implements CommandLineRunner, ApplicationListener<ContextClosedEvent>, InitializingBean, DisposableBean {
  59. private static String applicationName = "dsrc-comm-server";
  60. public static void main(String[] args) {
  61. File file1 = new File("./conf/" + applicationName + ".pid");
  62. if (file1.exists()) {
  63. System.out.println(System.getProperty("Program Already Running....."));
  64. log.error("Program Already Running.....");
  65. }
  66. if (!OS.isWindows()) {
  67. ApplicationContext context = new SpringApplicationBuilder(DsrcCommServerApplication.class)
  68. //.web(WebApplicationType.NONE)
  69. .listeners(new ApplicationPidFileWriter("./conf/" + applicationName + ".pid"))
  70. .headless(false)
  71. .bannerMode(Banner.Mode.OFF)
  72. .run(args);
  73. } else {
  74. SpringApplication application = new SpringApplicationBuilder()
  75. .sources(DsrcCommServerApplication.class)
  76. .listeners(new ApplicationPidFileWriter("./conf/" + applicationName + ".pid"))
  77. .build();
  78. application.setBannerMode(Banner.Mode.OFF);
  79. application.run(args);
  80. }
  81. }
  82. @Override
  83. public void run(String... args) throws Exception {
  84. ProcessConfig processConfig = (ProcessConfig) AppUtils.getBean(ProcessConfig.class);
  85. log.info("");
  86. log.info("");
  87. log.info("************************************************************************************");
  88. log.info("** **");
  89. log.info("** Intelligent Traffic System **");
  90. log.info("** DSRC(ASN.1) Communication Server Program. **");
  91. log.info("** **");
  92. log.info("** [ver.1.0] **");
  93. log.info("** {}", processConfig.getId());
  94. log.info("** startup: {}", processConfig.getBootingDateTime());
  95. log.info("************************************************************************************");
  96. // init application
  97. DbmsDataProcess dbmsDataProcess = (DbmsDataProcess)AppUtils.getBean(DbmsDataProcess.class);
  98. dbmsDataProcess.run();
  99. TcpServerDataProcess tcpServerDataProcess = (TcpServerDataProcess)AppUtils.getBean(TcpServerDataProcess.class);
  100. tcpServerDataProcess.run();
  101. UnitSystService unitSystService = (UnitSystService)AppUtils.getBean(UnitSystService.class);
  102. unitSystService.loadMaster();
  103. unitSystService.updateUnitSystStts(true);
  104. RseCtlrService ctlrService = (RseCtlrService)AppUtils.getBean(RseCtlrService.class);
  105. ctlrService.loadDb();
  106. ctlrService.updateCtlrStts(true);
  107. RseSectService rseSectService = (RseSectService)AppUtils.getBean(RseSectService.class);
  108. rseSectService.loadMaster();
  109. MultimediaService multimediaService = (MultimediaService)AppUtils.getBean(MultimediaService.class);
  110. multimediaService.loadMaster();
  111. DsrcTcpCommServerService dsrcTcpCommServerService = (DsrcTcpCommServerService)AppUtils.getBean(DsrcTcpCommServerService.class);
  112. dsrcTcpCommServerService.run();
  113. // UdpServerCenterComm udpServerCenterComm = (UdpServerCenterComm)AppUtils.getBean(UdpServerCenterComm.class);
  114. // udpServerCenterComm.run();
  115. // schedule enable
  116. processConfig.setStartSchedule(true);
  117. if (!OS.isWindows()) {
  118. SwingUtilities.invokeLater(() -> {
  119. String sysTime = SysUtils.getSysTimeStr();
  120. //JFrame.setDefaultLookAndFeelDecorated(true);
  121. JFrame frame = new JFrame("DSRC 통신 서버 - [" + sysTime + "]");
  122. MainUI UI = new MainUI(frame);
  123. try {
  124. ClassPathResource file = new ClassPathResource("static/image/application.png");
  125. URL imgURL = file.getURL();
  126. frame.setIconImage(new ImageIcon(imgURL).getImage());
  127. } catch (IOException e) {
  128. log.error("Not found application icon image");
  129. }
  130. frame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
  131. frame.setContentPane(UI.getRootPanel());
  132. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  133. frame.addWindowListener(new WindowAdapter() {
  134. @Override
  135. public void windowClosing(WindowEvent e) {
  136. if (JOptionPane.showConfirmDialog(UI.getRootPanel(), "시스템을 종료 하시겠습니까?", "시스템 종료", 0) == 0) {
  137. System.exit(0);
  138. } else {
  139. frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  140. }
  141. }
  142. });
  143. frame.pack();
  144. frame.setBounds(100, 100, 1000, 800);
  145. frame.setLocationRelativeTo(null);
  146. frame.setVisible(true);
  147. JTextArea logArea = UI.getTaLog();
  148. logArea.setText(null);
  149. JTextAreaOutputStream out = new JTextAreaOutputStream(logArea);
  150. System.setOut(new PrintStream(out));
  151. UI.LoadControllerInfo();
  152. });
  153. }
  154. }
  155. public void terminateApplication() {
  156. UnitSystService unitSystService = (UnitSystService) AppUtils.getBean(UnitSystService.class);
  157. unitSystService.updateUnitSystStts(false);
  158. RseCtlrService ctlrService = (RseCtlrService) AppUtils.getBean(RseCtlrService.class);
  159. ctlrService.updateCtlrStts(false);
  160. DsrcTcpCommServerService dsrcTcpCommServerService = (DsrcTcpCommServerService)AppUtils.getBean(DsrcTcpCommServerService.class);
  161. dsrcTcpCommServerService.stop();
  162. // UdpServerCenterComm udpServerCenterComm = (UdpServerCenterComm)AppUtils.getBean(UdpServerCenterComm.class);
  163. // udpServerCenterComm.getNioEventLoopGroup().shutdownGracefully();
  164. }
  165. @Override
  166. public void onApplicationEvent(ContextClosedEvent event) {
  167. log.error("Application Terminated: {}", event.getTimestamp());
  168. terminateApplication();
  169. }
  170. @Override
  171. public void afterPropertiesSet() throws Exception {
  172. }
  173. @Override
  174. public void destroy() throws Exception {
  175. }
  176. }