source: DCWoRMS/branches/coolemall/src/schedframe/resources/devices/DeviceAirflowInterface.java @ 1396

Revision 1396, 3.5 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.devices;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.joda.time.DateTimeUtils;
7
8import schedframe.Parameters;
9import schedframe.resources.computing.profiles.energy.EnergyEvent;
10import schedframe.resources.computing.profiles.energy.EnergyEventType;
11import schedframe.resources.computing.profiles.energy.airthroughput.AirflowValue;
12import schedframe.resources.computing.profiles.energy.airthroughput.AirflowProfile;
13import schedframe.resources.computing.profiles.energy.airthroughput.AirflowState;
14import schedframe.resources.computing.profiles.energy.airthroughput.AirflowStateName;
15import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirflowStateName;
16import schedframe.resources.computing.profiles.energy.airthroughput.ui.AirflowInterface;
17
18public class DeviceAirflowInterface implements AirflowInterface{
19
20        protected AirflowStateName currentAirflowState;
21        protected AirflowProfile airflowProfile;
22        protected PhysicalResource resource;
23       
24        public DeviceAirflowInterface(PhysicalResource resource, AirflowProfile airflowProfile){
25                this.resource = resource;
26                this.airflowProfile = airflowProfile;
27                this.currentAirflowState = StandardAirflowStateName.ON;
28        }
29       
30        public AirflowStateName getAirflowState() {
31                return currentAirflowState;
32        }
33
34        public boolean setAirflowState(AirflowStateName state) {
35                if(supportAirflowState(state)){
36                        currentAirflowState = state;
37                       
38                        //TO DO - notifications should be called for all resources starting form the lowest layer
39                        resource.handleEvent(new EnergyEvent(EnergyEventType.AIRFLOW_STATE_CHANGED, resource.getFullName()));
40                        resource.handleEvent(new EnergyEvent(EnergyEventType.POWER_STATE_CHANGED, resource.getFullName()));
41                        return true;
42                }
43                return false;
44        }
45
46        public boolean supportAirflowState(AirflowStateName state) {
47                for(AirflowState airflowState: airflowProfile.getAirflowStates()){
48                        if(airflowState.getName().getLabel().equals(state.getLabel())){
49                                return true;
50                        }
51                }
52                return false;
53        }
54
55        public List<AirflowState> getSupportedAirflowStates(){
56                List<AirflowState> airflowStates = new ArrayList<AirflowState>();
57                for(AirflowState airFlowState: airflowProfile.getAirflowStates()){
58                        airflowStates.add(airFlowState);
59                }
60                return airflowStates;
61        }
62
63        public double getAirflow(AirflowStateName state) throws NoSuchFieldException {
64                double airflow = 0;
65                if(supportAirflowState(state)){
66                        for(AirflowState airflowState: airflowProfile.getAirflowStates()){
67                                if(airflowState.getName().getLabel().equals(state.getLabel())){
68                                        airflow = airflowState.getValue();
69                                        break;
70                                }
71                        }
72                }
73                return airflow;
74        }
75
76        public double getPowerConsumption(AirflowStateName state) throws NoSuchFieldException {
77                double powerConsumption = 0;
78                if(supportAirflowState(state)){
79                        for(AirflowState airflowState: airflowProfile.getAirflowStates()){
80                                if(airflowState.getName().getLabel().equals(state.getLabel())){
81                                        powerConsumption = airflowState.getPowerUsage();
82                                        break;
83                                }
84                        }
85                }
86                return powerConsumption;
87        }
88       
89        public AirflowValue getRecentAirflow() {
90                AirflowValue airflow = null;
91                int lastIdx = getAirflowHistory().size() - 1;
92                if(lastIdx >= 0)
93                        airflow = getAirflowHistory().get(lastIdx);
94                else { 
95                        try {
96                                airflow = new AirflowValue(DateTimeUtils.currentTimeMillis(), getAirflow(currentAirflowState));
97                        } catch (NoSuchFieldException e) {
98                        }
99                }
100                return airflow;
101        }
102       
103        public List<AirflowValue> getAirflowHistory(){
104                return airflowProfile.getAirflowHistory();
105        }
106       
107        public Parameters getParameters() {
108                return airflowProfile.getParameters();
109        }
110
111}
Note: See TracBrowser for help on using the repository browser.