]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java
added CSV logging (still little bit buggy)
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / sched / AbstractScheduler.java
1 package at.ac.tuwien.lsdc.sched;
2
3 import java.io.File;
4 import java.util.LinkedList;
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.ScenarioType;
10 import at.ac.tuwien.lsdc.types.SchedulerEvent;
11 import at.ac.tuwien.lsdc.types.SchedulerType;
12
13 public abstract class AbstractScheduler {
14         
15         // the following types are only needed for correct
16         // log output
17         protected SchedulerType schedulerType;
18         protected ScenarioType scenario;
19         protected int numInSourced;
20         protected int numOutSourced;
21         
22         File logFile;
23
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;
28
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;
33
34         // the timestamp at which the Scheduler is finished
35         // it is updated with every added "EndEvent"
36         protected long endTime;
37
38         public AbstractScheduler(File logFile, SchedulerType schedulerType, ScenarioType scenario) {
39                 this.logFile = logFile;
40                 this.schedulerType = schedulerType;
41                 this.scenario = scenario;
42         }
43         
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
50                         // save event in map
51                 }
52                 //startScheduling();
53                 return doEndLogging();
54         }
55
56         protected void startScheduling() {
57                 while (true) {
58                         LinkedList<SchedulerEvent> events = eventMap.get(currTime);
59                         handleEvents(events);
60                         doStateLogging();
61                         //advance Time to next Event
62                         if (currTime == endTime) {
63                                 // reached last Event, Scheduler will shut down
64                                 break;
65                         }
66                 }
67         }
68
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);
72
73         protected void doStateLogging() {
74                 // at every timestamp (after handle Event)
75         }
76
77         // this creates the total summary which should be written to a CSV at the
78         // end
79         protected ScenarioData doEndLogging() {
80                 return new ScenarioData(schedulerType.toString(),scenario.toString(),1,1,1,1,1,1);
81         }
82 }