diff --git a/servo/src/main/java/com/galaxis/rcs/RCS.java b/servo/src/main/java/com/galaxis/rcs/RCS.java index 0ecbc50..90b3b7f 100644 --- a/servo/src/main/java/com/galaxis/rcs/RCS.java +++ b/servo/src/main/java/com/galaxis/rcs/RCS.java @@ -33,9 +33,9 @@ public class RCS { 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.findByEnvCode(1L) == null) { - LogisticsRuntimeService.createEnv(1); - LogisticsRuntime runtime = LogisticsRuntimeService.findByEnvCode(1); + if (LogisticsRuntimeService.INSTANCE.findByEnvCode(1L) == null) { + LogisticsRuntimeService.INSTANCE.createEnv(1); + LogisticsRuntime runtime = LogisticsRuntimeService.INSTANCE.findByEnvCode(1); runtime.loadMap(jw); runtime.start(); @@ -68,7 +68,7 @@ public class RCS { public static AddTaskResult addTask(long envId, AddTaskRequest request) { AddTaskResult result = new AddTaskResult(); - LogisticsRuntime logisticsRuntime = LogisticsRuntimeService.findByEnvCode(envId); + LogisticsRuntime logisticsRuntime = LogisticsRuntimeService.INSTANCE.findByEnvCode(envId); String bizTaskId = logisticsRuntime.taskService.addBizTask(request); result.bizTaskId = bizTaskId; @@ -92,7 +92,7 @@ public class RCS { AddTaskResult result = RCS.addTask(envId, request); - LogisticsRuntime logisticsRuntime = LogisticsRuntimeService.findByEnvCode(envId); + LogisticsRuntime logisticsRuntime = LogisticsRuntimeService.INSTANCE.findByEnvCode(envId); RcsTaskBiz bizTask = logisticsRuntime.taskService.waitingTaskList.get(logisticsRuntime.taskService.waitingTaskList.size() - 1); @@ -122,6 +122,6 @@ public class RCS { } public static LogisticsRuntime getDemo() { - return LogisticsRuntimeService.findByEnvCode(1L); + return LogisticsRuntimeService.INSTANCE.findByEnvCode(1L); } } diff --git a/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/AmrMessageHandler.java b/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/AmrMessageHandler.java index e1b711d..e77e15f 100644 --- a/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/AmrMessageHandler.java +++ b/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/AmrMessageHandler.java @@ -191,7 +191,7 @@ public class AmrMessageHandler { } public static PtrAgvItem getPtrAgvItem(String vehicleId) { - var runtime = LogisticsRuntimeService.findByEnvCode(1L); + var runtime = LogisticsRuntimeService.INSTANCE.findByEnvCode(1L); var executorItem = runtime.executorItemMap.get(vehicleId); return (PtrAgvItem) executorItem; } diff --git a/servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java b/servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java index 648aaf9..054cad7 100644 --- a/servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java +++ b/servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java @@ -9,13 +9,14 @@ import java.util.Map; * 物流运行时服务类 */ public class LogisticsRuntimeService { + public static final LogisticsRuntimeService INSTANCE = new LogisticsRuntimeService(); private static final Object LOCK = new Object(); - private static final Map runtimeMap = Maps.newHashMap(); + private final Map runtimeMap = Maps.newHashMap(); /** * 根据 EnvCode 查找物流运行时实例 */ - public static LogisticsRuntime findByEnvCode(long envId) { + public LogisticsRuntime findByEnvCode(long envId) { synchronized (LOCK) { LogisticsRuntime runtime = runtimeMap.get(envId); if (runtime != null) { @@ -26,7 +27,7 @@ public class LogisticsRuntimeService { } } - public static void createEnv(int envId) { + public void createEnv(int envId) { synchronized (LOCK) { LogisticsEnv env = new LogisticsEnv(); env.setEnvId(envId);