source: DCWoRMS/trunk/src/schedframe/resources/computing/profiles/energy/airthroughput/ui/ComputingResourceAirThroughputInterface.java @ 754

Revision 754, 3.2 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.computing.profiles.energy.airthroughput.ui;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import schedframe.Parameters;
7import schedframe.resources.computing.ComputingResource;
8import schedframe.resources.computing.profiles.energy.EnergyEvent;
9import schedframe.resources.computing.profiles.energy.EnergyEventType;
10import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputProfile;
11import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputState;
12import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputStateName;
13import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirThroughputStateName;
14
15public 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}
Note: See TracBrowser for help on using the repository browser.