source: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/Processor.java @ 1247

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