source: gssim/trunk/src/example/localplugin/FCFSLocalPlugin.java @ 93

Revision 93, 1.8 KB checked in by wojtekp, 14 years ago (diff)

Fix bug in FCFS strategy

  • Property svn:mime-type set to text/plain
RevLine 
[5]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
13/**
14 *
15 * @author Marcin Krystek
16 *
17 */
18public class FCFSLocalPlugin extends BaseLocalPlugin {
19
20       
21        public FCFSLocalPlugin(){
22        }
23       
24        public void schedule(SchedulingEvent event,
25                        List<? extends TaskInterface<?>> inExecution,
26                        List<? extends Queue<? extends TaskInterface<?>>> queues,
27                        ResourceUnitsManagerInterface unitsManagerInterface) {
28               
29                // do this trick to make add() method available
30                List <TaskInterface<?>> execute = (List<TaskInterface<?>>) inExecution;
31               
32                // chose the events types to serve.
33                // Different actions for different events are possible.
34                switch(event.getType()){
35                        case START_TASK_EXECUTION:
36                        case TASK_FINISHED:
37                                // our tasks are placed only in first queue (see BaseLocalPlugin.placeTasksInQueues() method)
38                                Queue<? extends TaskInterface<?>> q = queues.get(0);
39                                // check all tasks in queue
40                                for(int i = 0; i < q.size(); i++){
41                                        TaskInterface<?> task = q.get(i);
42                                        // if status of the tasks in READY
43                                        if(task.getStatus() == Gridlet.READY){
44                                                // then try to execute this task. Add it the execute list.
45                                                if(execute.add(task)){
46                                                        // if task started successfully, then remove it from the queue.
47                                                        q.remove(i);
48                                                        i--; // index trick to get the right position in the queue after task removal.
49                                                }
[93]50                                                else{
51                                                        break;
52                                                }
[5]53                                        }
54                                }
55                                break;
56                }
57               
58        }
59
60        public String getPluginName() {
61                return getClass().getName();
62        }
63
64        public void initPlugin(Properties properties) {
65                // no extra initialization is expected.
66        }
67       
68}
Note: See TracBrowser for help on using the repository browser.