Prechádzať zdrojové kódy

防止初次加载失败导致无法启动的问题

menglu 3 rokov pred
rodič
commit
a189e8a341

+ 7 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DaemonThread.java

@@ -9,11 +9,11 @@ import javax.annotation.PostConstruct;
 import org.springframework.stereotype.Component;
 
 import com.persagy.ibms.core.util.KeywordUtil;
-import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 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.RWDRepositoryUtil;
+import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 import com.persagy.ibms.data.sdk.util.RepositoryImpl;
 import com.persagy.ibms.data.sdk.websocket.AlarmWebSocketClient;
 import com.persagy.ibms.data.sdk.websocket.IOTWebSocketClient;
@@ -48,8 +48,12 @@ public class DaemonThread extends Thread {
 			try {
 				String validPath = Constant.getLatestPath(Constant.physical_world, true);
 				if (validPath == null) {
-					String tmpPath = Constant.physical_world + Constant.getSeperator() + sdf.format(currTime);
-					RWDDownloadUtil.LoadPhysicalWorld(tmpPath);
+					while (true) {
+						boolean changed_physical_world = RWDDownloadUtil.Process_physical_world();
+						if (changed_physical_world) {
+							break;
+						}
+					}
 				}
 			} catch (Exception e) {
 				log.error(e.getMessage(), e);

+ 3 - 39
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/RefreshThread.java

@@ -8,11 +8,11 @@ import javax.annotation.PostConstruct;
 
 import org.springframework.stereotype.Component;
 
-import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 import com.persagy.ibms.data.sdk.util.Constant;
 import com.persagy.ibms.data.sdk.util.FileUtil;
 import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
 import com.persagy.ibms.data.sdk.util.RWDRepositoryUtil;
+import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 import com.persagy.ibms.data.sdk.util.RepositoryImpl;
 
 import lombok.extern.slf4j.Slf4j;
@@ -36,8 +36,6 @@ public class RefreshThread extends Thread {
 		}
 	}
 
-	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-
 	public void run() {
 		while (true) {
 			try {
@@ -72,7 +70,7 @@ public class RefreshThread extends Thread {
 				boolean changed_physical_world = false;
 				if (last_refresh_physical_world == null || currTime.getTime() - last_refresh_physical_world.getTime() > 1000L * 60 * 60) {
 					if (Constant.physical_world_download_enable) {
-						changed_physical_world = this.Process_physical_world();
+						changed_physical_world = RWDDownloadUtil.Process_physical_world();
 					}
 					last_refresh_physical_world = currTime;
 				}
@@ -91,6 +89,7 @@ public class RefreshThread extends Thread {
 	}
 
 	private boolean Process_config() throws Exception {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
 		String validPath = Constant.getLatestPath(Constant.config, false);
 		File valid = new File(validPath);
 
@@ -107,39 +106,4 @@ public class RefreshThread extends Thread {
 			return false;
 		}
 	}
-
-	private boolean Process_physical_world() throws Exception {
-		String validPath = Constant.getLatestPath(Constant.physical_world, true);
-		// 存储临时文件
-		File dir1;
-		{
-			String tmpPath = Constant.physical_world + Constant.getSeperator() + "tmp1";
-			dir1 = new File(tmpPath);
-			RWDDownloadUtil.LoadPhysicalWorld(tmpPath);
-		}
-		File dir2;
-		{
-			String tmpPath = Constant.physical_world + Constant.getSeperator() + "tmp2";
-			dir2 = new File(tmpPath);
-			RWDDownloadUtil.LoadPhysicalWorld(tmpPath);
-		}
-		// 检查一致性
-		boolean compare = FileUtil.compareRecursive(dir1, dir2);
-		log.debug("Compare tmp1" + (compare ? "==" : "!=") + "tmp2");
-		if (compare) {
-			File valid = new File(validPath);
-			boolean compare_valid = FileUtil.compareRecursive(valid, dir2);
-			log.debug("Compare valid" + (compare_valid ? "==" : "!=") + "tmp2");
-			if (compare_valid) {
-				return false;
-			} else {
-				// 移动tmp2
-				Date currTime = new Date();
-				dir2.renameTo(new File(Constant.physical_world + Constant.getSeperator() + sdf.format(currTime)));
-				return true;
-			}
-		} else {
-			return false;
-		}
-	}
 }

+ 48 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDDownloadUtil.java

@@ -1,7 +1,9 @@
 package com.persagy.ibms.data.sdk.util;
 
 import java.io.File;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -50,6 +52,52 @@ public class RWDDownloadUtil {
 		}
 	}
 
+	public static boolean Process_physical_world() throws Exception {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+		String validPath = Constant.getLatestPath(Constant.physical_world, true);
+		// 存储临时文件
+		File dir1;
+		{
+			String tmpPath = Constant.physical_world + Constant.getSeperator() + "tmp1";
+			dir1 = new File(tmpPath);
+			RWDDownloadUtil.LoadPhysicalWorld(tmpPath);
+		}
+		File dir2;
+		{
+			String tmpPath = Constant.physical_world + Constant.getSeperator() + "tmp2";
+			dir2 = new File(tmpPath);
+			RWDDownloadUtil.LoadPhysicalWorld(tmpPath);
+		}
+		// 检查一致性
+		boolean compare = FileUtil.compareRecursive(dir1, dir2);
+		log.debug("Compare tmp1" + (compare ? "==" : "!=") + "tmp2");
+		if (compare) {
+			File valid = null;
+			if (validPath != null) {
+				valid = new File(validPath);
+			}
+			if (valid != null && valid.exists()) {
+				boolean compare_valid = FileUtil.compareRecursive(valid, dir2);
+				log.debug("Compare valid" + (compare_valid ? "==" : "!=") + "tmp2");
+				if (compare_valid) {
+					return false;
+				} else {
+					// 移动tmp2
+					Date currTime = new Date();
+					dir2.renameTo(new File(Constant.physical_world + Constant.getSeperator() + sdf.format(currTime)));
+					return true;
+				}
+			} else {
+				// 移动tmp2
+				Date currTime = new Date();
+				dir2.renameTo(new File(Constant.physical_world + Constant.getSeperator() + sdf.format(currTime)));
+				return true;
+			}
+		} else {
+			return false;
+		}
+	}
+
 	public static void LoadPhysicalWorld(String path) throws Exception {
 		log.debug("Download physical world refresh dir");
 		FileUtil.deleteRecursive(new File(path));