1 | package example.localplugin; |
---|
2 | |
---|
3 | import gridsim.Gridlet; |
---|
4 | |
---|
5 | import java.util.List; |
---|
6 | import java.util.Properties; |
---|
7 | |
---|
8 | import schedframe.scheduling.Queue; |
---|
9 | import schedframe.scheduling.TaskInterface; |
---|
10 | import schedframe.scheduling.events.SchedulingEvent; |
---|
11 | import schedframe.scheduling.plugin.local.ResourceUnitsManagerInterface; |
---|
12 | |
---|
13 | public class LCFS_EBFLocalPlugin extends BaseLocalPlugin { |
---|
14 | |
---|
15 | |
---|
16 | public LCFS_EBFLocalPlugin(){ |
---|
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 | } |
---|
45 | } |
---|
46 | break; |
---|
47 | } |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | public String getName() { |
---|
52 | return getClass().getName(); |
---|
53 | } |
---|
54 | |
---|
55 | public void init(Properties properties) { |
---|
56 | // no extra initialization is expected. |
---|
57 | } |
---|
58 | |
---|
59 | } |
---|