source: xssim/trunk/src/test/rewolucja/resources/physical/implementation/ComputingNode.java @ 132

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