1 package at.ac.tuwien.lsdc.sched;
4 import java.io.IOException;
6 import java.util.HashMap;
7 import java.util.LinkedList;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
13 import at.ac.tuwien.lsdc.types.Application;
14 import at.ac.tuwien.lsdc.types.ScenarioData;
15 import at.ac.tuwien.lsdc.types.ScenarioType;
16 import at.ac.tuwien.lsdc.types.SchedulerData;
17 import at.ac.tuwien.lsdc.types.SchedulerEvent;
18 import at.ac.tuwien.lsdc.types.SchedulerType;
19 import at.ac.tuwien.lsdc.util.CSVLogger;
21 public abstract class AbstractScheduler {
23 private static final Logger log = LoggerFactory.getLogger(AbstractScheduler.class);
25 // the following types are only needed for correct
27 protected SchedulerType schedulerType;
28 protected ScenarioType scenario;
29 protected int numInSourced;
30 protected int numOutSourced;
31 protected int numCurrInSourced;
32 protected int numCurrOutSourced;
37 // this map saves the following Type of Events:
38 // start of an Application, end of an Application
39 // (start outSourced, end outSourced, start inSourced, end inSourced)
40 protected HashMap<Long, LinkedList<SchedulerEvent>> eventMap;
42 // Scheduler has an internal Time "Abstraction"
43 // at every point in time it checks for Events in his "EventList"
44 // and handles them (via the individual scheduling algorithm)
45 protected long currTime;
47 // the timestamp at which the Scheduler is finished
48 // it is updated with every added "EndEvent"
49 protected long endTime;
51 public AbstractScheduler(File schedulerLog, SchedulerType schedulerType, ScenarioType scenario) throws IOException {
52 this.schedulerLog = schedulerLog;
53 this.schedulerType = schedulerType;
54 this.scenario = scenario;
55 this.eventMap = new HashMap<Long,LinkedList<SchedulerEvent>>();
56 this.logger = new CSVLogger(schedulerLog);
59 // Initialize Scheduler with Data from CSV
60 // CSV will be parsed and sent as List<Application> to Scheduler
61 public ScenarioData initAndStart(LinkedList<Application> apps) {
62 for (Application a : apps) {
63 //System.out.println(a);
64 // read start timestamp
70 } catch (IOException e) {
71 log.error("couldn't close logger");
73 return doEndLogging();
76 protected void startScheduling() {
78 LinkedList<SchedulerEvent> events = eventMap.get(currTime);
81 //advance Time to next Event
82 if (currTime == endTime) {
83 // reached last Event, Scheduler will shut down
89 // this method is where the Scheduling Algorithm resides
90 // it reads the Events (start & stop of applications)
91 protected abstract void handleEvents(LinkedList<SchedulerEvent> events);
93 protected void doStateLogging() {
94 SchedulerData data = new SchedulerData(currTime,1,1,1,1,1,1,numCurrInSourced,numCurrOutSourced);
96 logger.logSchedulerData(data);
97 } catch (IOException e) {
98 log.error("error logging data");
102 // this creates the total summary which should be written to a CSV at the
104 protected ScenarioData doEndLogging() {
105 return new ScenarioData(schedulerType.toString(),scenario.toString(),1,1,1,1,1,1);