1 | package de.uka.ipd.sdq.scheduler.queueing.strategies; |
2 | |
3 | import java.util.List; |
4 | |
5 | import de.uka.ipd.sdq.scheduler.loaddistribution.IInstanceSelector; |
6 | import de.uka.ipd.sdq.scheduler.loaddistribution.IProcessSelector; |
7 | import de.uka.ipd.sdq.scheduler.processes.IActiveProcess; |
8 | import de.uka.ipd.sdq.scheduler.queueing.IQueueingStrategy; |
9 | import de.uka.ipd.sdq.scheduler.queueing.IRunQueue; |
10 | import de.uka.ipd.sdq.scheduler.resources.IResourceInstance; |
11 | import de.uka.ipd.sdq.scheduler.resources.active.SimResourceInstance; |
12 | |
13 | public class SingleQueueStrategy implements IQueueingStrategy { |
14 | |
15 | private IRunQueue runQueue; |
16 | private IProcessSelector processSelector; |
17 | private IInstanceSelector idealInstanceSelector; |
18 | public SingleQueueStrategy(IRunQueue runQueue, |
19 | IProcessSelector processSelector, |
20 | IInstanceSelector idealInstanceSelector) { |
21 | super(); |
22 | this.runQueue = runQueue; |
23 | this.processSelector = processSelector; |
24 | this.idealInstanceSelector = idealInstanceSelector; |
25 | } |
26 | |
27 | public IActiveProcess getNextProcessFor(IResourceInstance instance) { |
28 | return processSelector.select(runQueue, instance); |
29 | } |
30 | |
31 | public void registerProcess(IActiveProcess process, IResourceInstance current) { |
32 | IResourceInstance instance = process.getLastInstance(); |
33 | if (instance == null) { |
34 | instance = idealInstanceSelector.selectInstanceFor(process, current); |
35 | process.setLastInstance(instance); |
36 | } |
37 | } |
38 | |
39 | public void addProcess(IActiveProcess process, IResourceInstance current, boolean inFront) { |
40 | registerProcess(process, current); |
41 | runQueue.addProcess(process, inFront); |
42 | } |
43 | |
44 | |
45 | public void activelyBalance(IResourceInstance instance) { |
46 | // nothing to do. |
47 | } |
48 | |
49 | |
50 | public boolean removePendingProcess(IActiveProcess process) { |
51 | return runQueue.removePendingProcess(process); |
52 | } |
53 | |
54 | |
55 | public boolean containsPending(IActiveProcess process) { |
56 | return runQueue.containsPending(process); |
57 | } |
58 | |
59 | |
60 | public void removeRunning(IActiveProcess process) { |
61 | runQueue.removeRunning(process); |
62 | } |
63 | |
64 | |
65 | public IResourceInstance runningOn(IActiveProcess process) { |
66 | return runQueue.runningOn(process); |
67 | } |
68 | |
69 | |
70 | public void setRunningOn(IActiveProcess process, IResourceInstance instance) { |
71 | runQueue.setRunningOn(process, instance); |
72 | } |
73 | |
74 | |
75 | public boolean isIdle(IResourceInstance instance) { |
76 | return runQueue.isIdle(instance); |
77 | } |
78 | |
79 | public void forkProcess(IActiveProcess process, IResourceInstance current, |
80 | boolean inFront) { |
81 | addProcess(process, current, inFront); |
82 | } |
83 | |
84 | public void fromRunningToWaiting(IActiveProcess process) { |
85 | removeRunning(process); |
86 | } |
87 | |
88 | public void fromWaitingToReady(IActiveProcess process, |
89 | IResourceInstance current, boolean in_front_after_waiting) { |
90 | addProcess(process, current, in_front_after_waiting); |
91 | } |
92 | |
93 | public void terminateProcess(IActiveProcess process) { |
94 | removePendingProcess(process); |
95 | } |
96 | |
97 | public void onSleep(IResourceInstance lastInstance) { |
98 | // nothing to do |
99 | } |
100 | |
101 | public List<IActiveProcess> getStarvingProcesses( |
102 | IResourceInstance instance, double starvationLimit) { |
103 | return runQueue.getStarvingProcesses(starvationLimit); |
104 | } |
105 | |
106 | public void resetStarvationInfo() { |
107 | runQueue.resetStarvationInfo(); |
108 | } |
109 | |
110 | public int getQueueLengthFor(SimResourceInstance simResourceInstance) { |
111 | return this.runQueue.getCurrentLoad(); |
112 | } |
113 | |
114 | } |