Commit 3ca63f88 authored by hengwen's avatar hengwen

Keep track of simulation status, related to 3364585a.

parent 3364585a
......@@ -30,6 +30,7 @@ public class SimulationService implements Runnable {
private Map<Integer, SimulatorService> simulators;
private List<VehicleService> vehicles;
private ServiceRegistry registry;
private SimulationStatus status;
private Properties prop;
private Logger logger = LoggerFactory.getLogger(SimulationService.class);
......@@ -39,6 +40,13 @@ public class SimulationService implements Runnable {
Map<Integer, List<VehicleModel>> results;
public SimulationService(int simulationID) {
if (instances == null){
instances = new HashMap<>();
}
instances.put(simulationID, this);
status = SimulationStatus.READY;
uuid = UUID.randomUUID().toString();
simulation = SimulationDAO.getByID(simulationID);
if (results == null){
......@@ -59,7 +67,7 @@ public class SimulationService implements Runnable {
}
synchronized public void startSimulation(ServiceRegistry registry) throws Exception {
// prepare scenario
// prepare map, read scenario
MapModel map = getSimulationMap();
if (map == null) {
return;
......@@ -167,10 +175,16 @@ public class SimulationService implements Runnable {
@Override
public void run() {
status = SimulationStatus.RUNNING;
try {
startSimulation(registry);
status = SimulationStatus.FINISHED;
} catch (ServiceRegistry.NoServiceException e){
status = SimulationStatus.FAILED;
logger.error("Resource not enough, please make sure there are enough simulators and rmi servers online.", e);
} catch (Exception e) {
logger.warn(e.getMessage(), e);
status = SimulationStatus.FAILED;
logger.error(e.getMessage(), e);
} finally {
registry.releaseAll();
}
......@@ -206,4 +220,17 @@ public class SimulationService implements Runnable {
public Properties getProp() {
return prop;
}
public static Map<Integer, SimulationService> getInstances() {
return instances;
}
public SimulationStatus getStatus() {
return status;
}
public enum SimulationStatus {
READY, RUNNING, FAILED, FINISHED
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment