EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.scheduler.resources.passive]

COVERAGE SUMMARY FOR SOURCE FILE [SimFairPassiveResource.java]

nameclass, %method, %block, %line, %
SimFairPassiveResource.java0%   (0/1)0%   (0/11)0%   (0/240)0%   (0/55)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimFairPassiveResource0%   (0/1)0%   (0/11)0%   (0/240)0%   (0/55)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
SimFairPassiveResource (SchedulerModel, int, String, String, IPriorityBoost, ... 0%   (0/1)0%   (0/17)0%   (0/4)
acquire (ISchedulableProcess, int, boolean, double): boolean 0%   (0/1)0%   (0/60)0%   (0/14)
addObserver (IPassiveResourceSensor): void 0%   (0/1)0%   (0/5)0%   (0/2)
canProceed (IRunningProcess, int): boolean 0%   (0/1)0%   (0/20)0%   (0/3)
getAvailable (): int 0%   (0/1)0%   (0/3)0%   (0/1)
grantAccess (PreemptiveProcess, int): void 0%   (0/1)0%   (0/45)0%   (0/8)
notifyWaitingProcesses (IResourceInstance): void 0%   (0/1)0%   (0/16)0%   (0/5)
release (ISchedulableProcess, int): void 0%   (0/1)0%   (0/43)0%   (0/9)
removeObserver (IPassiveResourceSensor): void 0%   (0/1)0%   (0/5)0%   (0/2)
tryToDequeueProcess (WaitingProcess): boolean 0%   (0/1)0%   (0/18)0%   (0/6)

1package de.uka.ipd.sdq.scheduler.resources.passive;
2 
3import de.uka.ipd.sdq.scheduler.IRunningProcess;
4import de.uka.ipd.sdq.scheduler.ISchedulableProcess;
5import de.uka.ipd.sdq.scheduler.LoggingWrapper;
6import de.uka.ipd.sdq.scheduler.SchedulerModel;
7import de.uka.ipd.sdq.scheduler.priority.IPriorityBoost;
8import de.uka.ipd.sdq.scheduler.processes.IActiveProcess;
9import de.uka.ipd.sdq.scheduler.processes.impl.PreemptiveProcess;
10import de.uka.ipd.sdq.scheduler.processes.impl.ProcessWithPriority;
11import de.uka.ipd.sdq.scheduler.resources.IResourceInstance;
12import de.uka.ipd.sdq.scheduler.resources.active.SimActiveResource;
13import de.uka.ipd.sdq.scheduler.sensors.IPassiveResourceSensor;
14 
15public class SimFairPassiveResource extends SimAbstractPassiveResource {
16 
17        private PassiveResourceObservee observee;
18        private int available;
19 
20        public SimFairPassiveResource(SchedulerModel model, int capacity, String name, String id,
21                        IPriorityBoost priority_boost, SimActiveResource managing_resource) {
22                super(model, capacity, name, id, priority_boost, managing_resource);
23                observee = new PassiveResourceObservee();
24                available = capacity;
25        }
26 
27        private boolean canProceed(IRunningProcess process, int num) {
28                return (waiting_queue.isEmpty() || waiting_queue.peek().getProcess()
29                                .equals(process))
30                                && num <= available;
31        }
32 
33        public boolean acquire(ISchedulableProcess sched_process, int num,
34                        boolean timeout, double timeoutValue) {
35 
36                // AM: Copied from AbstractActiveResource: If simulation is stopped,
37                // allow all processes to finish
38                if (!getModel().getSimulationControl().isRunning()) {
39                        // Do nothing, but allows calling process to complete
40                        return true;
41                }
42 
43                observee.fireRequest(sched_process, num);
44                PreemptiveProcess process = (PreemptiveProcess) main_resource
45                                .lookUp(sched_process);
46                if (canProceed(process, num)) {
47                        grantAccess(process, num);
48                        return true;
49                } else {
50                        LoggingWrapper.log("Process " + process + " is waiting for " + num
51                                        + " of " + this);
52                        WaitingProcess waiting_process = new WaitingProcess(process, num);
53                        fromRunningToWaiting(waiting_process, false);
54                        process.getSchedulableProcess().passivate();
55                        return false;
56                }
57        }
58 
59        public void release(ISchedulableProcess sched_process, int num) {
60 
61                // AM: Copied from AbstractActiveResource: If simulation is stopped,
62                // allow all processes to finish
63                if (!getModel().getSimulationControl().isRunning()) {
64                        // Do nothing, but allows calling process to complete
65                        return;
66                }
67 
68                IActiveProcess process = main_resource.lookUp(sched_process);
69 
70                LoggingWrapper.log("Process " + process + " releases " + num + " of "
71                                + this);
72                available += num;
73                observee.fireRelease(sched_process, num);
74                notifyWaitingProcesses(process.getLastInstance());
75        }
76 
77        private void notifyWaitingProcesses(IResourceInstance current) {
78                WaitingProcess waitingProcess = waiting_queue.peek();
79                if (waitingProcess != null) {
80                        if (tryToDequeueProcess(waitingProcess))
81                                fromWaitingToReady(waitingProcess, current);
82                }
83        }
84 
85        private void grantAccess(PreemptiveProcess process, int num) {
86                LoggingWrapper.log("Process " + process + " acquires " + num + " of "
87                                + this);
88                punish(process);
89                boostPriority(process);
90                available -= num;
91                observee.fireAquire(process.getSchedulableProcess(), num);
92                assert available >= 0 : "More resource than available have been acquired!";
93        }
94 
95        /**
96         * Tries to remove the given process from the waiting queue and get access
97         * of the required number of passive resources.
98         * 
99         * @param waitingProcess
100         * @return True if the process was successfully dequeued and activated,
101         *         otherwise false.
102         */
103        private boolean tryToDequeueProcess(WaitingProcess waitingProcess) {
104                if (canProceed(waitingProcess.getProcess(), waitingProcess
105                                .getNumRequested())) {
106                        grantAccess((ProcessWithPriority) waitingProcess.getProcess(),
107                                        waitingProcess.getNumRequested());
108                        return true;
109                }
110                return false;
111        }
112 
113        public void addObserver(IPassiveResourceSensor observer) {
114                observee.addObserver(observer);
115        }
116 
117        public void removeObserver(IPassiveResourceSensor observer) {
118                observee.removeObserver(observer);
119        }
120 
121        public int getAvailable() {
122                return available;
123        }
124 
125}

[all classes][de.uka.ipd.sdq.scheduler.resources.passive]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov