source: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/LoadExtension.java @ 1423

Revision 1423, 3.3 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.computing.profiles.load;
2
3import java.util.Properties;
4
5import schedframe.events.Event;
6import schedframe.resources.computing.extensions.Extension;
7import schedframe.resources.computing.extensions.ExtensionException;
8import schedframe.resources.computing.extensions.ExtensionType;
9import schedframe.resources.computing.profiles.energy.ResourceEvent;
10import schedframe.resources.computing.profiles.energy.ResourceEventType;
11import schedframe.resources.computing.profiles.load.ui.LoadInterface;
12import schedframe.resources.devices.PhysicalResource;
13import schedframe.scheduling.manager.tasks.JobRegistryImpl;
14
15public 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}
Note: See TracBrowser for help on using the repository browser.