source: xssim/branches/tpiontek/src/test/rewolucja/resources/physical/implementation/ComputingNode.java @ 197

Revision 197, 3.7 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.List;
4import java.util.Properties;
5
6import schedframe.resources.units.Cost;
7import schedframe.resources.units.Memory;
8import schedframe.scheduling.utils.ResourceParameterName;
9import test.rewolucja.energy.extension.EnergyExtension;
10import test.rewolucja.energy.profile.PowerInterface;
11import test.rewolucja.energy.profile.implementation.ComputingNodePowerProfile;
12import test.rewolucja.extensions.ExtensionType;
13import test.rewolucja.resources.Category;
14import test.rewolucja.resources.ResourceStatus;
15import test.rewolucja.resources.ResourceType;
16import test.rewolucja.resources.description.ExecResourceDescription;
17import test.rewolucja.resources.physical.base.ComputingResource;
18import test.rewolucja.resources.properties.ComputingNodePropertiesBuilder;
19import test.rewolucja.resources.properties.PropertiesDirector;
20
21public class ComputingNode extends ComputingResource{
22       
23        Category category;
24
25        public ComputingNode (ExecResourceDescription resDesc) {
26                super(resDesc);
27                category = resDesc.getCategory();
28                accept(resDesc.getPowerProfile());     
29        }
30       
31        /*public ComputingNode (String resourceName, ResourceCharacteristics resourceCharacteristic, Category cat, PowerInterface powerInterface) {
32                super(resourceName, ResourceType.COMPUTING_NODE, resourceCharacteristic);
33                category = cat;
34                accept(powerInterface);
35        //      extensionList.add(new EnergyExtension(this, "example.energy.ComputingNodeEnergyEstimationPlugin"));
36        }*/
37       
38       
39        public ComputingNodePowerProfile getPowerInterface(){
40                ComputingNodePowerProfile powerProfile = null;
41                if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){
42                        EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION);
43                        powerProfile = (ComputingNodePowerProfile)ee.getPowerInterface();
44                }
45                return powerProfile;
46        }
47
48        @SuppressWarnings("unchecked")
49        public List<Processor> getProcessors(){
50                try {
51                        return (List<Processor>) getDescendantsByType(ResourceType.CPU);
52                } catch (Exception e) {
53                        // TODO Auto-generated catch block
54                        e.printStackTrace();
55                }
56                return null;
57        }
58       
59        @SuppressWarnings("unchecked")
60        public List<Processor> getFreeProcessors(){
61                try {
62                        return (List<Processor>) getDescendantsByTypeAndStatus(ResourceType.CPU, ResourceStatus.FREE);
63                } catch (Exception e) {
64                        // TODO Auto-generated catch block
65                        e.printStackTrace();
66                }
67                return null;
68        }
69
70        public int getProcessorsNumber() {
71                return getProcessors().size();
72        }
73
74        public int getFreeProcessorsNumber() {
75                return getFreeProcessors().size();
76        }
77       
78       
79        //MEMORY
80        public int getFreeMemory() {
81                return getMemoryUnit().getFreeAmount();
82        }
83       
84        public int getTotalMemory() {
85                return getMemoryUnit().getAmount();
86        }
87
88        public boolean isMemRequirementSatisfied(int memoryReq) {
89                if (getFreeMemory() < memoryReq)
90                        return false;
91                return true;
92        }
93       
94        public Memory getMemoryUnit() {
95                return (Memory)resourceCharacteristic.getResourceUnit(ResourceParameterName.MEMORY);
96        }
97       
98        //COST
99        public int getProcessingCost() {
100                return getCostUnit().getAmount();
101        }
102       
103        private Cost getCostUnit() {
104                return (Cost) getResourceCharacteristic().getResourceUnit(ResourceParameterName.COST);
105        }
106       
107        public Category getCategory() {
108                return category;
109        }
110       
111        /*public void initCharacteristics(ExecResourceDescription resDesc){
112
113        }*/
114       
115        public Properties getProperties(){
116                PropertiesDirector propDirector = new PropertiesDirector();
117                propDirector.setPropertiesBuilder(new ComputingNodePropertiesBuilder());
118                propDirector.constructProperties(this);
119                return propDirector.getProperties();
120        }
121       
122        public void accept(PowerInterface powIntVis){
123                extensionList.add(new EnergyExtension(this, powIntVis, "example.energy.ComputingNodeEnergyEstimationPlugin"));
124                powIntVis.visit(this);
125        }
126}
Note: See TracBrowser for help on using the repository browser.