1 | package de.uka.ipd.sdq.scheduler.timeslice.impl; |
2 | |
3 | import de.uka.ipd.sdq.probfunction.math.util.MathTools; |
4 | import de.uka.ipd.sdq.scheduler.timeslice.ITimeSlice; |
5 | |
6 | |
7 | public class ContinuousTimeSlice implements ITimeSlice { |
8 | |
9 | protected double remaining_time; |
10 | protected double timeslice; |
11 | |
12 | public ContinuousTimeSlice(double timeslice) { |
13 | super(); |
14 | this.timeslice = timeslice; |
15 | this.remaining_time = 0; |
16 | } |
17 | |
18 | protected ContinuousTimeSlice(){ |
19 | this.timeslice = 0; |
20 | this.remaining_time = 0; |
21 | } |
22 | |
23 | public boolean isFinished() { |
24 | return MathTools.equalsDouble(remaining_time, 0.0); |
25 | } |
26 | |
27 | |
28 | public void substractTime(double time) { |
29 | remaining_time -= time; |
30 | assert MathTools.lessOrEqual(0.0, remaining_time) : "Timeslice exceeded: " + remaining_time; |
31 | } |
32 | |
33 | |
34 | public void fullReset() { |
35 | remaining_time = timeslice; |
36 | } |
37 | |
38 | |
39 | public double getRemainingTime() { |
40 | return remaining_time; |
41 | } |
42 | |
43 | |
44 | public void punish(int penalty) { |
45 | double time = Math.min(penalty, remaining_time); |
46 | substractTime(time); |
47 | } |
48 | |
49 | |
50 | public void setExpired() { |
51 | this.remaining_time = 0; |
52 | |
53 | } |
54 | |
55 | @Override |
56 | public ITimeSlice clone() { |
57 | ContinuousTimeSlice cts = new ContinuousTimeSlice(); |
58 | cts.timeslice = this.timeslice; |
59 | cts.remaining_time = this.remaining_time; |
60 | return cts; |
61 | } |
62 | |
63 | |
64 | public void halfReset() { |
65 | } |
66 | |
67 | public void updateTimeForBoosting() { |
68 | } |
69 | |
70 | public void updateTimeForScheduling() { |
71 | } |
72 | } |