1 | package schedframe.resources.computing.profiles.energy.airthroughput.ui; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import schedframe.Parameters; |
---|
7 | import schedframe.resources.computing.ComputingResource; |
---|
8 | import schedframe.resources.computing.profiles.energy.EnergyEvent; |
---|
9 | import schedframe.resources.computing.profiles.energy.EnergyEventType; |
---|
10 | import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputProfile; |
---|
11 | import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputState; |
---|
12 | import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputStateName; |
---|
13 | import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirThroughputStateName; |
---|
14 | |
---|
15 | public class ComputingResourceAirThroughputInterface implements AirThroughputInterface{ |
---|
16 | |
---|
17 | protected AirThroughputStateName currentAirThroughputState; |
---|
18 | protected AirThroughputProfile airThroughputProfile; |
---|
19 | protected ComputingResource resource; |
---|
20 | |
---|
21 | public ComputingResourceAirThroughputInterface(ComputingResource resource, AirThroughputProfile airThroughputProfile){ |
---|
22 | this.resource = resource; |
---|
23 | this.airThroughputProfile = airThroughputProfile; |
---|
24 | this.currentAirThroughputState = StandardAirThroughputStateName.FAN_ON; |
---|
25 | } |
---|
26 | |
---|
27 | public AirThroughputStateName getAirThroughputState() { |
---|
28 | return currentAirThroughputState; |
---|
29 | } |
---|
30 | |
---|
31 | public boolean setAirThroughputState(AirThroughputStateName state) { |
---|
32 | if(supportAirThroughputState(state)){ |
---|
33 | currentAirThroughputState = state; |
---|
34 | |
---|
35 | //TO DO - notifications should be called for all resources starting form the lowest layer |
---|
36 | resource.handleEvent(new EnergyEvent(EnergyEventType.AIRFLOW_STATE_CHANGED, resource.getName())); |
---|
37 | return true; |
---|
38 | } |
---|
39 | return false; |
---|
40 | } |
---|
41 | |
---|
42 | public boolean supportAirThroughputState(AirThroughputStateName state) { |
---|
43 | for(AirThroughputState airFlowState: airThroughputProfile.getAirThroughputStates()){ |
---|
44 | if(airFlowState.getName().equals(state.getName())){ |
---|
45 | return true; |
---|
46 | } |
---|
47 | } |
---|
48 | return false; |
---|
49 | } |
---|
50 | |
---|
51 | public List<AirThroughputState> getSupportedAirThroughputStates() throws NoSuchFieldException { |
---|
52 | List<AirThroughputState> airThroughputStates = new ArrayList<AirThroughputState>(); |
---|
53 | for(AirThroughputState airFlowState: airThroughputProfile.getAirThroughputStates()){ |
---|
54 | airThroughputStates.add(airFlowState); |
---|
55 | } |
---|
56 | return airThroughputStates; |
---|
57 | } |
---|
58 | |
---|
59 | public double getAirFlow(AirThroughputStateName state) throws NoSuchFieldException { |
---|
60 | double airThroughput = 0; |
---|
61 | if(supportAirThroughputState(state)){ |
---|
62 | for(AirThroughputState airFlowState: airThroughputProfile.getAirThroughputStates()){ |
---|
63 | if(airFlowState.getName().equals(state.getName())){ |
---|
64 | airThroughput = airFlowState.getValue(); |
---|
65 | break; |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | return airThroughput; |
---|
70 | } |
---|
71 | |
---|
72 | public double getPowerConsumption(AirThroughputStateName state) throws NoSuchFieldException { |
---|
73 | double powerConsumption = 0; |
---|
74 | if(supportAirThroughputState(state)){ |
---|
75 | for(AirThroughputState airFlowState: airThroughputProfile.getAirThroughputStates()){ |
---|
76 | if(airFlowState.getName().equals(state.getName())){ |
---|
77 | powerConsumption = airFlowState.getPowerUsage(); |
---|
78 | break; |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | return powerConsumption; |
---|
83 | } |
---|
84 | |
---|
85 | public Parameters getParameters() { |
---|
86 | return airThroughputProfile.getParameters(); |
---|
87 | } |
---|
88 | |
---|
89 | } |
---|