|
@@ -2,8 +2,6 @@ package com.persagy.ibms.data.sdk.service;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.net.URI;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
@@ -13,7 +11,6 @@ import com.persagy.ibms.core.util.KeywordUtil;
|
|
|
import com.persagy.ibms.data.sdk.test.CheckTest;
|
|
|
import com.persagy.ibms.data.sdk.util.Constant;
|
|
|
import com.persagy.ibms.data.sdk.util.DeamonUtil;
|
|
|
-import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
|
|
|
import com.persagy.ibms.data.sdk.util.RWDLoadUtil;
|
|
|
import com.persagy.ibms.data.sdk.util.RWDRepositoryUtil;
|
|
|
import com.persagy.ibms.data.sdk.util.RepositoryContainer;
|
|
@@ -42,73 +39,44 @@ public class DaemonThread extends Thread {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static boolean dir_already = false;
|
|
|
+ public static boolean initialized = false;
|
|
|
+ public static String path_config;
|
|
|
+ public static String path_physical_world;
|
|
|
+ public static String path_zkt_physical_world;
|
|
|
+ public static String path_ibms_physical_world;
|
|
|
+
|
|
|
public void run() {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
KeywordUtil.keyWordMap = Constant.keyWordMap;
|
|
|
KeywordUtil.prefixMap = Constant.prefixMap;
|
|
|
KeywordUtil.suffixMap = Constant.suffixMap;
|
|
|
|
|
|
{
|
|
|
- Date currTime = new Date();
|
|
|
- String[] pathArray = { Constant.physical_world, Constant.zkt_physical_world, Constant.config, Constant.ibms_physical_world };
|
|
|
- for (String path : pathArray) {
|
|
|
- File root = new File(path);
|
|
|
+ {
|
|
|
+ File root = new File(Constant.config);
|
|
|
if (!root.exists()) {
|
|
|
root.mkdir();
|
|
|
}
|
|
|
}
|
|
|
- try {
|
|
|
- String validPath = Constant.getLatestPath(Constant.physical_world, true);
|
|
|
- if (validPath == null) {
|
|
|
- while (true) {
|
|
|
- boolean changed_physical_world = RWDDownloadUtil.Process_physical_world();
|
|
|
- if (changed_physical_world) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ {
|
|
|
+ File root = new File(Constant.physical_world);
|
|
|
+ if (!root.exists()) {
|
|
|
+ root.mkdir();
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
}
|
|
|
if (Constant.zkt_physical_world_enable) {
|
|
|
- try {
|
|
|
- String validPath = Constant.getLatestPath(Constant.zkt_physical_world, true);
|
|
|
- if (validPath == null) {
|
|
|
- while (true) {
|
|
|
- boolean changed_physical_world = RWDDownloadUtil.Process_zkt_physical_world();
|
|
|
- if (changed_physical_world) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
+ File root = new File(Constant.zkt_physical_world);
|
|
|
+ if (!root.exists()) {
|
|
|
+ root.mkdir();
|
|
|
}
|
|
|
}
|
|
|
if (Constant.ibms_physical_world_enable) {
|
|
|
- try {
|
|
|
- String validPath = Constant.getLatestPath(Constant.ibms_physical_world, true);
|
|
|
- if (validPath == null) {
|
|
|
- while (true) {
|
|
|
- boolean changed_physical_world = RWDDownloadUtil.Process_ibms_physical_world();
|
|
|
- if (changed_physical_world) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
- try {
|
|
|
- String validPath = Constant.getLatestPath(Constant.config, false);
|
|
|
- if (validPath == null) {
|
|
|
- String tmpPath = Constant.config + Constant.getSeperator() + sdf.format(currTime) + ".json";
|
|
|
- RWDDownloadUtil.LoadConfig(tmpPath);
|
|
|
+ File root = new File(Constant.ibms_physical_world);
|
|
|
+ if (!root.exists()) {
|
|
|
+ root.mkdir();
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
}
|
|
|
+ dir_already = true;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -121,66 +89,127 @@ public class DaemonThread extends Thread {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- Constant.debug = false;
|
|
|
- RepositoryImpl Repository = RepositoryContainer.instance;
|
|
|
- Repository.use_thread = !Constant.debug;
|
|
|
- Repository.RepositoryBase = RepositoryContainer.RepositoryBase;
|
|
|
- RWDRepositoryUtil.DoRepository(Repository, true);
|
|
|
- log.warn("compute finish");
|
|
|
- RepositoryContainer.RepositoryBase.compute_finish = true;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (Constant.iot_websocket_url != null) {
|
|
|
- log.warn("iot-websocket");
|
|
|
- IOTWebSocketClient.client = new IOTWebSocketClient(new URI(Constant.iot_websocket_url + "?projectId="
|
|
|
- + RepositoryContainer.RepositoryBase.projectId.substring(2) + "&type=iot,text,pointset"));
|
|
|
- IOTWebSocketClient.client.connect();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Thread.sleep(1000L);
|
|
|
- }
|
|
|
- if (Constant.alarm_enable) {
|
|
|
- log.warn("alarm-websocket");
|
|
|
- AlarmWebSocketClient.client = new AlarmWebSocketClient(
|
|
|
- new URI(Constant.alarm_websocket_url + "/" + RepositoryContainer.RepositoryBase.projectId));
|
|
|
- AlarmWebSocketClient.client.connect();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ while (!stop) {
|
|
|
+ try {
|
|
|
Thread.sleep(1000L);
|
|
|
+ } catch (InterruptedException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
}
|
|
|
|
|
|
- while (!stop) {
|
|
|
- try {
|
|
|
- Thread.sleep(1000 * 60 * 5);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
+ boolean dir_all_valid = true;
|
|
|
+ String tmp_config = null;
|
|
|
+ {
|
|
|
+ tmp_config = Constant.getLatestPath(Constant.config, false, false);
|
|
|
+ if (tmp_config == null) {
|
|
|
+ dir_all_valid = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String tmp_physical_world = null;
|
|
|
+ {
|
|
|
+ tmp_physical_world = Constant.getLatestPath(Constant.physical_world, true, false);
|
|
|
+ if (tmp_physical_world == null) {
|
|
|
+ dir_all_valid = false;
|
|
|
}
|
|
|
+ }
|
|
|
+ String tmp_zkt_physical_world = null;
|
|
|
+ if (Constant.zkt_physical_world_enable) {
|
|
|
+ tmp_zkt_physical_world = Constant.getLatestPath(Constant.zkt_physical_world, true, false);
|
|
|
+ if (tmp_zkt_physical_world == null) {
|
|
|
+ dir_all_valid = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String tmp_ibms_physical_world = null;
|
|
|
+ if (Constant.ibms_physical_world_enable) {
|
|
|
+ tmp_ibms_physical_world = Constant.getLatestPath(Constant.ibms_physical_world, true, false);
|
|
|
+ if (tmp_ibms_physical_world == null) {
|
|
|
+ dir_all_valid = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!dir_all_valid) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn("config: " + tmp_config);
|
|
|
+ log.warn("physical_world: " + tmp_physical_world);
|
|
|
+ if (Constant.zkt_physical_world_enable) {
|
|
|
+ log.warn("zkt_physical_world: " + tmp_zkt_physical_world);
|
|
|
+ }
|
|
|
+ if (Constant.ibms_physical_world_enable) {
|
|
|
+ log.warn("ibms_physical_world: " + tmp_ibms_physical_world);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Constant.debug = false;
|
|
|
+ RepositoryImpl Repository = new RepositoryImpl();
|
|
|
+ Repository.use_thread = !Constant.debug;
|
|
|
+ Repository.RepositoryBase = RepositoryContainer.RepositoryBase;
|
|
|
+ RWDRepositoryUtil.DoRepository(Repository, true);
|
|
|
+ RepositoryContainer.instance = Repository;
|
|
|
+ log.warn("compute finish");
|
|
|
+ path_config = tmp_config;
|
|
|
+ path_physical_world = tmp_physical_world;
|
|
|
+ path_zkt_physical_world = tmp_zkt_physical_world;
|
|
|
+ path_ibms_physical_world = tmp_ibms_physical_world;
|
|
|
+ DaemonThread.initialized = true;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- try {
|
|
|
- log.warn("refresh calendar start");
|
|
|
- RWDLoadUtil.LoadCalendar(Repository);
|
|
|
- log.warn("refresh calendar finish");
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
+ if (Constant.iot_websocket_url != null) {
|
|
|
+ log.warn("iot-websocket");
|
|
|
+ IOTWebSocketClient.client = new IOTWebSocketClient(new URI(Constant.iot_websocket_url + "?projectId="
|
|
|
+ + RepositoryContainer.RepositoryBase.projectId.substring(2) + "&type=iot,text,pointset"));
|
|
|
+ IOTWebSocketClient.client.connect();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Thread.sleep(1000L);
|
|
|
}
|
|
|
- try {
|
|
|
- log.warn("deamon start");
|
|
|
- DeamonUtil.Process_deamon(Repository);
|
|
|
- log.warn("deamon finish");
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
+ if (Constant.alarm_enable) {
|
|
|
+ log.warn("alarm-websocket");
|
|
|
+ AlarmWebSocketClient.client = new AlarmWebSocketClient(
|
|
|
+ new URI(Constant.alarm_websocket_url + "/" + RepositoryContainer.RepositoryBase.projectId));
|
|
|
+ AlarmWebSocketClient.client.connect();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Thread.sleep(1000L);
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (DaemonThread.initialized) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ while (!stop) {
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000 * 60 * 5);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ RepositoryImpl Repository = RepositoryContainer.instance;
|
|
|
+ try {
|
|
|
+ log.warn("refresh calendar start");
|
|
|
+ RWDLoadUtil.LoadCalendar(Repository);
|
|
|
+ log.warn("refresh calendar finish");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ log.warn("deamon start");
|
|
|
+ DeamonUtil.Process_deamon(Repository);
|
|
|
+ log.warn("deamon finish");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
}
|