source: xssim/trunk/src/test/rewolucja/resources/physical/implementation/CPU.java @ 104

Revision 104, 2.6 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.rewolucja.resources.physical.implementation;
2
3import java.util.Properties;
4
5import schedframe.resources.units.CpuSpeed;
6import schedframe.scheduling.utils.ResourceParameterName;
7import test.rewolucja.energy.extension.EnergyExtension;
8import test.rewolucja.energy.profile.CPUPowerProfile;
9import test.rewolucja.energy.profile.PowerInterface;
10import test.rewolucja.extensions.ExtensionType;
11import test.rewolucja.resources.ResourceCharacteristics;
12import test.rewolucja.resources.ResourceStatus;
13import test.rewolucja.resources.description.ExecResourceDescription;
14import test.rewolucja.resources.physical.base.ComputingResource;
15import test.rewolucja.resources.properties.CpuPropertiesBuilder;
16import test.rewolucja.resources.properties.PropertiesDirector;
17
18public class CPU extends ComputingResource{
19       
20
21        public CPU (ExecResourceDescription resDesc) {
22                super(resDesc);
23                accept(resDesc.getPowerProfile());
24        }
25       
26        /*public CPU (String resourceName, ResourceCharacteristics resourceCharacteristic) {
27                super(resourceName, ResourceType.CPU, resourceCharacteristic);
28                extensionList.add(new EnergyExtension(this, "example.energy.CPUEnergyEstimationPlugin"));
29        }*/
30
31        public ComputingNode getComputingNode(){
32                return (ComputingNode)parent;
33        }
34       
35        public double getUtilization(){
36                if(getStatus() == ResourceStatus.BUSY)
37                        return 1;
38                else
39                        return 0;
40        }
41       
42        public int getMIPS(){
43                return getProcessorSpeed().getAmount();
44        }
45       
46        public int getAvailableMIPS(){
47                return getProcessorSpeed().getFreeAmount();
48        }
49
50        protected CpuSpeed getProcessorSpeed(){
51                return (CpuSpeed) getResourceCharacteristic().getResourceUnit(ResourceParameterName.CPUSPEED);
52        }
53       
54        public CPUPowerProfile getPowerInterface(){
55                if (extensionList != null) {
56                        if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){
57                                EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION);
58                                return (CPUPowerProfile)ee.getPowerInterface();
59                        }
60                }
61                return null;
62        }
63       
64        public void initCharacteristics(ExecResourceDescription resDesc){
65                resourceCharacteristic = new ResourceCharacteristics();
66                resourceCharacteristic.addResourceUnit(new CpuSpeed(name, 1, 0));
67        }
68       
69        public Properties getProperties(){
70                PropertiesDirector propDirector = new PropertiesDirector();
71                propDirector.setPropertiesBuilder(new CpuPropertiesBuilder());
72                propDirector.constructProperties(this);
73                return propDirector.getProperties();
74        }
75
76        public void accept(PowerInterface powIntVis){
77                extensionList.add(new EnergyExtension(this, powIntVis, "example.energy.CPUEnergyEstimationPlugin"));
78                powIntVis.visit(this);
79        }
80}
81
Note: See TracBrowser for help on using the repository browser.