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

COVERAGE SUMMARY FOR SOURCE FILE [PriorityArray.java]

nameclass, %method, %block, %line, %
PriorityArray.java0%   (0/5)0%   (0/39)0%   (0/555)0%   (0/91)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PriorityArray0%   (0/1)0%   (0/25)0%   (0/355)0%   (0/70)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
PriorityArray (SchedulerModel, IPriorityManager): void 0%   (0/1)0%   (0/35)0%   (0/7)
access$0 (PriorityArray): IPriorityManager 0%   (0/1)0%   (0/3)0%   (0/1)
access$1 (PriorityArray, IPriority): IProcessQueue 0%   (0/1)0%   (0/4)0%   (0/1)
add (IActiveProcess, boolean): void 0%   (0/1)0%   (0/7)0%   (0/2)
addFirst (IActiveProcess): void 0%   (0/1)0%   (0/5)0%   (0/2)
addLast (IActiveProcess): void 0%   (0/1)0%   (0/5)0%   (0/2)
ascending (): Iterable 0%   (0/1)0%   (0/5)0%   (0/1)
contains (IActiveProcess): boolean 0%   (0/1)0%   (0/21)0%   (0/4)
createNewInstance (): IProcessQueue 0%   (0/1)0%   (0/8)0%   (0/1)
descending (): Iterable 0%   (0/1)0%   (0/5)0%   (0/1)
getBestRunnableQueue (IResourceInstance): IProcessQueue 0%   (0/1)0%   (0/26)0%   (0/5)
getNextRunnableProcess (): IActiveProcess 0%   (0/1)0%   (0/10)0%   (0/4)
getNextRunnableProcess (IResourceInstance): IActiveProcess 0%   (0/1)0%   (0/25)0%   (0/5)
getNonEmptyQueueWithHighestPriority (): IProcessQueue 0%   (0/1)0%   (0/24)0%   (0/4)
getQueue (IPriority): IProcessQueue 0%   (0/1)0%   (0/6)0%   (0/1)
getQueueFor (IActiveProcess): IProcessQueue 0%   (0/1)0%   (0/15)0%   (0/2)
getStarvingProcesses (double): List 0%   (0/1)0%   (0/25)0%   (0/4)
getWaitingTime (IActiveProcess): double 0%   (0/1)0%   (0/6)0%   (0/1)
identifyMovableProcesses (IResourceInstance, boolean, boolean, int, List): void 0%   (0/1)0%   (0/36)0%   (0/6)
isEmpty (): boolean 0%   (0/1)0%   (0/20)0%   (0/4)
processStarving (double): boolean 0%   (0/1)0%   (0/21)0%   (0/4)
remove (IActiveProcess): boolean 0%   (0/1)0%   (0/6)0%   (0/1)
setWaitingTime (IActiveProcess, double): void 0%   (0/1)0%   (0/7)0%   (0/2)
size (): int 0%   (0/1)0%   (0/22)0%   (0/4)
     
class PriorityArray$10%   (0/1)0%   (0/3)0%   (0/14)0%   (0/3)
PriorityArray$1 (PriorityArray): void 0%   (0/1)0%   (0/6)0%   (0/2)
access$0 (PriorityArray$1): PriorityArray 0%   (0/1)0%   (0/3)0%   (0/1)
iterator (): Iterator 0%   (0/1)0%   (0/5)0%   (0/1)
     
class PriorityArray$1$10%   (0/1)0%   (0/4)0%   (0/86)0%   (0/11)
PriorityArray$1$1 (PriorityArray$1): void 0%   (0/1)0%   (0/16)0%   (0/4)
hasNext (): boolean 0%   (0/1)0%   (0/35)0%   (0/3)
next (): IActiveProcess 0%   (0/1)0%   (0/34)0%   (0/3)
remove (): void 0%   (0/1)0%   (0/1)0%   (0/1)
     
class PriorityArray$20%   (0/1)0%   (0/3)0%   (0/14)0%   (0/3)
PriorityArray$2 (PriorityArray): void 0%   (0/1)0%   (0/6)0%   (0/2)
access$0 (PriorityArray$2): PriorityArray 0%   (0/1)0%   (0/3)0%   (0/1)
iterator (): Iterator 0%   (0/1)0%   (0/5)0%   (0/1)
     
class PriorityArray$2$10%   (0/1)0%   (0/4)0%   (0/86)0%   (0/11)
PriorityArray$2$1 (PriorityArray$2): void 0%   (0/1)0%   (0/16)0%   (0/4)
hasNext (): boolean 0%   (0/1)0%   (0/35)0%   (0/3)
next (): IActiveProcess 0%   (0/1)0%   (0/34)0%   (0/3)
remove (): void 0%   (0/1)0%   (0/1)0%   (0/1)

