You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
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<Long, LogisticsRuntime> 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);
|
|
}
|
|
}
|
|
}
|
|
|