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

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