Browse Source

LogisticsRuntimeService.INSTANCE

master
修宁 6 months ago
parent
commit
cce5a8274b
  1. 12
      servo/src/main/java/com/galaxis/rcs/RCS.java
  2. 14
      servo/src/main/java/com/yvan/logisticsModel/LogisticsRuntimeService.java

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

@ -31,11 +31,12 @@ public class RCS {
@SneakyThrows @SneakyThrows
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));
JsonWrapper jw = new JsonWrapper(fs);
if (LogisticsRuntimeService.INSTANCE.findByEnvCode(1L) == null) { if (LogisticsRuntimeService.INSTANCE.findByEnvCode(1L) == null) {
LogisticsRuntimeService.INSTANCE.createEnv(1); String fs = Joiner.on("\n").join(FileUtils.readLines(new File("./yvan-rcs-web/src/example/example1.json"), StandardCharsets.UTF_8));
LogisticsRuntime runtime = LogisticsRuntimeService.INSTANCE.findByEnvCode(1); JsonWrapper jw = new JsonWrapper(fs);
LogisticsRuntimeService.INSTANCE.createEnv(1L);
LogisticsRuntime runtime = LogisticsRuntimeService.INSTANCE.findByEnvCode(1L);
runtime.loadMap(jw); runtime.loadMap(jw);
runtime.start(); runtime.start();
@ -43,8 +44,7 @@ public class RCS {
} }
public static void ok() public static void ok() {
{
} }
/** /**

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

@ -18,20 +18,18 @@ public class LogisticsRuntimeService {
*/ */
public LogisticsRuntime findByEnvCode(long envId) { public LogisticsRuntime findByEnvCode(long envId) {
synchronized (LOCK) { synchronized (LOCK) {
LogisticsRuntime runtime = runtimeMap.get(envId); return runtimeMap.get(envId);
if (runtime != null) {
return runtime;
}
return null;
// throw new RuntimeException("LogisticsRuntime not found for envCode: " + envId);
} }
} }
public void createEnv(int envId) { public void createEnv(long envId) {
synchronized (LOCK) { synchronized (LOCK) {
if (runtimeMap.containsKey(envId)) {
return;
}
LogisticsEnv env = new LogisticsEnv(); LogisticsEnv env = new LogisticsEnv();
env.setEnvId(envId); env.setEnvId(envId);
env.setVirtual(envId != 1); env.setVirtual(envId != 1L);
LogisticsRuntime runtime = new LogisticsRuntime(env); LogisticsRuntime runtime = new LogisticsRuntime(env);
runtimeMap.put(env.getEnvId(), runtime); runtimeMap.put(env.getEnvId(), runtime);

Loading…
Cancel
Save