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