package schedframe.resources.devices; import java.util.ArrayList; import java.util.List; import org.joda.time.DateTimeUtils; import schedframe.Parameters; import schedframe.resources.computing.profiles.energy.EnergyEvent; import schedframe.resources.computing.profiles.energy.EnergyEventType; import schedframe.resources.computing.profiles.energy.airthroughput.AirFlowValue; import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputProfile; import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputState; import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputStateName; import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirThroughputStateName; import schedframe.resources.computing.profiles.energy.airthroughput.ui.AirThroughputInterface; public class DeviceAirThroughputInterface implements AirThroughputInterface{ protected AirThroughputStateName currentAirThroughputState; protected AirThroughputProfile airThroughputProfile; protected PhysicalResource resource; public DeviceAirThroughputInterface(PhysicalResource resource, AirThroughputProfile airThroughputProfile){ this.resource = resource; this.airThroughputProfile = airThroughputProfile; this.currentAirThroughputState = StandardAirThroughputStateName.ON; } public AirThroughputStateName getAirThroughputState() { return currentAirThroughputState; } public boolean setAirThroughputState(AirThroughputStateName state) { if(supportAirThroughputState(state)){ currentAirThroughputState = state; //TO DO - notifications should be called for all resources starting form the lowest layer resource.handleEvent(new EnergyEvent(EnergyEventType.AIRFLOW_STATE_CHANGED, resource.getFullName())); resource.handleEvent(new EnergyEvent(EnergyEventType.POWER_STATE_CHANGED, resource.getFullName())); return true; } return false; } public boolean supportAirThroughputState(AirThroughputStateName state) { for(AirThroughputState airFlowState: airThroughputProfile.getAirThroughputStates()){ if(airFlowState.getName().equals(state.getName())){ return true; } } return false; } public List getSupportedAirThroughputStates(){ List airThroughputStates = new ArrayList(); for(AirThroughputState airFlowState: airThroughputProfile.getAirThroughputStates()){ airThroughputStates.add(airFlowState); } return airThroughputStates; } public double getAirFlow(AirThroughputStateName state) throws NoSuchFieldException { double airThroughput = 0; if(supportAirThroughputState(state)){ for(AirThroughputState airFlowState: airThroughputProfile.getAirThroughputStates()){ if(airFlowState.getName().equals(state.getName())){ airThroughput = airFlowState.getValue(); break; } } } return airThroughput; } public double getPowerConsumption(AirThroughputStateName state) throws NoSuchFieldException { double powerConsumption = 0; if(supportAirThroughputState(state)){ for(AirThroughputState airFlowState: airThroughputProfile.getAirThroughputStates()){ if(airFlowState.getName().equals(state.getName())){ 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(currentAirThroughputState)); } catch (NoSuchFieldException e) { } } return airFlow; } public List getAirFlowHistory(){ return airThroughputProfile.getAirThroughputHistory(); } public Parameters getParameters() { return airThroughputProfile.getParameters(); } }