1 | package de.uka.ipd.sdq.scheduler.loaddistribution.selectors.process; |
2 | |
3 | import de.uka.ipd.sdq.scheduler.loaddistribution.IProcessSelector; |
4 | import de.uka.ipd.sdq.scheduler.processes.IActiveProcess; |
5 | import de.uka.ipd.sdq.scheduler.queueing.IProcessQueue; |
6 | import de.uka.ipd.sdq.scheduler.queueing.IRunQueue; |
7 | import de.uka.ipd.sdq.scheduler.resources.IResourceInstance; |
8 | |
9 | public class PreferIdealAndLastProcessSelector implements IProcessSelector { |
10 | |
11 | public IActiveProcess select(IRunQueue runQueue, IResourceInstance instance) { |
12 | IProcessQueue queue = runQueue.getBestRunnableQueue(instance); |
13 | IActiveProcess result = null; |
14 | if (queue != null) { |
15 | for (IActiveProcess process : queue.ascending()) { |
16 | if (process.checkAffinity(instance)) { |
17 | if (result == null) { |
18 | result = process; |
19 | } else if (isPreferred(process, instance) |
20 | && !isPreferred(result, instance)) { |
21 | return process; |
22 | } |
23 | } |
24 | } |
25 | } |
26 | return result; |
27 | } |
28 | |
29 | private boolean isPreferred(IActiveProcess process, |
30 | IResourceInstance instance) { |
31 | return process.isIdealInstance(instance) |
32 | || process.isLastInstance(instance); |
33 | } |
34 | } |