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