1 | package schedframe.resources.computing.profiles.load; |
---|
2 | |
---|
3 | import java.util.Properties; |
---|
4 | |
---|
5 | import schedframe.events.Event; |
---|
6 | import schedframe.resources.computing.extensions.Extension; |
---|
7 | import schedframe.resources.computing.extensions.ExtensionException; |
---|
8 | import schedframe.resources.computing.extensions.ExtensionType; |
---|
9 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
10 | import schedframe.resources.computing.profiles.energy.ResourceEventType; |
---|
11 | import schedframe.resources.computing.profiles.load.ui.LoadInterface; |
---|
12 | import schedframe.resources.devices.PhysicalResource; |
---|
13 | import schedframe.scheduling.manager.tasks.JobRegistryImpl; |
---|
14 | |
---|
15 | public class LoadExtension implements Extension { |
---|
16 | |
---|
17 | protected LoadInterface loadInterface; |
---|
18 | protected LoadProfile loadProfile; |
---|
19 | protected PhysicalResource resource; |
---|
20 | |
---|
21 | public LoadExtension(LoadProfile loadProfile, PhysicalResource resource) { |
---|
22 | this.loadProfile = loadProfile; |
---|
23 | this.loadInterface = LoadInterfaceFactory.createLoadInterface(resource, loadProfile); |
---|
24 | this.resource = resource; |
---|
25 | } |
---|
26 | |
---|
27 | public boolean supportsEvent(Event event) { |
---|
28 | |
---|
29 | if(loadProfile == null || loadProfile.getLoadEstimationPlugin() == null) |
---|
30 | return false; |
---|
31 | if(event.getType().getName().equals(ResourceEventType.UTILIZATION_CHANGED.getName())) |
---|
32 | return true; |
---|
33 | else if(event.getType().getName().equals(ResourceEventType.TASK_STARTED.getName())) |
---|
34 | return true; |
---|
35 | else if(event.getType().getName().equals(ResourceEventType.TASK_FINISHED.getName())) |
---|
36 | return true; |
---|
37 | else if(event.getType().getName().equals(ResourceEventType.POWER_STATE_CHANGED.getName())) |
---|
38 | return true; |
---|
39 | else if(event.getType().getName().equals(ResourceEventType.CPU_FREQUENCY_CHANGED.getName())) |
---|
40 | return true; |
---|
41 | else return false; |
---|
42 | } |
---|
43 | |
---|
44 | public void handleEvent(Event event) { |
---|
45 | |
---|
46 | ResourceEvent resEvent = (ResourceEvent)event; |
---|
47 | double load = 0; |
---|
48 | try{ |
---|
49 | switch (resEvent.getType()) { |
---|
50 | |
---|
51 | case UTILIZATION_CHANGED: |
---|
52 | load = loadProfile.getLoadEstimationPlugin().estimateUtlization(resEvent, new JobRegistryImpl(resource.getFullName()), resource); |
---|
53 | loadProfile.addToLoadHistory(load); |
---|
54 | break; |
---|
55 | |
---|
56 | case TASK_STARTED: |
---|
57 | load = loadProfile.getLoadEstimationPlugin().estimateUtlization(resEvent, new JobRegistryImpl(resource.getFullName()), resource); |
---|
58 | loadProfile.addToLoadHistory(load); |
---|
59 | break; |
---|
60 | |
---|
61 | case TASK_FINISHED: |
---|
62 | load = loadProfile.getLoadEstimationPlugin().estimateUtlization(resEvent, new JobRegistryImpl(resource.getFullName()), resource); |
---|
63 | loadProfile.addToLoadHistory(load); |
---|
64 | break; |
---|
65 | |
---|
66 | case POWER_STATE_CHANGED: |
---|
67 | load = loadProfile.getLoadEstimationPlugin().estimateUtlization(resEvent, new JobRegistryImpl(resource.getFullName()), resource); |
---|
68 | loadProfile.addToLoadHistory(load); |
---|
69 | break; |
---|
70 | |
---|
71 | case CPU_FREQUENCY_CHANGED: |
---|
72 | load = loadProfile.getLoadEstimationPlugin().estimateUtlization(resEvent, new JobRegistryImpl(resource.getFullName()), resource); |
---|
73 | loadProfile.addToLoadHistory(load); |
---|
74 | break; |
---|
75 | |
---|
76 | } |
---|
77 | }catch(Exception e){ |
---|
78 | |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | @Override |
---|
83 | public void init(Properties properties) throws ExtensionException { |
---|
84 | // TODO Auto-generated method stub |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | @Override |
---|
89 | public ExtensionType getType() { |
---|
90 | return ExtensionType.LOAD_EXTENSION; |
---|
91 | } |
---|
92 | |
---|
93 | public LoadProfile getLoadProfile() { |
---|
94 | return loadProfile; |
---|
95 | } |
---|
96 | |
---|
97 | public LoadInterface getLoadInterface() { |
---|
98 | return loadInterface; |
---|
99 | } |
---|
100 | |
---|
101 | } |
---|