ItsOpServerApplication.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. public ItsOpServerApplication() {
  44. super();
  45. setRegisterErrorPageFilter(false);
  46. }
  47. @Override
  48. protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
  49. return builder.sources(ItsOpServerApplication.class);
  50. }
  51. public static void main(String[] args) {
  52. SpringApplication application = new SpringApplicationBuilder()
  53. .sources(ItsOpServerApplication.class)
  54. .listeners(new ApplicationPidFileWriter("./conf/" + applicationName + ".pid"))
  55. .build();
  56. application.setBannerMode(Banner.Mode.OFF);
  57. application.run(args);
  58. }
  59. @Override
  60. public void run(String... args) {
  61. ApplicationConfig applicationConfig = (ApplicationConfig) AppUtils.getBean(ApplicationConfig.class);
  62. log.info("");
  63. log.info("");
  64. log.info("************************************************************************************");
  65. log.info("** **");
  66. log.info("** Intelligent Traffic System **");
  67. log.info("** Intelligent Traffic System Common Operating Server. **");
  68. log.info("** **");
  69. log.info("** [ver.1.0] **");
  70. log.info("** process: {}", applicationConfig.getId());
  71. log.info("** startup: {}", applicationConfig.getBootingDateTime());
  72. log.info("************************************************************************************");
  73. CenterCommUdpServer centerCommUdpServer = (CenterCommUdpServer)AppUtils.getBean(CenterCommUdpServer.class);
  74. centerCommUdpServer.run();
  75. // VdsCommClientService vdsCommClientService = (VdsCommClientService)AppUtils.getBean(VdsCommClientService.class);
  76. // vdsCommClientService.run();
  77. VmsServerConfig vmsServerConfig = (VmsServerConfig)AppUtils.getBean(VmsServerConfig.class);
  78. TbUnitSystManager unitSystManager = (TbUnitSystManager)AppUtils.getBean(TbUnitSystManager.class);
  79. TbUnitSyst vmsServer = unitSystManager.get(vmsServerConfig.getProcessId());
  80. if (vmsServer != null) {
  81. vmsServerConfig.setIpAddress(vmsServer.getSystIp1().trim());
  82. vmsServerConfig.setPort(Integer.parseInt(vmsServer.getPrgmPort().trim()));
  83. }
  84. VdsServerConfig vdsServerConfig = (VdsServerConfig)AppUtils.getBean(VdsServerConfig.class);
  85. TbUnitSyst vdsServer = unitSystManager.get(vdsServerConfig.getProcessId());
  86. if (vdsServer != null) {
  87. vdsServerConfig.setIpAddress(vdsServer.getSystIp1().trim());
  88. vdsServerConfig.setPort(Integer.parseInt(vdsServer.getPrgmPort().trim()));
  89. }
  90. RseServerConfig rseServerConfig = (RseServerConfig)AppUtils.getBean(RseServerConfig.class);
  91. TbUnitSyst rseServer = unitSystManager.get(rseServerConfig.getProcessId());
  92. if (rseServer != null) {
  93. rseServerConfig.setIpAddress(rseServer.getSystIp1().trim());
  94. rseServerConfig.setPort(Integer.parseInt(rseServer.getPrgmPort().trim()));
  95. }
  96. CctvServerConfig cctvServerConfig = (CctvServerConfig)AppUtils.getBean(CctvServerConfig.class);
  97. TbUnitSyst cctvServer = unitSystManager.get(cctvServerConfig.getProcessId());
  98. if (cctvServer != null) {
  99. cctvServerConfig.setIpAddress(cctvServer.getSystIp1().trim());
  100. cctvServerConfig.setPort(Integer.parseInt(cctvServer.getPrgmPort().trim()));
  101. }
  102. DbmsSttsJobThread dbmsSttsJobThread = (DbmsSttsJobThread)AppUtils.getBean(DbmsSttsJobThread.class);
  103. dbmsSttsJobThread.run();
  104. applicationConfig.setStartSchedule(true);
  105. // Thread daemonThread = new Thread(new DaemonThread());
  106. // daemonThread.setDaemon(true);
  107. // daemonThread.start();
  108. }
  109. @Override
  110. public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
  111. // shutdown.....
  112. SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  113. log.error("Application Terminated: {}, {}", sdfDate.format(new Date()), contextClosedEvent.toString());
  114. }
  115. @Override
  116. public void destroy() {
  117. }
  118. @Override
  119. public void afterPropertiesSet() {
  120. }
  121. }