1 | package schedframe.resources.computing; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | import java.util.Properties; |
---|
5 | |
---|
6 | import schedframe.resources.ResourceStatus; |
---|
7 | import schedframe.resources.StandardResourceType; |
---|
8 | import schedframe.resources.computing.description.ComputingResourceDescription; |
---|
9 | import schedframe.resources.computing.extensions.ExtensionType; |
---|
10 | import schedframe.resources.computing.profiles.energy.EnergyExtension; |
---|
11 | import schedframe.resources.computing.profiles.energy.power.PowerInterfaceFactory; |
---|
12 | import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface; |
---|
13 | import schedframe.resources.computing.profiles.energy.power.ui.ProcessorPowerInterface; |
---|
14 | import schedframe.resources.computing.properties.CpuPropertiesBuilder; |
---|
15 | import schedframe.resources.computing.properties.PropertiesDirector; |
---|
16 | import schedframe.resources.units.CpuSpeed; |
---|
17 | import schedframe.resources.units.StandardResourceUnitName; |
---|
18 | |
---|
19 | public 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 | |
---|