1 | package desmoj.core.advancedModellingFeatures.report; |
2 | |
3 | import desmoj.core.statistic.StatisticObject; |
4 | |
5 | /** |
6 | * Captures all relevant information about the Res. |
7 | * |
8 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
9 | * @author Soenke Claassen based on ideas from Tim Lechler |
10 | * @author based on DESMO-C from Thomas Schniewind, 1998 |
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 | |
25 | public class ResourceReporter extends desmoj.core.report.Reporter { |
26 | |
27 | // ****** methods ****** |
28 | |
29 | /** |
30 | * Constructor for a new ResourceReporter. Note that although any Reportable |
31 | * is accepted you should make sure that only subtypes of Res are passed to |
32 | * this constructor. Otherwise the number of column titles and their |
33 | * individual headings will differ from the actual content collected by this |
34 | * reporter. |
35 | * |
36 | * @param informationSource |
37 | * desmoj.core.simulator.Reportable : The Res to report about. |
38 | */ |
39 | public ResourceReporter(desmoj.core.simulator.Reportable informationSource) { |
40 | super(informationSource); // make a Reporter |
41 | |
42 | numColumns = 14; |
43 | columns = new String[numColumns]; |
44 | columns[0] = "Title"; |
45 | columns[1] = "Order"; |
46 | columns[2] = "pass"; |
47 | columns[3] = "(Re)set"; |
48 | columns[4] = "Users"; |
49 | columns[5] = "Limit"; |
50 | columns[6] = "Min"; |
51 | columns[7] = "Now"; |
52 | columns[8] = "Usage[%]"; |
53 | columns[9] = "avg.Wait"; |
54 | columns[10] = "QLimit"; |
55 | columns[11] = "QMaxL"; |
56 | columns[12] = "refus."; |
57 | columns[13] = "DL"; |
58 | groupHeading = "Resources"; |
59 | groupID = 811; // see Reporter for more information about groupID |
60 | entries = new String[numColumns]; |
61 | } |
62 | |
63 | /** |
64 | * Returns an array of Strings each containing the data for the |
65 | * corresponding column in array <code>columns[]</code>. Implement this |
66 | * method in a way, that an array of the same length as the columntitles is |
67 | * produced containing the data at the point of time this method is called |
68 | * by someone else to produce up-to-date information. |
69 | * |
70 | * @return java.lang.String[] : Array containing the data for reporting |
71 | */ |
72 | public String[] getEntries() { |
73 | if (source instanceof desmoj.core.advancedModellingFeatures.Res) { |
74 | // the Res we report about |
75 | desmoj.core.advancedModellingFeatures.Res rs = (desmoj.core.advancedModellingFeatures.Res) source; // source |
76 | // = |
77 | // informationSource |
78 | |
79 | // Title |
80 | entries[0] = rs.getName(); |
81 | // order |
82 | entries[1] = rs.getQueueStrategy(); |
83 | // pass |
84 | String pass = "no"; |
85 | if (rs.getPassBy()) { |
86 | pass = "yes"; |
87 | } |
88 | entries[2] = pass; |
89 | // (Re)set |
90 | entries[3] = rs.resetAt().toString(); |
91 | // Users |
92 | entries[4] = Long.toString(rs.getUsers()); |
93 | // Limit |
94 | entries[5] = Long.toString(rs.getLimit()); |
95 | // Min |
96 | entries[6] = Long.toString(rs.getMinimum()); |
97 | // Now. |
98 | entries[7] = Long.toString(rs.getAvail()); |
99 | // Usage[%] |
100 | // round to percentage |
101 | entries[8] = Double.toString(StatisticObject.round(rs.avgUsage() * 100)); |
102 | // avg.Wait |
103 | entries[9] = rs.averageWaitTime().toString(); |
104 | // Qlimit |
105 | entries[10] = Long.toString(rs.getQueueLimit()); |
106 | if (rs.getQueueLimit() == Integer.MAX_VALUE) { |
107 | entries[10] = "unlimit."; |
108 | } |
109 | // QMaxL |
110 | entries[11] = Long.toString(rs.maxLength()); |
111 | // refused |
112 | entries[12] = Long.toString(rs.getRefused()); |
113 | // DL |
114 | String deadLock = "no"; |
115 | if (rs.isDeadlockDetected()) { |
116 | deadLock = "yes"; |
117 | } |
118 | entries[13] = deadLock; |
119 | } else { |
120 | for (int i = 0; i < numColumns; i++) { |
121 | entries[i] = "Invalid source!"; |
122 | } // end for |
123 | } // end else |
124 | |
125 | return entries; |
126 | } |
127 | } // end class ResourceReporter |