Commit b4e2bf3d authored by Björn Richerzhagen's avatar Björn Richerzhagen Committed by Jose Ignacio Monreal Bailey
Browse files

Use SimulationObserver to close connection to SUMO

parent ec43a6f9
...@@ -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,15 +130,18 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -129,15 +130,18 @@ 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() {
/*
* 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(); _connection.close();
} }
}, null, 0);
}
} }
@Override @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