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

Revision 1247, 2.2 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.computing;
2
3import schedframe.resources.StandardResourceType;
4import schedframe.resources.computing.description.ComputingResourceDescription;
5import schedframe.resources.units.CpuSpeed;
6import schedframe.resources.units.StandardResourceUnitName;
7
8public class Core extends ComputingResource{
9       
10
11        public Core (ComputingResourceDescription resDesc) {
12                super(resDesc);
13                //PowerInterface pi = PowerInterfaceFactory.createPowerInterface(this, resDesc.getPowerProfile());
14                //accept(new EnergyExtension(pi, resDesc.getPowerProfile()));   
15        }
16
17        public Processor getProcessor(){
18                ComputingResource compRes = parent;
19                while(compRes != null && !compRes.getType().equals(StandardResourceType.Processor)){
20                        compRes = compRes.getParent();
21                }
22                Processor proc = null;
23                try{
24                        proc = (Processor)compRes;
25                } catch(ClassCastException e) {
26                }
27                return proc;
28        }
29       
30        public Node getNode(){
31                ComputingResource compRes = parent;
32                while(compRes != null && !compRes.getType().equals(StandardResourceType.Node)){
33                        compRes = compRes.getParent();
34                }
35                Node compNode = null;
36                try{
37                        compNode = (Node)compRes;
38                } catch(ClassCastException e) {
39                }
40                return compNode;
41        }
42       
43        public int getMIPS(){
44                int mips;
45                try {
46                        mips = getSpeedUnit().getAmount();
47                } catch (NoSuchFieldException e) {
48                        mips = 1;
49                }
50                return mips;
51        }
52       
53        public int getAvailableMIPS(){
54                int mips;
55                try {
56                        mips = getSpeedUnit().getFreeAmount();
57                } catch (NoSuchFieldException e) {
58                        mips = 1;
59                }
60                return mips;
61        }
62
63        private CpuSpeed getSpeedUnit() throws NoSuchFieldException{
64                return (CpuSpeed) ((ComputingResourceCharacteristics)resourceCharacteristic).getResourceUnit(StandardResourceUnitName.CPUSPEED);
65        }
66
67        public void initCharacteristics(ComputingResourceDescription resDesc){
68                super.initCharacteristics(resDesc);
69                try{
70                        ((ComputingResourceCharacteristics)resourceCharacteristic).addResourceUnit(new CpuSpeed(name, Integer.valueOf(resDesc.getCompResourceParameterValue("speed")) * 1, 0));
71                } catch(Exception e){
72                        ((ComputingResourceCharacteristics)resourceCharacteristic).addResourceUnit(new CpuSpeed(name,  1, 0));
73                }
74        }
75
76        /*private void accept(EnergyExtension e){
77                extensionList.add(e);
78                e.setResource(this);
79        }*/
80}
81
Note: See TracBrowser for help on using the repository browser.