[104] | 1 | package test.rewolucja.energy.profile; |
---|
| 2 | |
---|
| 3 | import java.util.Arrays; |
---|
| 4 | import java.util.List; |
---|
| 5 | |
---|
| 6 | import schedframe.resources.PowerState; |
---|
| 7 | import test.rewolucja.energy.extension.EnergyExtension; |
---|
| 8 | import test.rewolucja.extensions.ExtensionType; |
---|
| 9 | import test.rewolucja.resources.ResourceStatus; |
---|
| 10 | import test.rewolucja.resources.physical.base.ComputingResource; |
---|
| 11 | import test.rewolucja.resources.physical.implementation.ComputingNode; |
---|
| 12 | |
---|
| 13 | public class ComputingNodePowerProfile extends AbstractPowerProfile{ |
---|
| 14 | |
---|
| 15 | protected ComputingNode computingNode; |
---|
| 16 | |
---|
| 17 | public ComputingNodePowerProfile(){ |
---|
| 18 | powerState = PowerState.ON; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | public void visit(ComputingNode compNode){ |
---|
| 22 | computingNode = compNode; |
---|
| 23 | energyExtension = (EnergyExtension) computingNode.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | public boolean setPowerState(PowerState state){ |
---|
| 27 | if(!supportPowerState(state)) |
---|
| 28 | return false; |
---|
| 29 | powerState = state; |
---|
| 30 | if(computingNode.getProcessors() != null) |
---|
| 31 | { |
---|
| 32 | for(ComputingResource child:computingNode.getProcessors()){ |
---|
| 33 | child.getPowerInterface().setPowerState(state); |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | if(state == PowerState.OFF){ |
---|
| 37 | computingNode.setStatus(ResourceStatus.NOTAVAILABLE); |
---|
| 38 | } |
---|
| 39 | else if(state == PowerState.ON){ |
---|
| 40 | computingNode.setStatus(ResourceStatus.FREE); |
---|
| 41 | } |
---|
| 42 | return true; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | public double getPowerConsumption(PowerState state) { |
---|
| 46 | if(powerState == PowerState.OFF) |
---|
| 47 | return 0; |
---|
| 48 | else if(powerState == PowerState.ON) |
---|
| 49 | return 750; |
---|
| 50 | else return 500; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | public boolean supportPowerState(PowerState state) { |
---|
| 54 | switch(state){ |
---|
| 55 | case ON: |
---|
| 56 | return true; |
---|
| 57 | case OFF: |
---|
| 58 | return true; |
---|
| 59 | case SLEEP: |
---|
| 60 | return true; |
---|
| 61 | case HIBERNATE: |
---|
| 62 | return true; |
---|
| 63 | default: return false; |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | public List<PowerState> getSupportedPowerStates() { |
---|
| 68 | return Arrays.asList(new PowerState[]{PowerState.ON, PowerState.OFF, PowerState.SLEEP, PowerState.HIBERNATE}); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public void turnOn(){ |
---|
| 72 | setPowerState(PowerState.ON); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | public void turnOff(){ |
---|
| 76 | setPowerState(PowerState.OFF); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | } |
---|