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

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