1 | package schedframe.resources.units; |
---|
2 | |
---|
3 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
4 | |
---|
5 | public class Processors extends ResourceUnit { |
---|
6 | |
---|
7 | protected int total; |
---|
8 | protected int used; |
---|
9 | protected int peSpeed; |
---|
10 | |
---|
11 | protected Processors(){ |
---|
12 | super(ResourceParameterName.CPUCOUNT); |
---|
13 | this.peSpeed = 1; |
---|
14 | } |
---|
15 | |
---|
16 | public Processors(int total, int used, int avgSpeed){ |
---|
17 | this(); |
---|
18 | this.total = total; |
---|
19 | this.used = used; |
---|
20 | this.peSpeed = avgSpeed; |
---|
21 | } |
---|
22 | |
---|
23 | public Processors(String resId, int total, int used) { |
---|
24 | super(resId, ResourceParameterName.CPUCOUNT); |
---|
25 | this.total = total; |
---|
26 | this.used = used; |
---|
27 | this.peSpeed = 1; |
---|
28 | } |
---|
29 | |
---|
30 | public void setProcessorSpeed(int speed) { |
---|
31 | this.peSpeed = speed; |
---|
32 | } |
---|
33 | |
---|
34 | public int getProcessorSpeed(){ |
---|
35 | return this.peSpeed; |
---|
36 | } |
---|
37 | |
---|
38 | public int getFreeAmount() { |
---|
39 | return this.total - this.used; |
---|
40 | } |
---|
41 | |
---|
42 | public int getUsedAmount(){ |
---|
43 | return this.used; |
---|
44 | } |
---|
45 | |
---|
46 | public int getAmount(){ |
---|
47 | return this.total; |
---|
48 | } |
---|
49 | |
---|
50 | public void setUsedAmount(int amount) { |
---|
51 | this.used = amount; |
---|
52 | } |
---|
53 | |
---|
54 | public void reset(){ |
---|
55 | this.used = 0; |
---|
56 | } |
---|
57 | |
---|
58 | public ResourceUnit toDiscrete(){ |
---|
59 | throw new UnsupportedOperationException(); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /** |
---|
64 | * Compares processing power of the free processors, which is calculated as product |
---|
65 | * of {@link #getAmount()} * {@link #getProcessorSpeed()} |
---|
66 | * Returns a negative integer, zero, or a positive integer as this object is less |
---|
67 | * than, equal to, or greater than the specified object |
---|
68 | */ |
---|
69 | public int compareTo(ResourceUnit o) { |
---|
70 | if(o instanceof Processors){ |
---|
71 | Processors p = (Processors) o; |
---|
72 | int p_power = p.getAmount() * p.getProcessorSpeed(); |
---|
73 | int power = this.getAmount() * this.getProcessorSpeed(); |
---|
74 | if(power < p_power) return -1; |
---|
75 | if(power > p_power) return 1; |
---|
76 | return 0; |
---|
77 | } else { |
---|
78 | throw new ClassCastException(); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | public boolean equals(Object o){ |
---|
83 | if(o instanceof Processors){ |
---|
84 | if(!super.equals(o)) |
---|
85 | return false; |
---|
86 | Processors p = (Processors) o; |
---|
87 | if(p.getProcessorSpeed() != this.getProcessorSpeed()) return false; |
---|
88 | return true; |
---|
89 | } else { |
---|
90 | return false; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | } |
---|