ItsOpServerApplication.java 6.4 KB

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