ItsOpServerApplication.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package com.its.op;
  2. import com.its.op.config.*;
  3. import com.its.op.entity.its.unit.TbUnitSyst;
  4. import com.its.op.global.TbUnitSystManager;
  5. import com.its.op.scheduler.job.DbmsSttsJobThread;
  6. import com.its.op.xnetudp.CenterCommUdpServer;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.DisposableBean;
  9. import org.springframework.beans.factory.InitializingBean;
  10. import org.springframework.boot.Banner;
  11. import org.springframework.boot.CommandLineRunner;
  12. import org.springframework.boot.SpringApplication;
  13. import org.springframework.boot.autoconfigure.SpringBootApplication;
  14. import org.springframework.boot.builder.SpringApplicationBuilder;
  15. import org.springframework.boot.context.ApplicationPidFileWriter;
  16. import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
  17. import org.springframework.context.ApplicationListener;
  18. import org.springframework.context.annotation.Configuration;
  19. import org.springframework.context.annotation.EnableAspectJAutoProxy;
  20. import org.springframework.context.event.ContextClosedEvent;
  21. import org.springframework.scheduling.annotation.EnableAsync;
  22. import org.springframework.web.bind.annotation.CrossOrigin;
  23. import java.text.SimpleDateFormat;
  24. import java.util.Date;
  25. @Slf4j
  26. //@EnableJpaAuditing // JPA Auditing 활성화
  27. @EnableAspectJAutoProxy
  28. @EnableAsync
  29. @Configuration
  30. @SpringBootApplication
  31. /*@ComponentScan(basePackages = {
  32. "com.its.op.config",
  33. "com.its.op.dao.repository.its",
  34. "com.its.op.dao.repository.bis",
  35. "com.its.op.dao.repository.utis",
  36. "com.its.op.controller.*"
  37. })*/
  38. //@ComponentScan("com.its")
  39. //@MapperScan({"com.its.op.dao.mapper.its", "com.its.op.dao.mapper.bis", "com.its.op.dao.mapper.utis"})
  40. @CrossOrigin("*")
  41. public class ItsOpServerApplication extends SpringBootServletInitializer implements CommandLineRunner, ApplicationListener<ContextClosedEvent>, InitializingBean, DisposableBean {
  42. private static final String applicationName = "its-op-server";
  43. //@Autowired
  44. public ItsOpServerApplication() {
  45. super();
  46. setRegisterErrorPageFilter(false);
  47. }
  48. @Override
  49. protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
  50. return builder.sources(ItsOpServerApplication.class);
  51. }
  52. public static void main(String[] args) {
  53. SpringApplication application = new SpringApplicationBuilder()
  54. .sources(ItsOpServerApplication.class)
  55. .listeners(new ApplicationPidFileWriter("./conf/" + applicationName + ".pid"))
  56. .build();
  57. application.setBannerMode(Banner.Mode.OFF);
  58. application.run(args);
  59. }
  60. @Override
  61. public void run(String... args) {
  62. ApplicationConfig applicationConfig = (ApplicationConfig) AppUtils.getBean(ApplicationConfig.class);
  63. log.info("");
  64. log.info("");
  65. log.info("************************************************************************************");
  66. log.info("** **");
  67. log.info("** Intelligent Traffic System **");
  68. log.info("** Intelligent Traffic System Common Operating Server. **");
  69. log.info("** **");
  70. log.info("** [ver.1.0] **");
  71. log.info("** process: {}", applicationConfig.getId());
  72. log.info("** startup: {}", applicationConfig.getBootingDateTime());
  73. log.info("************************************************************************************");
  74. CenterCommUdpServer centerCommUdpServer = (CenterCommUdpServer)AppUtils.getBean(CenterCommUdpServer.class);
  75. centerCommUdpServer.run();
  76. // VdsCommClientService vdsCommClientService = (VdsCommClientService)AppUtils.getBean(VdsCommClientService.class);
  77. // vdsCommClientService.run();
  78. VmsServerConfig vmsServerConfig = (VmsServerConfig)AppUtils.getBean(VmsServerConfig.class);
  79. TbUnitSystManager unitSystManager = (TbUnitSystManager)AppUtils.getBean(TbUnitSystManager.class);
  80. TbUnitSyst vmsServer = unitSystManager.get(vmsServerConfig.getProcessId());
  81. if (vmsServer != null) {
  82. vmsServerConfig.setIpAddress(vmsServer.getSystIp1().trim());
  83. vmsServerConfig.setPort(Integer.parseInt(vmsServer.getPrgmPort().trim()));
  84. }
  85. VdsServerConfig vdsServerConfig = (VdsServerConfig)AppUtils.getBean(VdsServerConfig.class);
  86. TbUnitSyst vdsServer = unitSystManager.get(vdsServerConfig.getProcessId());
  87. if (vdsServer != null) {
  88. vdsServerConfig.setIpAddress(vdsServer.getSystIp1().trim());
  89. vdsServerConfig.setPort(Integer.parseInt(vdsServer.getPrgmPort().trim()));
  90. }
  91. RseServerConfig rseServerConfig = (RseServerConfig)AppUtils.getBean(RseServerConfig.class);
  92. TbUnitSyst rseServer = unitSystManager.get(rseServerConfig.getProcessId());
  93. if (rseServer != null) {
  94. rseServerConfig.setIpAddress(rseServer.getSystIp1().trim());
  95. rseServerConfig.setPort(Integer.parseInt(rseServer.getPrgmPort().trim()));
  96. }
  97. CctvServerConfig cctvServerConfig = (CctvServerConfig)AppUtils.getBean(CctvServerConfig.class);
  98. TbUnitSyst cctvServer = unitSystManager.get(cctvServerConfig.getProcessId());
  99. if (cctvServer != null) {
  100. cctvServerConfig.setIpAddress(cctvServer.getSystIp1().trim());
  101. cctvServerConfig.setPort(Integer.parseInt(cctvServer.getPrgmPort().trim()));
  102. }
  103. DbmsSttsJobThread dbmsSttsJobThread = (DbmsSttsJobThread)AppUtils.getBean(DbmsSttsJobThread.class);
  104. dbmsSttsJobThread.run();
  105. applicationConfig.setStartSchedule(true);
  106. // Thread daemonThread = new Thread(new DaemonThread());
  107. // daemonThread.setDaemon(true);
  108. // daemonThread.start();
  109. }
  110. @Override
  111. public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
  112. // shutdown.....
  113. SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  114. log.error("Application Terminated: {}, {}", sdfDate.format(new Date()), contextClosedEvent.toString());
  115. }
  116. @Override
  117. public void destroy() {
  118. }
  119. @Override
  120. public void afterPropertiesSet() {
  121. }
  122. }