source: DCWoRMS/trunk/src/schedframe/resources/computing/Processor.java @ 495

Revision 495, 3.0 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.computing;
2
3import java.util.List;
4import java.util.Properties;
5
6import schedframe.resources.StandardResourceType;
7import schedframe.resources.computing.description.ComputingResourceDescription;
8import schedframe.resources.computing.extensions.ExtensionType;
9import schedframe.resources.computing.profiles.energy.EnergyExtension;
10import schedframe.resources.computing.profiles.energy.power.PowerInterfaceFactory;
11import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface;
12import schedframe.resources.computing.profiles.energy.power.ui.ProcessorPowerInterface;
13import schedframe.resources.computing.properties.CpuPropertiesBuilder;
14import schedframe.resources.computing.properties.PropertiesDirector;
15import schedframe.resources.units.CpuSpeed;
16import schedframe.resources.units.StandardResourceUnitName;
17
18public class Processor extends ComputingResource{
19       
20
21        public Processor (ComputingResourceDescription resDesc) {
22                super(resDesc);
23                //extensionList.add(new EnergyExtension(this, resDesc.getPowerInterface(), resDesc.getEnergyEstimationPlugin()));
24                PowerInterface pi = PowerInterfaceFactory.createPowerInterface(this, resDesc.getPowerProfile());
25                accept(new EnergyExtension(pi, resDesc.getPowerProfile()));     
26        }
27
28
29        public ComputingNode getComputingNode(){
30                return (ComputingNode)parent;
31        }
32       
33        @SuppressWarnings("unchecked")
34        public List<Core> getCores(){
35                return (List<Core>) getDescendantsByType(StandardResourceType.Core);
36        }
37       
38        public int getMIPS(){
39                int mips;
40                try {
41                        mips = getSpeedUnit().getAmount();
42                } catch (NoSuchFieldException e) {
43                        mips = 1;
44                }
45                return mips;
46        }
47       
48        public int getAvailableMIPS(){
49                int mips;
50                try {
51                        mips = getSpeedUnit().getFreeAmount();
52                } catch (NoSuchFieldException e) {
53                        mips = 1;
54                }
55                return mips;
56        }
57
58        private CpuSpeed getSpeedUnit() throws NoSuchFieldException{
59                return (CpuSpeed) resourceCharacteristic.getResourceUnit(StandardResourceUnitName.CPUSPEED);
60        }
61       
62        public ProcessorPowerInterface getPowerInterface(){
63                if (extensionList != null) {
64                        if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){
65                                EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION);
66                                return (ProcessorPowerInterface)ee.getPowerInterface();
67                        }
68                }
69                return null;
70        }
71       
72        public void initCharacteristics(ComputingResourceDescription resDesc){
73                //resourceCharacteristic = new ResourceCharacteristics.Builder().resourceUnits().build();
74                super.initCharacteristics(resDesc);
75                try{
76                        resourceCharacteristic.addResourceUnit(new CpuSpeed(name, Integer.valueOf(resDesc.getCompResourceParameterValue("speed")) * 1, 0));
77                } catch(Exception e){
78                        resourceCharacteristic.addResourceUnit(new CpuSpeed(name,  1, 0));
79                }
80        }
81       
82        public Properties getProperties(){
83                PropertiesDirector propDirector = new PropertiesDirector();
84                propDirector.setPropertiesBuilder(new CpuPropertiesBuilder());
85                propDirector.constructProperties(this);
86                return propDirector.getProperties();
87        }
88
89        public void accept(EnergyExtension e){
90                extensionList.add(e);
91                e.setResource(this);
92        }
93}
94
Note: See TracBrowser for help on using the repository browser.