Commit f419b5c2 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Use SimulationObserver to close connection to SUMO

parent 1f68e52b
......@@ -14,6 +14,7 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import de.tud.kom.p2psim.api.simengine.SimulatorObserver;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
......@@ -46,7 +47,7 @@ import de.tudresden.ws.container.SumoPosition2D;
import de.tudresden.ws.container.SumoStringList;
import it.polito.appeal.traci.SumoTraciConnection;
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController {
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController, SimulatorObserver {
private static final File TEMP_FILE = new File(new File(System.getProperty("java.io.tmpdir")), "road_network.tmp");
private List<RoadNetworkEdge> modifiedEdges = new ArrayList<>();
......@@ -129,15 +130,18 @@ public class TraciSimulationController implements VehicleController, SimulationS
Runtime.getRuntime().addShutdownHook(new Thread(shutdownHook));
_initalized = true;
Event.scheduleWithDelay(Simulator.getEndTime()-Simulator.getCurrentTime(), new EventHandler() {
}
}
@Override
public void eventOccurred(Object content, int type) {
public void simulationFinished() {
/*
* This is called by the simulation scheduler once the simulation is
* finished - it should be used to terminate the connection to SUMO.
*/
if (_connection != null && !_connection.isClosed()) {
_connection.close();
}
}, null, 0);
}
}
@Override
......
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