package com.yvan.logisticsModel; import com.google.common.collect.Maps; import com.yvan.logisticsEnv.LogisticsEnv; import java.util.Map; /** * 物流运行时服务类 */ public class LogisticsRuntimeService { public static final LogisticsRuntimeService INSTANCE = new LogisticsRuntimeService(); private static final Object LOCK = new Object(); private final Map runtimeMap = Maps.newHashMap(); /** * 根据 EnvCode 查找物流运行时实例 */ 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); } } public void createEnv(int envId) { synchronized (LOCK) { LogisticsEnv env = new LogisticsEnv(); env.setEnvId(envId); env.setVirtual(envId != 1); LogisticsRuntime runtime = new LogisticsRuntime(env); runtimeMap.put(env.getEnvId(), runtime); } } }