1 package at.ac.tuwien.lsdc.sched;
4 import java.util.LinkedList;
7 import at.ac.tuwien.lsdc.types.Application;
8 import at.ac.tuwien.lsdc.types.ScenarioData;
9 import at.ac.tuwien.lsdc.types.ScenarioType;
10 import at.ac.tuwien.lsdc.types.SchedulerEvent;
11 import at.ac.tuwien.lsdc.types.SchedulerType;
13 public abstract class AbstractScheduler {
15 // the following types are only needed for correct
17 protected SchedulerType schedulerType;
18 protected ScenarioType scenario;
19 protected int numInSourced;
20 protected int numOutSourced;
24 // this map saves the following Type of Events:
25 // start of an Application, end of an Application
26 // (start outSourced, end outSourced, start inSourced, end inSourced)
27 protected Map<Long, LinkedList<SchedulerEvent>> eventMap;
29 // Scheduler has an internal Time "Abstraction"
30 // at every point in time it checks for Events in his "EventList"
31 // and handles them (via the individual scheduling algorithm)
32 protected long currTime;
34 // the timestamp at which the Scheduler is finished
35 // it is updated with every added "EndEvent"
36 protected long endTime;
38 public AbstractScheduler(File logFile, SchedulerType schedulerType, ScenarioType scenario) {
39 this.logFile = logFile;
40 this.schedulerType = schedulerType;
41 this.scenario = scenario;
44 // Initialize Scheduler with Data from CSV
45 // CSV will be parsed and sent as List<Application> to Scheduler
46 public ScenarioData initAndStart(LinkedList<Application> apps) {
47 for (Application a : apps) {
48 //System.out.println(a);
49 // read start timestamp
53 return doEndLogging();
56 protected void startScheduling() {
58 LinkedList<SchedulerEvent> events = eventMap.get(currTime);
61 //advance Time to next Event
62 if (currTime == endTime) {
63 // reached last Event, Scheduler will shut down
69 // this method is where the Scheduling Algorithm resides
70 // it reads the Events (start & stop of applications)
71 protected abstract void handleEvents(LinkedList<SchedulerEvent> events);
73 protected void doStateLogging() {
74 // at every timestamp (after handle Event)
77 // this creates the total summary which should be written to a CSV at the
79 protected ScenarioData doEndLogging() {
80 return new ScenarioData(schedulerType.toString(),scenario.toString(),1,1,1,1,1,1);