package schedframe.resources.devices; import java.util.List; import org.joda.time.DateTimeUtils; import schedframe.Parameters; import schedframe.resources.computing.profiles.energy.ResourceEvent; import schedframe.resources.computing.profiles.energy.ResourceEventType; import schedframe.resources.computing.profiles.energy.airthroughput.AirflowValue; import schedframe.resources.computing.profiles.energy.airthroughput.AirflowProfile; import schedframe.resources.computing.profiles.energy.airthroughput.AirflowState; import schedframe.resources.computing.profiles.energy.airthroughput.AirflowStateName; import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirflowStateName; import schedframe.resources.computing.profiles.energy.airthroughput.ui.AirflowInterface; public class DeviceAirflowInterface implements AirflowInterface{ protected AirflowStateName currentAirflowState; protected AirflowProfile airflowProfile; protected PhysicalResource resource; public DeviceAirflowInterface(PhysicalResource resource, AirflowProfile airflowProfile){ this.resource = resource; this.airflowProfile = airflowProfile; this.currentAirflowState = StandardAirflowStateName.ON; } public AirflowStateName getAirflowState() { return currentAirflowState; } public boolean setAirflowState(AirflowStateName state) { if(supportAirflowState(state)){ currentAirflowState = state; //TO DO - notifications should be called for all resources starting form the lowest layer resource.handleEvent(new ResourceEvent(ResourceEventType.AIRFLOW_STATE_CHANGED, resource.getFullName())); resource.handleEvent(new ResourceEvent(ResourceEventType.POWER_STATE_CHANGED, resource.getFullName())); return true; } return false; } public boolean supportAirflowState(AirflowStateName state) { for(AirflowState airflowState: airflowProfile.getAirflowStates()){ if(airflowState.getName().getLabel().equals(state.getLabel())){ return true; } } return false; } public List getSupportedAirflowStates(){ return airflowProfile.getAirflowStates(); } public double getAirflow(AirflowStateName state) throws NoSuchFieldException { double airflow = 0; if(supportAirflowState(state)){ for(AirflowState airflowState: airflowProfile.getAirflowStates()){ if(airflowState.getName().getLabel().equals(state.getLabel())){ airflow = airflowState.getValue(); break; } } } return airflow; } public double getPowerConsumption(AirflowStateName state) throws NoSuchFieldException { double powerConsumption = 0; if(supportAirflowState(state)){ for(AirflowState airflowState: airflowProfile.getAirflowStates()){ if(airflowState.getName().getLabel().equals(state.getLabel())){ powerConsumption = airflowState.getPowerUsage(); break; } } } return powerConsumption; } public AirflowValue getRecentAirflow() { AirflowValue airflow = null; int lastIdx = getAirflowHistory().size() - 1; if(lastIdx >= 0) airflow = getAirflowHistory().get(lastIdx); else { try { airflow = new AirflowValue(DateTimeUtils.currentTimeMillis(), getAirflow(currentAirflowState)); } catch (NoSuchFieldException e) { } } return airflow; } public List getAirflowHistory(){ return airflowProfile.getAirflowHistory(); } public Parameters getParameters() { return airflowProfile.getParameters(); } }