shjung 2 жил өмнө
parent
commit
eb74378429

+ 2 - 0
conf/apiKey.properties

@@ -0,0 +1,2 @@
+atmp-key=GKhEEB6LS9UEgLea0CorQiKzY0xxP86eJfhj8a2wmx4jNJ%2FBhL8f7rBviPWQY92ugK8zPjLYGQ8QQ5TRShtYFQ%3D%3D
+frcs-key=GKhEEB6LS9UEgLea0CorQiKzY0xxP86eJfhj8a2wmx4jNJ%2FBhL8f7rBviPWQY92ugK8zPjLYGQ8QQ5TRShtYFQ%3D%3D

+ 10 - 12
src/main/java/com/its/wthr/WthrCommServerApplication.java

@@ -85,11 +85,11 @@ public class WthrCommServerApplication implements CommandLineRunner, Application
     public void run(String... args) throws Exception {
 
         if (OS.isWindows()) {
+            String sysTime = SysUtils.getSysTimeStr();
+            //JFrame.setDefaultLookAndFeelDecorated(true);
+            JFrame frame = new JFrame("기상정보 연계 서버 - [" + sysTime + "]");
+            MainUI UI = new MainUI(frame);
             SwingUtilities.invokeLater(() -> {
-                String sysTime = SysUtils.getSysTimeStr();
-                //JFrame.setDefaultLookAndFeelDecorated(true);
-                JFrame frame = new JFrame("기상정보 연계 서버 - [" + sysTime + "]");
-                MainUI UI = new MainUI(frame);
                 try {
                     ClassPathResource file = new ClassPathResource("static/image/application.png");
                     URL imgURL = file.getURL();
@@ -119,8 +119,6 @@ public class WthrCommServerApplication implements CommandLineRunner, Application
                 logArea.setText(null);
                 JTextAreaOutputStream out = new JTextAreaOutputStream(logArea);
                 System.setOut(new PrintStream(out));
-
-                //UI.LoadControllerInfo();
             });
         }
 
@@ -148,12 +146,6 @@ public class WthrCommServerApplication implements CommandLineRunner, Application
         AtmpService atmpService = (AtmpService) AppUtils.getBean(AtmpService.class);
         FrcsService frcsService = (FrcsService) AppUtils.getBean(FrcsService.class);
 
-        atmpService.doJob();
-        frcsService.doJob();
-
-        // schedule enable
-        serverConfig.setStartSchedule(true);
-
         if (OS.isWindows()) {
             MainUI UI = MainUI.getInstance();
             if (UI != null) {
@@ -161,6 +153,12 @@ public class WthrCommServerApplication implements CommandLineRunner, Application
             }
         }
 
+        atmpService.doJob();
+        frcsService.doJob();
+
+        // schedule enable
+        serverConfig.setStartSchedule(true);
+
     }
 
     public void terminateApplication() {

+ 36 - 0
src/main/java/com/its/wthr/config/AtmpConfig.java

@@ -8,6 +8,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 
 import javax.annotation.PostConstruct;
+import java.io.FileInputStream;
+import java.util.Properties;
 
 @Slf4j
 @Getter
@@ -26,6 +28,40 @@ public class AtmpConfig {
 
     @PostConstruct
     private void init() {
+        loadApiKey();
         log.info("{}", this);
     }
+
+    public boolean loadApiKey() {
+        try
+        {
+            String workingDir = System.getProperty("user.dir");
+            FileInputStream in = null;
+            try
+            {
+                in = new FileInputStream(workingDir + "/conf/apiKey.properties");
+            }
+            catch(Exception e)
+            {
+                log.error("{}.loadApiKey: Exception: {}", this.getClass().getSimpleName(), e.toString());
+                return false;
+            }
+
+            Properties props = new Properties();
+            props.load(in);
+            in.close();
+
+            String apiKey = props.getProperty("atmp-key",  "x").trim();
+            if (!"x".equals(apiKey)) {
+                log.info("ATMP Key: {}", apiKey);
+                this.apiKey = apiKey;
+            }
+        }
+        catch(Exception e)
+        {
+            log.error("{}.loadApiKey: Exception: {}", this.getClass().getSimpleName(), e.toString());
+            return false;
+        }
+        return true;
+    }
 }

+ 36 - 0
src/main/java/com/its/wthr/config/FrcsConfig.java

@@ -8,6 +8,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 
 import javax.annotation.PostConstruct;
+import java.io.FileInputStream;
+import java.util.Properties;
 
 @Slf4j
 @Getter
@@ -26,6 +28,40 @@ public class FrcsConfig {
 
     @PostConstruct
     private void init() {
+        loadApiKey();
         log.info("{}", this);
     }
+
+    public boolean loadApiKey() {
+        try
+        {
+            String workingDir = System.getProperty("user.dir");
+            FileInputStream in = null;
+            try
+            {
+                in = new FileInputStream(workingDir + "/conf/apiKey.properties");
+            }
+            catch(Exception e)
+            {
+                log.error("{}.loadApiKey: Exception: {}", this.getClass().getSimpleName(), e.toString());
+                return false;
+            }
+
+            Properties props = new Properties();
+            props.load(in);
+            in.close();
+
+            String apiKey = props.getProperty("frcs-key",  "x").trim();
+            if (!"x".equals(apiKey)) {
+                log.info("FRCS Key: {}", apiKey);
+                this.apiKey = apiKey;
+            }
+        }
+        catch(Exception e)
+        {
+            log.error("{}.loadApiKey: Exception: {}", this.getClass().getSimpleName(), e.toString());
+            return false;
+        }
+        return true;
+    }
 }

+ 2 - 5
src/main/java/com/its/wthr/process/AbstractDbmsJobProcess.java

@@ -42,7 +42,7 @@ public abstract class AbstractDbmsJobProcess {
                     try {
                         DbmsJobData dbmsJobData = AbstractDbmsJobProcess.DBMS_DATA_QUEUE.take();
                         if (dbmsJobData != null) {
-                            log.info("DBMS_DATA_QUEUE..take: {} EA, {}, {}", DBMS_DATA_QUEUE.size(), dbmsJobData, Thread.currentThread().getName());
+                            //log.info("DBMS_DATA_QUEUE..take: {} EA, {}, {}", DBMS_DATA_QUEUE.size(), dbmsJobData, Thread.currentThread().getName());
                             DbmsJobTask handler = (DbmsJobTask) AppUtils.getBean(DbmsJobTask.class);
                             handler.run(this, dbmsJobData);
                         }
@@ -88,7 +88,7 @@ public abstract class AbstractDbmsJobProcess {
                 log.error("AbstractDbmsJobProcess.add: Queue Full Error, Size: {} EA, {}", DBMS_DATA_QUEUE.size(), dbmsJobData);
                 return false;
             }
-            log.info("DBMS_DATA_QUEUE.offer: {} EA, {}", DBMS_DATA_QUEUE.size(), dbmsJobData);
+            //log.info("DBMS_DATA_QUEUE.offer: {} EA, {}", DBMS_DATA_QUEUE.size(), dbmsJobData);
             return true;
         } catch (Exception e) {
             log.error("AbstractDbmsJobProcess.add: Exception: {}", e.getMessage(), e);
@@ -97,11 +97,8 @@ public abstract class AbstractDbmsJobProcess {
     }
 
     public void runJob(DbmsJobData dbmsJobData) {
-
         //log.info("AbstractDbmsJobProcess.runJob: type: {}, {}", dbmsJobData.getType(), Thread.currentThread().getName());
-
         if (dbmsJobData.getType() == DbmsJobType.DATA_TYPE_UNIT_SYST_STTS) {
-
             // UNIT 상태정보 관리는 라이브러리에서 수행한다.
             UnitSystSttsVo stts = (UnitSystSttsVo)dbmsJobData.getData();
             this.unitSystMapper.updateUnitSystStts(stts);       // 상태정보 업데이트

+ 0 - 1
src/main/java/com/its/wthr/process/DbmsJobProcess.java

@@ -58,7 +58,6 @@ public class DbmsJobProcess extends AbstractDbmsJobProcess {
             e.printStackTrace();
             log.error("DbmsJobProcess.process: Exception: {}", e.toString());
         }
-
         log.info("DbmsJobProcess.process: ..end: {}, {} EA, {} ms. {}", sType, count, elapsed.milliSeconds(), Thread.currentThread().getName());
     }
 

+ 21 - 6
src/main/java/com/its/wthr/scheduler/SchedulerTask.java

@@ -32,41 +32,56 @@ public class SchedulerTask {
             return;
         }
         Elapsed elapsed = new Elapsed();
-        log.info("UnitSystSchedule :: start. {}", Thread.currentThread().getName());
+        //log.info("UnitSystSchedule :: start. {}", Thread.currentThread().getName());
 
         // 1. 프로세스 상태정보 업데이트
         this.unitSystService.updateUnitSyst(true);
 
-        log.info("UnitSystSchedule :: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
+        long jobElapsed = elapsed.milliSeconds();
+        if (jobElapsed > 3000) {
+            log.info("UnitSystSchedule :: ..end. {} ms. {}", jobElapsed, Thread.currentThread().getName());
+        }
     }
 
-    @Scheduled(cron = "${application.atmp.crontab:0 15 * * * *}")
+    @Scheduled(cron = "${application.atmp.crontab:40 0/30 * * * *}")
     public void atmpSchedule() {
         if (!this.serverConfig.isStartSchedule()) {
+            log.error("AtmpSchedule :: schedule setting not yet");
             return;
         }
         if (!this.atmpConfig.isEnabled()) {
+            log.error("AtmpSchedule :: schedule is not enable.");
             return;
         }
 
         Elapsed elapsed = new Elapsed();
         log.info("AtmpSchedule :: start. {}", Thread.currentThread().getName());
-        this.atmpService.doJob();
+        try {
+            this.atmpService.doJob();
+        } catch (Exception e) {
+            log.error("AtmpSchedule :: ..end. {} ms. {}, ERROR: {}", elapsed.milliSeconds(), Thread.currentThread().getName(), e.getMessage());
+        }
         log.info("AtmpSchedule :: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
     }
 
-    @Scheduled(cron = "${application.frcs.crontab:0 15 * * * *}")
+    @Scheduled(cron = "${application.frcs.crontab:50 0/30 * * * *}")
     public void frcsSchedule() {
         if (!this.serverConfig.isStartSchedule()) {
+            log.error("FrcsSchedule :: schedule setting not yet");
             return;
         }
         if (!this.frcsConfig.isEnabled()) {
+            log.error("FrcsSchedule :: schedule is not enable.");
             return;
         }
 
         Elapsed elapsed = new Elapsed();
         log.info("FrcsSchedule :: start. {}", Thread.currentThread().getName());
-        this.frcsService.doJob();
+        try {
+            this.frcsService.doJob();
+        } catch (Exception e) {
+            log.error("FrcsSchedule :: ..end. {} ms. {}, ERROR: {}", elapsed.milliSeconds(), Thread.currentThread().getName(), e.getMessage());
+        }
         log.info("FrcsSchedule :: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
     }
 

+ 1 - 0
src/main/java/com/its/wthr/service/AtmpService.java

@@ -56,6 +56,7 @@ public class AtmpService extends AbstractXmlService {
             }
             for (Map.Entry<String, AtmpPltnVo> e : AppRepository.getInstance().getAtmpPltnMap().entrySet()) {
                 e.getValue().setRequestResult(1);
+//                log.info("{}", e.getValue());
             }
         }
         catch (Exception e) {

+ 1 - 0
src/main/java/com/its/wthr/service/FrcsService.java

@@ -69,6 +69,7 @@ public class FrcsService extends AbstractXmlService {
             }
             for (Map.Entry<String, FrcsZoneVo> e : AppRepository.getInstance().getFrcsZoneMap().entrySet()) {
                 e.getValue().setRequestResult(1);
+//                log.info("{}", e.getValue());
             }
         }
         catch (Exception e) {

+ 1 - 2
src/main/java/com/its/wthr/service/UnitSystService.java

@@ -97,7 +97,6 @@ public class UnitSystService {
         catch (Exception e) {
             log.error("[LOADING...] UnitSystService.selectAll: Exception: {}", e.getMessage());
         }
-
         //for (Map.Entry<String, UnitSystVo> e : this.unitSystMap.entrySet()) {
         //    log.info(e.toString());
         //}
@@ -128,7 +127,7 @@ public class UnitSystService {
         else {
             AbstractDbmsJobProcess.addQ(new DbmsJobData(DbmsJobType.DATA_TYPE_UNIT_SYST_STTS, insHs, this.unitSystStts, 1));
             if (insHs) {
-                loadMaster();
+                //loadMaster();
             }
         }
         MDC.remove(keyData);

+ 35 - 29
src/main/java/com/its/wthr/ui/MainUI.java

@@ -67,17 +67,32 @@ public class MainUI {
     private JTable listAtmp;
     private JTable listFrcs;
     private JButton btnRequest;
+    private boolean isUpdatable;
+    private boolean isUpdateAtmp;
+    private boolean isUpdateFrcs;
 
     public static MainUI getInstance() {
         return _instance;
     }
 
     public void displaySystime() {
-        lblSystime.setText(" " + SysUtils.getSysTimeStr() + "  ");
+        String sysTime = SysUtils.getSysTimeStr();
+        lblSystime.setText(" " + sysTime + "  ");
+        updateCommSttsTotal(sysTime);
+    }
+
+    private void updateCommSttsTotal(String sysTime) {
+        if (this.isUpdatable) {
+            if (this.isUpdateAtmp) {
+                updateAtmpPltnStts(sysTime);
+            }
+            if (this.isUpdateFrcs) {
+                updateFrcsPltnStts(sysTime);
+            }
+        }
     }
 
     public void displayResource() {
-        //OperatingSystemMXBean osBean = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
         long memoryUsage = Math.round(((double) (osBean.getTotalPhysicalMemorySize() - osBean.getFreePhysicalMemorySize())) / (double) osBean.getTotalPhysicalMemorySize() * 100.0);
         lblMemoryUsage.setText(String.valueOf(memoryUsage));
         double cpuLoad = osBean.getSystemCpuLoad();
@@ -86,18 +101,14 @@ public class MainUI {
         } else {
             lblCpuRate.setText("---");
         }
-//        if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
-//            com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean)osBean;
-//            log.error("CPU LOAD: {}", Math.ceil(nativeOsBean.getSystemCpuLoad() * 100.0));
-//        }
-//        else {
-//            log.error("You're not using Oracle Java nor using the native library. You won't be able to read some native data");
-//        }
     }
 
     public MainUI(JFrame jFrame) {
         System.setProperty("awt.useSystemAAFontSettings", "false"); // AntiAliasing false
 
+        this.isUpdatable = false;
+        this.isUpdateAtmp = false;
+        this.isUpdateFrcs = false;
         this.jFrame = jFrame;
         if (_instance == null) {
             _instance = this;
@@ -280,7 +291,7 @@ public class MainUI {
         for (int ii = 0; ii < getColumnModel_.getColumnCount(); ii++) {
             getColumnModel_.getColumn(ii).setCellRenderer(frcsCellRenderer);
         }
-
+        this.isUpdatable = true;
     }
 
     public void LoadControllerInfo() {
@@ -302,7 +313,12 @@ public class MainUI {
         initTblListUI(atmpList, frcsList);
     }
 
-    public void updateAtmpPltnStts(String sysTime) {
+    public boolean updateAtmpPltnStts(String sysTime) {
+        if (!this.isUpdatable) {
+            this.isUpdateAtmp = true;
+            return false;
+        }
+        this.isUpdateAtmp = false;
         tabInfo.setTitleAt(0, "대기환경 - [" + sysTime + "]");
 
         try {
@@ -314,9 +330,15 @@ public class MainUI {
             log.error("Cast Atmp Error");
         }
         tabAtmp.repaint();
+        return true;
     }
 
-    public void updateFrcsPltnStts(String sysTime) {
+    public boolean updateFrcsPltnStts(String sysTime) {
+        if (!this.isUpdatable) {
+            this.isUpdateFrcs = true;
+            return false;
+        }
+        this.isUpdateFrcs = false;
         tabInfo.setTitleAt(1, "동네예보 - [" + sysTime + "]");
 
         try {
@@ -328,23 +350,7 @@ public class MainUI {
             log.error("Cast Frcs Error");
         }
         tabFrcs.repaint();
-    }
-
-    public void updateCtlrStts(AtmpPltnVo obj) {
-        if (this.atmpTableModel == null) {
-            return;
-        }
-        for (int ii = 0; ii < this.atmpTableModel.getRowCount(); ii++) {
-//            if (obj.getPIS_NMBR().equals(ctlrSttsTableModel.getValueAt(ii, 1).toString())) {
-//                int modelRow = tblCtlrList.convertRowIndexToModel(ii);
-//                this.ctlrSttsTableModel.setValue(obj, ii, modelRow);
-//                break;
-//            }
-        }
-        AtmpTableModel tableModel = (AtmpTableModel) listAtmp.getModel();
-        if (tableModel != null) {
-            tableModel.fireTableDataChanged();
-        }
+        return true;
     }
 
     {

+ 4 - 4
src/main/resources/application.yml

@@ -9,16 +9,16 @@ application:
 
   atmp:
     enabled: true
-    crontab: 30 0/15 * * * *
-    api-key: 2y3qwo%2BwhlG6E%2BZfcyDKLMCr5Lp4gy%2BNgGuvWmgAdq7O%2Bf%2Fs4DPQz2ZD1rzDLowBq%2F6pfSi5F6UWlyM5meRiaw%3D%3D
+    crontab: 40 0/30 * * * *
+    api-key: GKhEEB6LS9UEgLea0CorQiKzY0xxP86eJfhj8a2wmx4jNJ%2FBhL8f7rBviPWQY92ugK8zPjLYGQ8QQ5TRShtYFQ%3D%3D
     api-ver: 1.3
     start-hour: 0
     end-hour: 23
 
   frcs:
     enabled: true
-    crontab: 10 0/15 * * * *
-    api-key: 2y3qwo%2BwhlG6E%2BZfcyDKLMCr5Lp4gy%2BNgGuvWmgAdq7O%2Bf%2Fs4DPQz2ZD1rzDLowBq%2F6pfSi5F6UWlyM5meRiaw%3D%3D
+    crontab: 50 0/30 * * * *
+    api-key: GKhEEB6LS9UEgLea0CorQiKzY0xxP86eJfhj8a2wmx4jNJ%2FBhL8f7rBviPWQY92ugK8zPjLYGQ8QQ5TRShtYFQ%3D%3D
     start-hour: 0
     end-hour: 23