diff --git a/servo/src/main/java/com/galaxis/rcs/RCS.java b/servo/src/main/java/com/galaxis/rcs/RCS.java index 90b3b7f..68e39a9 100644 --- a/servo/src/main/java/com/galaxis/rcs/RCS.java +++ b/servo/src/main/java/com/galaxis/rcs/RCS.java @@ -31,11 +31,12 @@ public class RCS { @SneakyThrows public static void init() { - String fs = Joiner.on("\n").join(FileUtils.readLines(new File("./yvan-rcs-web/src/example/example1.json"), StandardCharsets.UTF_8)); - JsonWrapper jw = new JsonWrapper(fs); if (LogisticsRuntimeService.INSTANCE.findByEnvCode(1L) == null) { - LogisticsRuntimeService.INSTANCE.createEnv(1); - LogisticsRuntime runtime = LogisticsRuntimeService.INSTANCE.findByEnvCode(1); + String fs = Joiner.on("\n").join(FileUtils.readLines(new File("./yvan-rcs-web/src/example/example1.json"), StandardCharsets.UTF_8)); + JsonWrapper jw = new JsonWrapper(fs); + + LogisticsRuntimeService.INSTANCE.createEnv(1L); + LogisticsRuntime runtime = LogisticsRuntimeService.INSTANCE.findByEnvCode(1L); runtime.loadMap(jw); runtime.start(); @@ -43,8 +44,7 @@ public class RCS { } - public static void ok() - { + public static void ok() { } /** diff --git a/servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java b/servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java index 054cad7..c57cb2e 100644 --- a/servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java +++ b/servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java @@ -18,20 +18,18 @@ public class LogisticsRuntimeService { */ public LogisticsRuntime findByEnvCode(long envId) { synchronized (LOCK) { - LogisticsRuntime runtime = runtimeMap.get(envId); - if (runtime != null) { - return runtime; - } - return null; -// throw new RuntimeException("LogisticsRuntime not found for envCode: " + envId); + return runtimeMap.get(envId); } } - public void createEnv(int envId) { + public void createEnv(long envId) { synchronized (LOCK) { + if (runtimeMap.containsKey(envId)) { + return; + } LogisticsEnv env = new LogisticsEnv(); env.setEnvId(envId); - env.setVirtual(envId != 1); + env.setVirtual(envId != 1L); LogisticsRuntime runtime = new LogisticsRuntime(env); runtimeMap.put(env.getEnvId(), runtime);