|
@@ -6,6 +6,7 @@ import java.util.Observable;
|
|
|
import javax.swing.Timer;
|
|
|
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.Schedulable;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.Scheduler;
|
|
|
|
|
|
/**
|
|
@@ -78,7 +79,7 @@ public class SimulationManager extends Observable {
|
|
|
/**
|
|
|
* Scheduler which stores the event queue and enables scheduling and running of further events
|
|
|
*/
|
|
|
- private Scheduler scheduler;
|
|
|
+ private static Scheduler scheduler;
|
|
|
|
|
|
/**
|
|
|
* Creates a new Simulationmanager
|
|
@@ -131,7 +132,23 @@ public class SimulationManager extends Observable {
|
|
|
//TODO: Export
|
|
|
|
|
|
//Simulates the network
|
|
|
- simulateNetwork(startTime, duration);
|
|
|
+ boolean oldWay = false;
|
|
|
+ if(oldWay)
|
|
|
+ simulateNetwork(startTime, duration);
|
|
|
+ else{
|
|
|
+ long maxTime = startTime+duration;
|
|
|
+ scheduler.scheduleAll(model);
|
|
|
+ for(Connection con:model.getConnections()){
|
|
|
+ Link l = con.getLink();
|
|
|
+ if(l!=null)
|
|
|
+ l.addPackets(con.getTerminationPackages(startTime));
|
|
|
+ }
|
|
|
+ while(scheduler.hasNext(maxTime)){
|
|
|
+ Schedulable currentEvent = scheduler.getAndRemoveFirst();
|
|
|
+ System.out.println("Event time: "+currentEvent.getEventTime());
|
|
|
+ currentEvent.simulateEvent();
|
|
|
+ }
|
|
|
+ }
|
|
|
runAlgorithms(startTime+duration);
|
|
|
collectionMan.collectPackets();
|
|
|
//Run all
|
|
@@ -340,6 +357,7 @@ public class SimulationManager extends Observable {
|
|
|
this.controller = controller;
|
|
|
if(algo!=null)
|
|
|
algos.add(algo);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -365,4 +383,22 @@ public class SimulationManager extends Observable {
|
|
|
public PacketExportManager getPacketExportManager(){
|
|
|
return exportMan;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds an event to the event queue, which will be simulated later. Returns falls, if it could not be added (e.g. timestep to low)
|
|
|
+ * @param event event which should be scheduled
|
|
|
+ * @return true if it was scheduled, false if not
|
|
|
+ */
|
|
|
+ public static boolean scheduleEvent(Schedulable event){
|
|
|
+ return scheduler.scheduleEvent(event);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Removes an event from the global event queue
|
|
|
+ * @param event Event which should be removed
|
|
|
+ * @return true, if it was removed, false if not
|
|
|
+ */
|
|
|
+ public static boolean removeEvent(Schedulable event){
|
|
|
+ return scheduler.removeEvent(event);
|
|
|
+ }
|
|
|
}
|