1 | package schedframe.resources.devices; |
---|
2 | |
---|
3 | import schedframe.Initializable; |
---|
4 | import schedframe.events.EventHandler; |
---|
5 | import schedframe.resources.Resource; |
---|
6 | import schedframe.resources.ResourceStatus; |
---|
7 | import schedframe.resources.ResourceType; |
---|
8 | import schedframe.resources.computing.ResourceCharacteristics; |
---|
9 | import schedframe.resources.computing.extensions.Extension; |
---|
10 | import schedframe.resources.computing.extensions.ExtensionList; |
---|
11 | import schedframe.resources.computing.extensions.ExtensionListImpl; |
---|
12 | import schedframe.resources.computing.extensions.ExtensionType; |
---|
13 | import schedframe.resources.computing.profiles.energy.EnergyExtension; |
---|
14 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
15 | import schedframe.resources.computing.profiles.energy.airthroughput.ui.AirflowInterface; |
---|
16 | import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface; |
---|
17 | import schedframe.resources.computing.profiles.energy.thermal.ui.ThermalInterface; |
---|
18 | import schedframe.resources.computing.profiles.load.LoadExtension; |
---|
19 | import schedframe.resources.computing.profiles.load.ui.LoadInterface; |
---|
20 | |
---|
21 | public abstract class PhysicalResource implements Resource, Initializable{ |
---|
22 | |
---|
23 | protected String name; |
---|
24 | protected ResourceType type; |
---|
25 | protected String category; |
---|
26 | protected ResourceStatus status; |
---|
27 | protected ResourceCharacteristics resourceCharacteristic; |
---|
28 | protected ExtensionList extensionList; |
---|
29 | |
---|
30 | |
---|
31 | public abstract void handleEvent(ResourceEvent event); |
---|
32 | |
---|
33 | public abstract EventHandler getEventHandler(); |
---|
34 | |
---|
35 | public String getName() { |
---|
36 | return name; |
---|
37 | } |
---|
38 | |
---|
39 | public ResourceType getType() { |
---|
40 | return type; |
---|
41 | } |
---|
42 | |
---|
43 | public String getCategory(){ |
---|
44 | return category; |
---|
45 | } |
---|
46 | |
---|
47 | public abstract void setStatus(ResourceStatus newStatus); |
---|
48 | |
---|
49 | public ResourceStatus getStatus() { |
---|
50 | return status; |
---|
51 | } |
---|
52 | |
---|
53 | private Extension getExtension(ExtensionType type){ |
---|
54 | if (extensionList != null) { |
---|
55 | for (Extension extension : extensionList) { |
---|
56 | if (extension.getType() == type) { |
---|
57 | return extension; |
---|
58 | } |
---|
59 | } |
---|
60 | } |
---|
61 | return null; |
---|
62 | } |
---|
63 | |
---|
64 | public PowerInterface getPowerInterface(){ |
---|
65 | Extension extension = getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
66 | if(extension != null){ |
---|
67 | EnergyExtension ee = (EnergyExtension)extension; |
---|
68 | return ee.getPowerInterface(); |
---|
69 | } |
---|
70 | return null; |
---|
71 | } |
---|
72 | |
---|
73 | public AirflowInterface getAirflowInterface(){ |
---|
74 | Extension extension = getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
75 | if(extension != null){ |
---|
76 | EnergyExtension ee = (EnergyExtension)extension; |
---|
77 | return ee.getAirflowInterface(); |
---|
78 | } |
---|
79 | return null; |
---|
80 | } |
---|
81 | |
---|
82 | public ThermalInterface getThermalInterface(){ |
---|
83 | Extension extension = getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
84 | if(extension != null){ |
---|
85 | EnergyExtension ee = (EnergyExtension)extension; |
---|
86 | return ee.getThermalInterface(); |
---|
87 | } |
---|
88 | return null; |
---|
89 | } |
---|
90 | |
---|
91 | public LoadInterface getLoadInterface(){ |
---|
92 | Extension extension = getExtension(ExtensionType.LOAD_EXTENSION); |
---|
93 | if(extension != null){ |
---|
94 | LoadExtension le = (LoadExtension)extension; |
---|
95 | return le.getLoadInterface(); |
---|
96 | } |
---|
97 | return null; |
---|
98 | } |
---|
99 | |
---|
100 | public ExtensionList getExtensionList() { |
---|
101 | if(extensionList == null){ |
---|
102 | return new ExtensionListImpl(0); |
---|
103 | } |
---|
104 | return extensionList; |
---|
105 | } |
---|
106 | |
---|
107 | protected void accept(Extension e){ |
---|
108 | extensionList.add(e); |
---|
109 | } |
---|
110 | |
---|
111 | public ResourceCharacteristics getResourceCharacteristic() { |
---|
112 | return resourceCharacteristic; |
---|
113 | } |
---|
114 | |
---|
115 | } |
---|