1 | package de.uka.ipd.sdq.scheduler.processes.impl; |
2 | |
3 | import java.util.Hashtable; |
4 | |
5 | import de.uka.ipd.sdq.scheduler.ISchedulableProcess; |
6 | import de.uka.ipd.sdq.scheduler.processes.IActiveProcess; |
7 | import de.uka.ipd.sdq.scheduler.resources.active.SimActiveResource; |
8 | |
9 | |
10 | public class ProcessRegistry { |
11 | |
12 | private Hashtable<ISchedulableProcess, IActiveProcess> registry; |
13 | private SimActiveResource resource; |
14 | |
15 | public ProcessRegistry(SimActiveResource resource) { |
16 | super(); |
17 | this.registry = new Hashtable<ISchedulableProcess, IActiveProcess>(); |
18 | this.resource = resource; |
19 | } |
20 | |
21 | public void registerProcess(IActiveProcess process){ |
22 | registry.put(process.getSchedulableProcess(), process); |
23 | // process.getSchedulableProcess().setMainResource(resource); |
24 | } |
25 | |
26 | public IActiveProcess lookUp(ISchedulableProcess process){ |
27 | return registry.get(process); |
28 | } |
29 | |
30 | public void unregisterProcess(ISchedulableProcess process){ |
31 | registry.remove(process); |
32 | } |
33 | |
34 | public IActiveProcess findProcess(String processName) { |
35 | for (IActiveProcess p: registry.values()){ |
36 | if (p.getName().startsWith(processName)) |
37 | return p; |
38 | } |
39 | assert false : "Cannot find process: " + processName; |
40 | return null; |
41 | } |
42 | |
43 | public boolean isRegistered(IActiveProcess p) { |
44 | return registry.containsKey(p.getSchedulableProcess()); |
45 | } |
46 | |
47 | } |