1 | package de.uka.ipd.sdq.scheduler.sensors.impl; |
2 | |
3 | import de.uka.ipd.sdq.scheduler.SchedulerModel; |
4 | import de.uka.ipd.sdq.scheduler.processes.IActiveProcess; |
5 | import de.uka.ipd.sdq.scheduler.processes.PROCESS_STATE; |
6 | import de.uka.ipd.sdq.scheduler.sensors.IProcessStateSensor; |
7 | |
8 | public class HptSensor implements IProcessStateSensor { |
9 | |
10 | private SchedulerModel model; |
11 | private PROCESS_STATE last_state; |
12 | private double lastUpdateTime; |
13 | private boolean isHpt = false; |
14 | private double hpt = 0; |
15 | private double threshold; |
16 | private double hptStart; |
17 | |
18 | public HptSensor(SchedulerModel model, IActiveProcess process, double threshold){ |
19 | this.model = model; |
20 | this.lastUpdateTime = 0; |
21 | this.last_state = process.getState(); |
22 | this.threshold = threshold; |
23 | } |
24 | |
25 | public void start(){ |
26 | isHpt = true; |
27 | hpt = 0.0; |
28 | hptStart = model.getSimulationControl().getCurrentSimulationTime(); |
29 | lastUpdateTime = hptStart; |
30 | } |
31 | |
32 | public double getHpt() { |
33 | return hpt; |
34 | } |
35 | |
36 | public double getHptStart() { |
37 | return hptStart; |
38 | } |
39 | |
40 | public void stop() { |
41 | double currentTime = model.getSimulationControl().getCurrentSimulationTime(); |
42 | double passedTime = currentTime - lastUpdateTime; |
43 | |
44 | if (last_state == PROCESS_STATE.RUNNING){ |
45 | if (isHpt ){ |
46 | hpt += passedTime; |
47 | } |
48 | } |
49 | lastUpdateTime = currentTime; |
50 | isHpt = false; |
51 | } |
52 | |
53 | public void update(PROCESS_STATE new_state) { |
54 | if (isHpt){ |
55 | double currentTime = model.getSimulationControl().getCurrentSimulationTime(); |
56 | double passedTime = currentTime - lastUpdateTime; |
57 | |
58 | // Process was running, but is finished now |
59 | if (last_state == PROCESS_STATE.RUNNING && |
60 | new_state != PROCESS_STATE.RUNNING) { |
61 | if (isHpt ){ |
62 | hpt += passedTime; |
63 | } |
64 | lastUpdateTime = currentTime; |
65 | } |
66 | |
67 | // Process was not running, but starts now |
68 | if (last_state != PROCESS_STATE.RUNNING && |
69 | new_state == PROCESS_STATE.RUNNING) { |
70 | if (passedTime > threshold){ |
71 | isHpt = false; |
72 | } |
73 | lastUpdateTime = currentTime; |
74 | } |
75 | last_state = new_state; |
76 | } |
77 | } |
78 | } |