| 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 | 2 | 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 | 2 | melati.getResponse().setContentType("text/html"); |
| 79 | 2 | output = melati.getWriter(); |
| 80 | 2 | Date now = new Date(); |
| 81 | 2 | println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD " |
| 82 | |
+ "HTML 4.01 Transitional//EN\">\n"); |
| 83 | 2 | println("<html>\n"); |
| 84 | 2 | println("<head>\n"); |
| 85 | 2 | println("<title>Transaction Analysis</title>\n"); |
| 86 | 2 | String repeat = melati.getRequest().getParameter("repeat"); |
| 87 | 2 | if (repeat != null) |
| 88 | 0 | println("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"" |
| 89 | |
+ repeat + "; URL=" |
| 90 | |
+ melati.getRequest().getRequestURI() + "?repeat=" |
| 91 | |
+ repeat + "\">"); |
| 92 | 2 | println(" <link rel='stylesheet' title='Default' href='" + |
| 93 | |
melati.getConfig().getStaticURL() + "/admin.css' \n" + |
| 94 | |
"type='text/css' media='screen'>\n"); |
| 95 | 2 | println("</head>"); |
| 96 | 2 | println("<body>"); |
| 97 | 2 | println("<h1>Transactions Analysis</h1>"); |
| 98 | 2 | println("<p>Run at " + now + "</p>\n"); |
| 99 | 2 | println("<p>JVM Free memory: " + |
| 100 | |
NumberFormat.getInstance().format(Runtime.getRuntime().freeMemory()) |
| 101 | |
+ "</p>\n" |
| 102 | |
+ "<p>JVM Total memory: " + |
| 103 | |
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 | 2 | println("<h2>Poem sessions</h2>\n"); |
| 111 | |
|
| 112 | 2 | Enumeration<SessionToken> e = PoemThread.openSessions().elements(); |
| 113 | |
|
| 114 | 2 | int totalSessions = 0; |
| 115 | 2 | 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 | |
+ token.getTransaction() + "<br>(Database:" |
| 124 | |
+ 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 | 2 | println("<h4>Poem sessions in use: " + totalSessions + "</h4>\n"); |
| 137 | |
|
| 138 | 2 | println("<h2>Initialised Databases</h2>"); |
| 139 | 2 | println("<table border=1 cellspacing=0 cellpadding=1>"); |
| 140 | 2 | println("<tr><th>Database</th><th>PoemTransaction</th>"); |
| 141 | 2 | println("<th>Free</th><th>Blocked</th></tr>\n"); |
| 142 | |
|
| 143 | 2 | int totalDbs = 0; |
| 144 | 2 | Enumeration<Database> dbs = org.melati.LogicalDatabase.initialisedDatabases(). |
| 145 | |
elements(); |
| 146 | 14 | while(dbs.hasMoreElements()) { |
| 147 | 12 | totalDbs++; |
| 148 | 12 | Database db = dbs.nextElement(); |
| 149 | 12 | println("<tr>"); |
| 150 | 12 | println(" <td>" + db.getDisplayName() + "</td>"); |
| 151 | 12 | println(" <td>" + db + "</td>"); |
| 152 | 12 | println(" <td>" + db.getFreeTransactionsCount() + "</td>"); |
| 153 | 12 | println(" <td>" + (db.transactionsMax() - db.getFreeTransactionsCount()) + "</td>"); |
| 154 | |
|
| 155 | 12 | println("</tr>"); |
| 156 | 60 | for(int i=0; i < db.transactionsMax(); i++) { |
| 157 | 48 | boolean isFree = db.isFree(db.poemTransaction(i)); |
| 158 | 48 | Transaction blockedOn = db.poemTransaction(i).getBlockedOn(); |
| 159 | 48 | println("<tr><td> </td>\n" |
| 160 | |
+ "<td>" + db.poemTransaction(i) + "</td>\n" |
| 161 | |
+ "<td bgcolor=" + (isFree ? "green" : "red") + ">" |
| 162 | |
+ isFree + "</td>\n" |
| 163 | |
+ "<td bgcolor=" + (blockedOn != null ? "red" : "green") + ">" |
| 164 | |
+ (blockedOn != null ? blockedOn.toString() : " ") + "</td>\n" |
| 165 | |
+ "</tr>\n"); |
| 166 | |
} |
| 167 | 12 | } |
| 168 | 2 | println("</table>\n"); |
| 169 | 2 | println("<h4>Initialised databases in use: " + totalDbs + "</h4>"); |
| 170 | |
|
| 171 | |
|
| 172 | 2 | println("</body>\n"); |
| 173 | 2 | println("</html>\n"); |
| 174 | 2 | } |
| 175 | |
|
| 176 | |
void println(String in) throws IOException { |
| 177 | 160 | output.write(in + "\n"); |
| 178 | 160 | } |
| 179 | |
} |
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|