1 | package de.uka.ipd.sdq.scheduler.loaddistribution.selectors.instance; |
2 | |
3 | import java.util.Iterator; |
4 | |
5 | import de.uka.ipd.sdq.scheduler.processes.IActiveProcess; |
6 | import de.uka.ipd.sdq.scheduler.resources.IResourceInstance; |
7 | import de.uka.ipd.sdq.scheduler.resources.active.SimActiveResource; |
8 | |
9 | |
10 | public class RoundRobinSelector extends AbstractInstanceSelector { |
11 | |
12 | Iterator<IResourceInstance> instance_iterator; |
13 | |
14 | public RoundRobinSelector(SimActiveResource resource) { |
15 | super(resource); |
16 | reset(); |
17 | } |
18 | |
19 | public IResourceInstance selectInstanceFor(IActiveProcess process, IResourceInstance running_on) { |
20 | IResourceInstance result = null; |
21 | while(result == null){ |
22 | IResourceInstance current = getNext(); |
23 | if (process.checkAffinity(current)){ |
24 | result = current; |
25 | if (!process.hasIdealInstance()){ |
26 | process.setIdealInstance(current); |
27 | } |
28 | } |
29 | } |
30 | return result; |
31 | } |
32 | |
33 | private IResourceInstance getNext() { |
34 | if (!instance_iterator.hasNext()) |
35 | reset(); |
36 | return instance_iterator.next(); |
37 | } |
38 | |
39 | private void reset() { |
40 | instance_iterator = resource.getInstanceList().iterator(); |
41 | } |
42 | } |