1 package at.ac.tuwien.lsdc.sched;
4 import java.io.IOException;
6 import java.util.HashMap;
7 import java.util.LinkedList;
10 import at.ac.tuwien.lsdc.types.Application;
11 import at.ac.tuwien.lsdc.types.ScenarioData;
12 import at.ac.tuwien.lsdc.types.ScenarioType;
13 import at.ac.tuwien.lsdc.types.SchedulerData;
14 import at.ac.tuwien.lsdc.types.SchedulerEvent;
15 import at.ac.tuwien.lsdc.types.SchedulerType;
16 import at.ac.tuwien.lsdc.util.CSVLogger;
18 public abstract class AbstractScheduler {
20 // the following types are only needed for correct
22 protected SchedulerType schedulerType;
23 protected ScenarioType scenario;
24 protected int numInSourced;
25 protected int numOutSourced;
26 protected int numCurrInSourced;
27 protected int numCurrOutSourced;
32 // this map saves the following Type of Events:
33 // start of an Application, end of an Application
34 // (start outSourced, end outSourced, start inSourced, end inSourced)
35 protected HashMap<Long, LinkedList<SchedulerEvent>> eventMap;
37 // Scheduler has an internal Time "Abstraction"
38 // at every point in time it checks for Events in his "EventList"
39 // and handles them (via the individual scheduling algorithm)
40 protected long currTime;
42 // the timestamp at which the Scheduler is finished
43 // it is updated with every added "EndEvent"
44 protected long endTime;
46 public AbstractScheduler(File schedulerLog, SchedulerType schedulerType, ScenarioType scenario) throws IOException {
47 this.schedulerLog = schedulerLog;
48 this.schedulerType = schedulerType;
49 this.scenario = scenario;
50 this.eventMap = new HashMap<Long,LinkedList<SchedulerEvent>>();
51 this.logger = new CSVLogger(schedulerLog);
54 // Initialize Scheduler with Data from CSV
55 // CSV will be parsed and sent as List<Application> to Scheduler
56 public ScenarioData initAndStart(LinkedList<Application> apps) {
57 for (Application a : apps) {
58 //System.out.println(a);
59 // read start timestamp
65 } catch (IOException e) {
66 System.err.println("couldn't close logger");
68 return doEndLogging();
71 protected void startScheduling() {
73 LinkedList<SchedulerEvent> events = eventMap.get(currTime);
76 //advance Time to next Event
77 if (currTime == endTime) {
78 // reached last Event, Scheduler will shut down
84 // this method is where the Scheduling Algorithm resides
85 // it reads the Events (start & stop of applications)
86 protected abstract void handleEvents(LinkedList<SchedulerEvent> events);
88 protected void doStateLogging() {
89 SchedulerData data = new SchedulerData(currTime,1,1,1,1,1,1,numCurrInSourced,numCurrOutSourced);
91 logger.logSchedulerData(data);
92 } catch (IOException e) {
93 System.err.println("error logging data");
97 // this creates the total summary which should be written to a CSV at the
99 protected ScenarioData doEndLogging() {
100 return new ScenarioData(schedulerType.toString(),scenario.toString(),1,1,1,1,1,1);