1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
package org.melati.test; |
47 | |
|
48 | |
import java.io.IOException; |
49 | |
import java.text.NumberFormat; |
50 | |
import java.util.Date; |
51 | |
import java.util.Enumeration; |
52 | |
|
53 | |
import javax.servlet.ServletException; |
54 | |
|
55 | |
import org.melati.Melati; |
56 | |
import org.melati.poem.Database; |
57 | |
import org.melati.poem.PoemThread; |
58 | |
import org.melati.poem.SessionToken; |
59 | |
import org.melati.poem.transaction.Transaction; |
60 | |
import org.melati.servlet.ConfigServlet; |
61 | |
import org.melati.util.MelatiWriter; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | 1 | public class SessionAnalysisServlet extends ConfigServlet { |
72 | |
private static final long serialVersionUID = 1L; |
73 | |
private MelatiWriter output; |
74 | |
|
75 | |
protected void doConfiguredRequest(Melati melati) |
76 | |
throws ServletException, IOException { |
77 | |
|
78 | 1 | melati.getResponse().setContentType("text/html"); |
79 | 1 | output = melati.getWriter(); |
80 | 1 | Date now = new Date(); |
81 | 1 | println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD " |
82 | |
+ "HTML 4.01 Transitional//EN\">\n"); |
83 | 1 | println("<html>\n"); |
84 | 1 | println("<head>\n"); |
85 | 1 | println("<title>Transaction Analysis</title>\n"); |
86 | 1 | String repeat = melati.getRequest().getParameter("repeat"); |
87 | 1 | if (repeat != null) |
88 | 0 | println("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"" |
89 | |
+ repeat + "; URL=" |
90 | 0 | + melati.getRequest().getRequestURI() + "?repeat=" |
91 | |
+ repeat + "\">"); |
92 | 2 | println(" <link rel='stylesheet' title='Default' href='" + |
93 | 1 | melati.getConfig().getStaticURL() + "/admin.css' \n" + |
94 | |
"type='text/css' media='screen'>\n"); |
95 | 1 | println("</head>"); |
96 | 1 | println("<body>"); |
97 | 1 | println("<h1>Transactions Analysis</h1>"); |
98 | 1 | println("<p>Run at " + now + "</p>\n"); |
99 | 2 | println("<p>JVM Free memory: " + |
100 | 1 | NumberFormat.getInstance().format(Runtime.getRuntime().freeMemory()) |
101 | |
+ "</p>\n" |
102 | |
+ "<p>JVM Total memory: " + |
103 | 1 | NumberFormat.getInstance().format(Runtime.getRuntime().totalMemory()) |
104 | |
+ "</p>\n" |
105 | |
+ "<form action=''>Reload every " |
106 | |
+ "<input name='repeat' size='5' value='" |
107 | |
+ repeat + "'> seconds <input type=submit></form>\n"); |
108 | |
|
109 | |
|
110 | 1 | println("<h2>Poem sessions</h2>\n"); |
111 | |
|
112 | 1 | Enumeration<SessionToken> e = PoemThread.openSessions().elements(); |
113 | |
|
114 | 1 | int totalSessions = 0; |
115 | 1 | while(e.hasMoreElements()) { |
116 | 0 | totalSessions++; |
117 | 0 | SessionToken token = e.nextElement(); |
118 | 0 | println("<table border='1' cellspacing='0' cellpadding='1'>"); |
119 | 0 | println(" <tr><th colspan='2'>Session: " + token + "</td></tr>"); |
120 | 0 | println(" <tr><th>Running for</th><td>" + (now.getTime() - token.getStarted()) + " ms</td></tr>"); |
121 | 0 | println(" <tr><th>Thread</th><td>" + token.getThread() + "</td></tr>"); |
122 | 0 | println(" <tr><th>PoemTransaction</th><td>" |
123 | 0 | + token.getTransaction() + "<br>(Database:" |
124 | 0 | + token.getTransaction().getDatabase() + ")</td></tr>"); |
125 | 0 | println(" <tr><th>PoemTask</th><td>" + token.getTask() + "</td></tr>\n"); |
126 | 0 | Enumeration<Object> o = token.toTidy().elements(); |
127 | 0 | if(o.hasMoreElements()) { |
128 | 0 | println("<tr><th>Open: </th><td>"); |
129 | 0 | while (o.hasMoreElements()) { |
130 | 0 | println(o.nextElement() + "<br>"); |
131 | |
} |
132 | 0 | println("</td></tr>\n"); |
133 | |
} |
134 | 0 | println("</table>\n"); |
135 | 0 | } |
136 | 1 | println("<h4>Poem sessions in use: " + totalSessions + "</h4>\n"); |
137 | |
|
138 | 1 | println("<h2>Initialised Databases</h2>"); |
139 | 1 | println("<table border=1 cellspacing=0 cellpadding=1>"); |
140 | 1 | println("<tr><th>Database</th><th>PoemTransaction</th>"); |
141 | 1 | println("<th>Free</th><th>Blocked</th></tr>\n"); |
142 | |
|
143 | 1 | int totalDbs = 0; |
144 | 1 | Enumeration<Database> dbs = org.melati.LogicalDatabase.initialisedDatabases(). |
145 | 1 | elements(); |
146 | 4 | while(dbs.hasMoreElements()) { |
147 | 3 | totalDbs++; |
148 | 3 | Database db = dbs.nextElement(); |
149 | 3 | println("<tr>"); |
150 | 3 | println(" <td>" + db.getDisplayName() + "</td>"); |
151 | 3 | println(" <td>" + db + "</td>"); |
152 | 3 | println(" <td>" + db.getFreeTransactionsCount() + "</td>"); |
153 | 3 | println(" <td>" + (db.transactionsMax() - db.getFreeTransactionsCount()) + "</td>"); |
154 | |
|
155 | 3 | println("</tr>"); |
156 | 27 | for(int i=0; i < db.transactionsMax(); i++) { |
157 | 24 | boolean isFree = db.isFree(db.poemTransaction(i)); |
158 | 24 | Transaction blockedOn = db.poemTransaction(i).getBlockedOn(); |
159 | 48 | println("<tr><td> </td>\n" |
160 | 24 | + "<td>" + db.poemTransaction(i) + "</td>\n" |
161 | |
+ "<td bgcolor=" + (isFree ? "green" : "red") + ">" |
162 | |
+ isFree + "</td>\n" |
163 | |
+ "<td bgcolor=" + (blockedOn != null ? "red" : "green") + ">" |
164 | 0 | + (blockedOn != null ? blockedOn.toString() : " ") + "</td>\n" |
165 | |
+ "</tr>\n"); |
166 | |
} |
167 | 3 | } |
168 | 1 | println("</table>\n"); |
169 | 1 | println("<h4>Initialised databases in use: " + totalDbs + "</h4>"); |
170 | |
|
171 | |
|
172 | 1 | println("</body>\n"); |
173 | 1 | println("</html>\n"); |
174 | 1 | } |
175 | |
|
176 | |
void println(String in) throws IOException { |
177 | 62 | output.write(in + "\n"); |
178 | 62 | } |
179 | |
} |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|