1 | package de.uka.ipd.sdq.scheduler.loaddistribution.selectors.instance; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.List; |
5 | |
6 | import de.uka.ipd.sdq.scheduler.processes.IActiveProcess; |
7 | import de.uka.ipd.sdq.scheduler.resources.IResourceInstance; |
8 | import de.uka.ipd.sdq.scheduler.resources.active.SimActiveResource; |
9 | |
10 | |
11 | public class IdleSelector extends AbstractInstanceSelector { |
12 | |
13 | RoundRobinSelector ideal_instance_selector; |
14 | |
15 | public IdleSelector(SimActiveResource resource) { |
16 | super(resource); |
17 | ideal_instance_selector = new RoundRobinSelector(resource); |
18 | } |
19 | |
20 | public IResourceInstance selectInstanceFor(IActiveProcess process, IResourceInstance current) { |
21 | return current; |
22 | // List<IResourceInstance> idleInstances = getIdleInstances(); |
23 | // process.removeNonAffineInstances(idleInstances); |
24 | // |
25 | // if (!process.hasIdealInstance()) |
26 | // selectIdealInstance(process); |
27 | // |
28 | // if(!idleInstances.isEmpty()){ |
29 | // if(idleInstances.contains(process.getIdealInstance())){ |
30 | // return process.getIdealInstance(); |
31 | // } |
32 | // if(process.hasLastInstance() && idleInstances.contains(process.getLastInstance())){ |
33 | // return process.getLastInstance(); |
34 | // } |
35 | // return idleInstances.get(0); |
36 | // } |
37 | // return process.getIdealInstance(); |
38 | } |
39 | |
40 | // private void selectIdealInstance(IActiveProcess process) { |
41 | // ideal_instance_selector.selectInstanceFor(process); |
42 | // } |
43 | |
44 | public List<IResourceInstance> getIdleInstances() { |
45 | List<IResourceInstance> idleInstances = new ArrayList<IResourceInstance>(); |
46 | for (IResourceInstance instance : resource.getInstanceList()) { |
47 | if (resource.isIdle(instance)) |
48 | idleInstances.add(instance); |
49 | } |
50 | return idleInstances; |
51 | } |
52 | |
53 | } |