]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java
implemented parsing of CSV in SchedSimulator
[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.Map;
5
6 import at.ac.tuwien.lsdc.types.Application;
7 import at.ac.tuwien.lsdc.types.ScenarioData;
8 import at.ac.tuwien.lsdc.types.SchedulerEvent;
9
10 public abstract class AbstractScheduler {
11         
12         // the following types are only needed for correct
13         // log output
14         protected String schedulerName;
15         protected String scenario;
16         protected int numInSourced;
17         protected int numOutSourced;
18
19         // this map saves the following Type of Events:
20         // start of an Application, end of an Application
21         // (start outSourced, end outSourced, start inSourced, end inSourced)
22         protected Map<Long, LinkedList<SchedulerEvent>> eventMap;
23
24         // Scheduler has an internal Time "Abstraction"
25         // at every point in time it checks for Events in his "EventList"
26         // and handles them (via the individual scheduling algorithm)
27         protected long currTime;
28
29         // the timestamp at which the Scheduler is finished
30         // it is updated with every added "EndEvent"
31         protected long endTime;
32
33         // Initialize Scheduler with Data from CSV
34         // CSV will be parsed and sent as List<Application> to Scheduler
35         public ScenarioData initAndStart(LinkedList<Application> apps) {
36                 for (Application a : apps) {
37                         System.out.println(a);
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 }