]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java
started input handling of SchedulerSimulator
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / sched / AbstractScheduler.java
1 package at.ac.tuwien.lsdc.sched;
2
3 import java.util.LinkedList;
4 import java.util.List;
5 import java.util.Map;
6
7 import at.ac.tuwien.lsdc.types.Application;
8 import at.ac.tuwien.lsdc.types.ScenarioData;
9 import at.ac.tuwien.lsdc.types.SchedulerEvent;
10
11 public abstract class AbstractScheduler {
12         
13         // the following types are only needed for correct
14         // log output
15         protected String schedulerName;
16         protected String scenario;
17         protected int numInSourced;
18         protected int numOutSourced;
19
20         // this map saves the following Type of Events:
21         // start of an Application, end of an Application
22         // (start outSourced, end outSourced, start inSourced, end inSourced)
23         protected Map<Long, LinkedList<SchedulerEvent>> eventMap;
24
25         // Scheduler has an internal Time "Abstraction"
26         // at every point in time it checks for Events in his "EventList"
27         // and handles them (via the individual scheduling algorithm)
28         protected long currTime;
29
30         // the timestamp at which the Scheduler is finished
31         // it is updated with every added "EndEvent"
32         protected long endTime;
33
34         // Initialize Scheduler with Data from CSV
35         // CSV will be parsed and sent as List<Application> to Scheduler
36         public ScenarioData initAndStart(LinkedList<SchedulerEvent> apps) {
37                 for (SchedulerEvent a : apps) {
38                         // read start timestamp
39                         // save event in map
40                 }
41                 startScheduling();
42                 return doEndLogging();
43         }
44
45         protected void startScheduling() {
46                 while (true) {
47                         LinkedList<SchedulerEvent> events = eventMap.get(currTime);
48                         handleEvents(events);
49                         doStateLogging();
50                         //advance Time to next Event
51                         if (currTime == endTime) {
52                                 // reached last Event, Scheduler will shut down
53                                 break;
54                         }
55                 }
56         }
57
58         // this method is where the Scheduling Algorithm resides
59         // it reads the Events (start & stop of applications)
60         protected abstract void handleEvents(LinkedList<SchedulerEvent> events);
61
62         protected void doStateLogging() {
63                 // at every timestamp (after handle Event)
64         }
65
66         // this creates the total summary which should be written to a CSV at the
67         // end
68         protected ScenarioData doEndLogging() {
69                 return new ScenarioData(schedulerName,scenario,1,1,1,1,1,1);
70         }
71 }