source: xssim/trunk/src/example/localplugin/LCFSLocalPlugin.java @ 104

Revision 104, 1.7 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.localplugin;
2
3import gridsim.Gridlet;
4
5import java.util.List;
6import java.util.Properties;
7
8import schedframe.scheduling.Queue;
9import schedframe.scheduling.TaskInterface;
10import schedframe.scheduling.events.SchedulingEvent;
11import schedframe.scheduling.plugin.local.ResourceUnitsManagerInterface;
12
13public class LCFSLocalPlugin extends BaseLocalPlugin {
14
15       
16        public LCFSLocalPlugin(){
17        }
18       
19        public void schedule(SchedulingEvent event,
20                        List<? extends TaskInterface<?>> inExecution,
21                        List<? extends Queue<? extends TaskInterface<?>>> queues,
22                        ResourceUnitsManagerInterface unitsManagerInterface) {
23               
24                // do this trick to make add() method available
25                List <TaskInterface<?>> execute = (List<TaskInterface<?>>) inExecution;
26               
27                // chose the events types to serve.
28                // Different actions for different events are possible.
29                switch(event.getType()){
30                        case START_TASK_EXECUTION:
31                        case TASK_FINISHED:
32                                // our tasks are placed only in first queue (see BaseLocalPlugin.placeTasksInQueues() method)
33                                Queue<? extends TaskInterface<?>> q = queues.get(0);
34                                // check all tasks in queue
35                                for(int i = q.size() - 1; i >= 0; i--){
36                                        TaskInterface<?> task = q.get(i);
37                                        // if status of the tasks in READY
38                                        if(task.getStatus() == Gridlet.READY){
39                                                // then try to execute this task. Add it the execute list.
40                                                if(execute.add(task)){
41                                                        // if task started successfully, then remove it from the queue.
42                                                        q.remove(i);
43                                                }
44                                                else{
45                                                        break;
46                                                }
47                                        }
48                                }
49                                break;
50                }
51               
52        }
53
54        public String getName() {
55                return getClass().getName();
56        }
57
58        public void init(Properties properties) {
59                // no extra initialization is expected.
60        }
61       
62}
Note: See TracBrowser for help on using the repository browser.