1 | package desmoj.core.report; |
2 | |
3 | import desmoj.core.simulator.ProcessQueue; |
4 | |
5 | /** |
6 | * Captures all relevant information about a ProcessQueue. |
7 | * |
8 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
9 | * @author Tim Lechler |
10 | * @author modified by Soenke Claassen |
11 | * |
12 | * Licensed under the Apache License, Version 2.0 (the "License"); |
13 | * you may not use this file except in compliance with the License. You |
14 | * may obtain a copy of the License at |
15 | * http://www.apache.org/licenses/LICENSE-2.0 |
16 | * |
17 | * Unless required by applicable law or agreed to in writing, software |
18 | * distributed under the License is distributed on an "AS IS" |
19 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
20 | * or implied. See the License for the specific language governing |
21 | * permissions and limitations under the License. |
22 | * |
23 | */ |
24 | public class ProcessQueueReporter extends Reporter { |
25 | /** |
26 | * Creates a new ProcessQueueReporter. Note that although any Reportable is |
27 | * accepted you should make sure that only subtypes of Queue are passed to |
28 | * this constructor. Otherwise the number of column titles and their |
29 | * individual headings will differ from the actual content collected by this |
30 | * reporter. |
31 | * |
32 | * @param informationSource |
33 | * desmoj.core.simulator.Reportable : The queue to report about |
34 | */ |
35 | public ProcessQueueReporter( |
36 | desmoj.core.simulator.Reportable informationSource) { |
37 | |
38 | super(informationSource); |
39 | |
40 | numColumns = 12; |
41 | columns = new String[numColumns]; |
42 | columns[0] = "Title"; |
43 | columns[1] = "Qorder"; |
44 | columns[2] = "(Re)set"; |
45 | columns[3] = "Obs"; |
46 | columns[4] = "QLimit"; |
47 | columns[5] = "Qmax"; |
48 | columns[6] = "Qnow"; |
49 | columns[7] = "Qavg."; |
50 | columns[8] = "Zeros"; |
51 | columns[9] = "max.Wait"; |
52 | columns[10] = "avg.Wait"; |
53 | columns[11] = "refus."; |
54 | groupHeading = "Queues"; |
55 | groupID = 251; |
56 | entries = new String[numColumns]; |
57 | } |
58 | |
59 | /** |
60 | * Returns an array of Strings each containing the data for the |
61 | * corresponding column in array <code>columns[]</code>. Implement this |
62 | * method tha an array of the same langth as the columntitles is produced |
63 | * containing the data at the point of time this method is called by someone |
64 | * else to produce up-to-date information. |
65 | * |
66 | * @return java.lang.String[] : Array containing the data for reporting |
67 | */ |
68 | public String[] getEntries() { |
69 | |
70 | if (source instanceof ProcessQueue) { |
71 | // variable valid for block only - for faster access |
72 | ProcessQueue<?> q = (ProcessQueue<?>) source; |
73 | |
74 | // Title |
75 | entries[0] = source.getName(); |
76 | // order |
77 | entries[1] = q.getQueueStrategy(); |
78 | // (Re)set |
79 | entries[2] = source.resetAt().toString(); |
80 | // Obs |
81 | entries[3] = Long.toString(source.getObservations()); |
82 | // Qlimit |
83 | entries[4] = Long.toString(q.getQueueLimit()); |
84 | if (q.getQueueLimit() == Integer.MAX_VALUE) { |
85 | entries[4] = "unlimit."; |
86 | } |
87 | // Qmax |
88 | entries[5] = Long.toString(q.maxLength()); |
89 | // Qnow |
90 | entries[6] = Long.toString(q.length()); |
91 | // Qavg. |
92 | entries[7] = Double.toString(q.averageLength()); |
93 | // Zeros |
94 | entries[8] = Long.toString(q.zeroWaits()); |
95 | // max.Wait |
96 | entries[9] = q.maxWaitTime().toString(); |
97 | // avg.Wait |
98 | entries[10] = q.averageWaitTime().toString(); |
99 | // refused |
100 | entries[11] = Long.toString(q.getRefused()); |
101 | } else { |
102 | for (int i = 0; i < numColumns; i++) { |
103 | entries[i] = "Invalid source!"; |
104 | } // end for |
105 | } |
106 | |
107 | return entries; |
108 | } |
109 | } |