1 | package de.uka.ipd.sdq.scheduler.resources.passive; |
2 | |
3 | import java.util.ArrayDeque; |
4 | import java.util.Deque; |
5 | |
6 | import de.uka.ipd.sdq.scheduler.IPassiveResource; |
7 | import de.uka.ipd.sdq.scheduler.IRunningProcess; |
8 | import de.uka.ipd.sdq.scheduler.SchedulerModel; |
9 | import de.uka.ipd.sdq.scheduler.priority.IPriorityBoost; |
10 | import de.uka.ipd.sdq.scheduler.processes.impl.ProcessWithPriority; |
11 | import de.uka.ipd.sdq.scheduler.resources.AbstractSimResource; |
12 | import de.uka.ipd.sdq.scheduler.resources.IResourceInstance; |
13 | import de.uka.ipd.sdq.scheduler.resources.active.SimActiveResource; |
14 | |
15 | public abstract class SimAbstractPassiveResource extends AbstractSimResource |
16 | implements IPassiveResource { |
17 | |
18 | private IPriorityBoost priority_boost; |
19 | protected Deque<WaitingProcess> waiting_queue; |
20 | protected SimActiveResource main_resource; |
21 | |
22 | public SimAbstractPassiveResource(SchedulerModel model, int capacity, String name, String id, |
23 | IPriorityBoost priority_boost, SimActiveResource managing_resource) { |
24 | super(model, capacity, name, id); |
25 | this.priority_boost = priority_boost; |
26 | this.main_resource = managing_resource; |
27 | this.waiting_queue = new ArrayDeque<WaitingProcess>(); |
28 | } |
29 | |
30 | protected void fromWaitingToReady(WaitingProcess waiting_process, |
31 | IResourceInstance current) { |
32 | if (main_resource != null){ |
33 | main_resource.getScheduler().fromWaitingToReady(waiting_process, |
34 | waiting_queue, current); |
35 | } |
36 | } |
37 | |
38 | protected void fromRunningToWaiting(WaitingProcess waiting_process, |
39 | boolean inFront) { |
40 | if (main_resource != null) { |
41 | main_resource.getScheduler().fromRunningToWaiting(waiting_process, |
42 | waiting_queue, inFront); |
43 | } |
44 | } |
45 | |
46 | protected void boostPriority(IRunningProcess process) { |
47 | if (priority_boost != null) { |
48 | assert process instanceof ProcessWithPriority : "If priority boosts are used only ProcessWithPriorities can be used!"; |
49 | priority_boost.boost((ProcessWithPriority) process); |
50 | } |
51 | } |
52 | |
53 | protected void punish(IRunningProcess process) { |
54 | if (priority_boost != null) { |
55 | assert process instanceof ProcessWithPriority : "If priority boosts are used only ProcessWithPriorities can be used!"; |
56 | priority_boost.punish((ProcessWithPriority) process); |
57 | } |
58 | } |
59 | |
60 | @Override |
61 | public String toString() { |
62 | return super.getName()+"_"+super.getId(); |
63 | } |
64 | } |