1package de.uka.ipd.sdq.scheduler.queueing.basicqueues;
2 
3import java.util.ArrayList;
4import java.util.Hashtable;
5import java.util.Iterator;
6import java.util.List;
7 
8import de.uka.ipd.sdq.scheduler.SchedulerModel;
9import de.uka.ipd.sdq.scheduler.priority.IPriority;
10import de.uka.ipd.sdq.scheduler.priority.IPriorityManager;
11import de.uka.ipd.sdq.scheduler.processes.IActiveProcess;
12import de.uka.ipd.sdq.scheduler.processes.impl.ProcessWithPriority;
13import de.uka.ipd.sdq.scheduler.queueing.IProcessQueue;
14import de.uka.ipd.sdq.scheduler.resources.IResourceInstance;
15 
16public class PriorityArray implements IProcessQueue {
17 
18    private SchedulerModel model;
19        private Hashtable<IPriority, IProcessQueue> priorityTable;
20        private IPriorityManager priority_manager;
21 
22        public PriorityArray(SchedulerModel model, IPriorityManager priority_manager) {
23            this.model = model;
24                this.priority_manager = priority_manager;
25                this.priorityTable = new Hashtable<IPriority, IProcessQueue>();
26                for (IPriority prio : priority_manager.decreasing()) {
27                        priorityTable.put(prio, new ProcessQueueImpl(model));
28                }
29        }
30 
31        /**
32         * Returns the number of processes in the priority array.
33         */
34        @SuppressWarnings("unchecked")
35        public int size() {
36                int num = 0;
37                for (IProcessQueue queue : priorityTable.values()) {
38                        num += queue.size();
39                }
40                return num;
41        }
42 
43        /**
44         * @return True, if the priority array is empty. False, otherwise.
45         */
46        @SuppressWarnings("unchecked")
47        public boolean isEmpty() {
48                for (IProcessQueue queue : priorityTable.values()) {
49                        if (!queue.isEmpty())
50                                return false;
51                }
52                return true;
53        }
54 
55        /**
56         * Removes the given process from the priorityarray.
57         * 
58         * @param process
59         * @return True, if the process has been successfully removed. False,
60         *         otherwise.
61         */
62        public boolean remove(IActiveProcess process) {
63                return getQueueFor(process).remove(process);
64        }
65 
66        /**
67         * Adds a new process at the END of the process' priority's queue.
68         * 
69         * @param process
70         */
71        public void addLast(IActiveProcess process) {
72                add(process,false);
73        }
74 
75        /**
76         * Adds a new process at the BEGINNING of the process' priority's queue.
77         * 
78         * @param process
79         */
80        public void addFirst(IActiveProcess process) {
81                add(process,true);
82        }
83 
84        public void add(IActiveProcess process, boolean in_front) {
85                getQueueFor(process).add(process,in_front);
86        }
87 
88        /**
89         * Returns the queue of the process' priority.
90         * 
91         * @param process
92         * @return Queue for the given process.
93         */
94        private IProcessQueue getQueueFor(IActiveProcess process) {
95                assert process instanceof ProcessWithPriority;
96                return getQueue( ((ProcessWithPriority)process).getDynamicPriority());
97        }
98        
99 
100        /**
101         * @return Returns the queue with the highest priority which is not empty.
102         *         Null if all queues are empty.
103         */
104        private IProcessQueue getNonEmptyQueueWithHighestPriority() {
105                for (IPriority prio : priority_manager.decreasing()) {
106                        if (!getQueue(prio).isEmpty())
107                                return getQueue(prio);
108                }
109                return null;
110        }
111 
112        private IProcessQueue getQueue(IPriority prio) {
113                return priorityTable.get(prio);
114        }
115 
116        /**
117         * Returns the queue with the highest priority of which at least one process
118         * can be executed on instance.
119         * 
120         * @param instance
121         * @return
122         */
123        @SuppressWarnings("unchecked")
124        public IProcessQueue getBestRunnableQueue(
125                        IResourceInstance instance) {
126                IProcessQueue queue = null;
127                for (IPriority prio : priority_manager.decreasing()) {
128                         queue = getQueue(prio).getBestRunnableQueue(instance);
129                         if (queue != null) break;
130                }
131                return queue;
132        }
133 
134        /**
135         * Returns the process with the highest priority runnable on the given instance.
136         * @param instance
137         * @return
138         */
139        public IActiveProcess getNextRunnableProcess(IResourceInstance instance) {
140                IActiveProcess process = null;
141                for (IPriority prio : priority_manager.decreasing()) {
142                        process = getQueue(prio).getNextRunnableProcess();
143                        if (process != null) break;
144                }
145                return process;
146        }
147 
148        public boolean contains(IActiveProcess process) {
149                for (IProcessQueue queue : priorityTable.values()) {
150                        if (queue.contains(process))
151                                return true;
152                }
153                return false;
154        }
155 
156        public IActiveProcess getNextRunnableProcess() {
157                IProcessQueue queue = getNonEmptyQueueWithHighestPriority();
158                if (queue != null){
159                        return queue.getNextRunnableProcess();
160                }
161                return null;
162        }
163 
164        /**
165         * Adds processes that do not violate the affinity constraint to the list
166         * in the specified direction.
167         * 
168         * @param target_instance
169         */
170        public void identifyMovableProcesses(
171                        IResourceInstance target_instance, boolean prio_increasing,
172                        boolean queue_ascending, int processes_needed, List<IActiveProcess> process_list){
173                Iterable<IPriority> prio_direction = prio_increasing ? priority_manager.increasing() : priority_manager.decreasing(); 
174                for (IPriority prio : prio_direction) {
175                        getQueue(prio).identifyMovableProcesses(target_instance, prio_increasing, queue_ascending, processes_needed, process_list);
176                        if (process_list.size() >= processes_needed)
177                                break;
178                }
179        }
180 
181        public Iterable<IActiveProcess> ascending() {
182                return new Iterable<IActiveProcess>(){
183                        public Iterator<IActiveProcess> iterator() {
184                                return new Iterator<IActiveProcess>(){
185                                        
186                                        Iterator<IPriority> prio_iterator = priority_manager.increasing().iterator();
187                                        Iterator<IActiveProcess> queue_iterator = null;
188 
189                                        public boolean hasNext() {
190                                                while ((queue_iterator == null || !queue_iterator.hasNext()) && prio_iterator.hasNext()){
191                                                        queue_iterator = getQueue(prio_iterator.next()).ascending().iterator();
192                                                }
193                                                return (queue_iterator != null && queue_iterator.hasNext());
194                                        }
195 
196                                        public IActiveProcess next() {
197                                                while ((queue_iterator == null || !queue_iterator.hasNext()) && prio_iterator.hasNext()){
198                                                        queue_iterator = getQueue(prio_iterator.next()).ascending().iterator();
199                                                }
200                                                return queue_iterator == null ? null : queue_iterator.next();
201                                        }
202 
203                                        public void remove() {
204                                        }
205                                        
206                                };
207                        }
208                        
209                };
210        }
211 
212        public Iterable<IActiveProcess> descending() {
213                return new Iterable<IActiveProcess>(){
214                        public Iterator<IActiveProcess> iterator() {
215                                return new Iterator<IActiveProcess>(){
216                                        
217                                        Iterator<IPriority> prio_iterator = priority_manager.decreasing().iterator();
218                                        Iterator<IActiveProcess> queue_iterator = null;
219 
220                                        public boolean hasNext() {
221                                                while ((queue_iterator == null || !queue_iterator.hasNext()) && prio_iterator.hasNext()){
222                                                        queue_iterator = getQueue(prio_iterator.next()).descending().iterator();
223                                                }
224                                                return (queue_iterator != null && queue_iterator.hasNext());
225                                        }
226 
227                                        public IActiveProcess next() {
228                                                while ((queue_iterator == null || !queue_iterator.hasNext()) && prio_iterator.hasNext()){
229                                                        queue_iterator = getQueue(prio_iterator.next()).descending().iterator();
230                                                }
231                                                return queue_iterator == null ? null : queue_iterator.next();
232                                        }
233 
234                                        public void remove() {
235                                        }
236                                        
237                                };
238                        }
239                        
240                };
241        }
242 
243        public IProcessQueue createNewInstance() {
244                return new PriorityArray(model, priority_manager);
245        }
246        
247        public boolean processStarving(double threshold) {
248                for(IProcessQueue q : priorityTable.values()){
249                        if (q.processStarving(threshold))
250                                return true;
251                }
252                return false;
253        }
254        
255        public double getWaitingTime(IActiveProcess process) {
256                return getQueueFor(process).getWaitingTime(process);
257        }
258        
259        public void setWaitingTime(IActiveProcess process, double waiting) {
260                getQueueFor(process).setWaitingTime(process, waiting);
261        }
262 
263        public List<IActiveProcess> getStarvingProcesses(double starvationLimit) {
264                List<IActiveProcess> result = new ArrayList<IActiveProcess>();
265                for(IProcessQueue q : priorityTable.values()){
266                        result.addAll(q.getStarvingProcesses(starvationLimit));
267                }
268                return result;
269        }
270}

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