Browse Source

LogisticsRuntimeService.INSTANCE

master
修宁 6 months ago
parent
commit
dfda31c807
  1. 12
      servo/src/main/java/com/galaxis/rcs/RCS.java
  2. 2
      servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/AmrMessageHandler.java
  3. 7
      servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java

12
servo/src/main/java/com/galaxis/rcs/RCS.java

@ -33,9 +33,9 @@ public class RCS {
public static void init() { public static void init() {
String fs = Joiner.on("\n").join(FileUtils.readLines(new File("./yvan-rcs-web/src/example/example1.json"), StandardCharsets.UTF_8)); 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); JsonWrapper jw = new JsonWrapper(fs);
if (LogisticsRuntimeService.findByEnvCode(1L) == null) { if (LogisticsRuntimeService.INSTANCE.findByEnvCode(1L) == null) {
LogisticsRuntimeService.createEnv(1); LogisticsRuntimeService.INSTANCE.createEnv(1);
LogisticsRuntime runtime = LogisticsRuntimeService.findByEnvCode(1); LogisticsRuntime runtime = LogisticsRuntimeService.INSTANCE.findByEnvCode(1);
runtime.loadMap(jw); runtime.loadMap(jw);
runtime.start(); runtime.start();
@ -68,7 +68,7 @@ public class RCS {
public static AddTaskResult addTask(long envId, AddTaskRequest request) { public static AddTaskResult addTask(long envId, AddTaskRequest request) {
AddTaskResult result = new AddTaskResult(); AddTaskResult result = new AddTaskResult();
LogisticsRuntime logisticsRuntime = LogisticsRuntimeService.findByEnvCode(envId); LogisticsRuntime logisticsRuntime = LogisticsRuntimeService.INSTANCE.findByEnvCode(envId);
String bizTaskId = logisticsRuntime.taskService.addBizTask(request); String bizTaskId = logisticsRuntime.taskService.addBizTask(request);
result.bizTaskId = bizTaskId; result.bizTaskId = bizTaskId;
@ -92,7 +92,7 @@ public class RCS {
AddTaskResult result = RCS.addTask(envId, request); 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); RcsTaskBiz bizTask = logisticsRuntime.taskService.waitingTaskList.get(logisticsRuntime.taskService.waitingTaskList.size() - 1);
@ -122,6 +122,6 @@ public class RCS {
} }
public static LogisticsRuntime getDemo() { public static LogisticsRuntime getDemo() {
return LogisticsRuntimeService.findByEnvCode(1L); return LogisticsRuntimeService.INSTANCE.findByEnvCode(1L);
} }
} }

2
servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/AmrMessageHandler.java

@ -191,7 +191,7 @@ public class AmrMessageHandler {
} }
public static PtrAgvItem getPtrAgvItem(String vehicleId) { public static PtrAgvItem getPtrAgvItem(String vehicleId) {
var runtime = LogisticsRuntimeService.findByEnvCode(1L); var runtime = LogisticsRuntimeService.INSTANCE.findByEnvCode(1L);
var executorItem = runtime.executorItemMap.get(vehicleId); var executorItem = runtime.executorItemMap.get(vehicleId);
return (PtrAgvItem) executorItem; return (PtrAgvItem) executorItem;
} }

7
servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java

@ -9,13 +9,14 @@ import java.util.Map;
* 物流运行时服务类 * 物流运行时服务类
*/ */
public class LogisticsRuntimeService { public class LogisticsRuntimeService {
public static final LogisticsRuntimeService INSTANCE = new LogisticsRuntimeService();
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private static final Map<Long, LogisticsRuntime> runtimeMap = Maps.newHashMap(); private final Map<Long, LogisticsRuntime> runtimeMap = Maps.newHashMap();
/** /**
* 根据 EnvCode 查找物流运行时实例 * 根据 EnvCode 查找物流运行时实例
*/ */
public static LogisticsRuntime findByEnvCode(long envId) { public LogisticsRuntime findByEnvCode(long envId) {
synchronized (LOCK) { synchronized (LOCK) {
LogisticsRuntime runtime = runtimeMap.get(envId); LogisticsRuntime runtime = runtimeMap.get(envId);
if (runtime != null) { if (runtime != null) {
@ -26,7 +27,7 @@ public class LogisticsRuntimeService {
} }
} }
public static void createEnv(int envId) { public void createEnv(int envId) {
synchronized (LOCK) { synchronized (LOCK) {
LogisticsEnv env = new LogisticsEnv(); LogisticsEnv env = new LogisticsEnv();
env.setEnvId(envId); env.setEnvId(envId);

Loading…
Cancel
Save