1 6 package org.logicalcobwebs.proxool.admin.servlet; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 import org.logicalcobwebs.proxool.*; 11 import org.logicalcobwebs.proxool.admin.SnapshotIF; 12 import org.logicalcobwebs.proxool.admin.StatisticsIF; 13 14 import javax.servlet.ServletConfig ; 15 import javax.servlet.ServletException ; 16 import javax.servlet.ServletOutputStream ; 17 import javax.servlet.http.HttpServlet ; 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpServletResponse ; 20 import java.io.IOException ; 21 import java.text.DateFormat ; 22 import java.text.DecimalFormat ; 23 import java.text.SimpleDateFormat ; 24 import java.util.Calendar ; 25 import java.util.Date ; 26 import java.util.Iterator ; 27 import java.util.Properties ; 28 29 69 public class AdminServlet extends HttpServlet { 70 71 private static final Log LOG = LogFactory.getLog(AdminServlet.class); 72 73 82 private static final String [] STATUS_CLASSES = {"null", "available", "active", "offline"}; 83 84 89 public static final String OUTPUT_FULL = "full"; 90 91 96 public static final String OUTPUT_SIMPLE = "simple"; 97 98 102 private String output; 103 104 108 109 private String cssFile; 110 111 114 private static final String STATISTIC = "statistic"; 115 116 119 private static final String CORE_PROPERTY = "core-property"; 120 121 124 private static final String STANDARD_PROPERTY = "standard-property"; 125 126 129 private static final String DELEGATED_PROPERTY = "delegated-property"; 130 131 134 private static final String SNAPSHOT = "snapshot"; 135 136 public void init(ServletConfig servletConfig) throws ServletException { 137 super.init(servletConfig); 138 139 output = servletConfig.getInitParameter("output"); 141 if (output != null) { 142 if (output.equalsIgnoreCase(OUTPUT_FULL)) { 143 output = OUTPUT_FULL; 144 } else if (output.equalsIgnoreCase(OUTPUT_SIMPLE)) { 145 output = OUTPUT_SIMPLE; 146 } else { 147 LOG.warn("Unrecognised output parameter for " + this.getClass().getName() + ". Expected: " + OUTPUT_FULL + " or " + OUTPUT_SIMPLE); 148 output = null; 149 } 150 } 151 if (output == null) { 152 output = OUTPUT_FULL; 153 } 154 155 cssFile = servletConfig.getInitParameter("cssFile"); 156 157 } 158 159 163 private static final DateFormat TIME_FORMAT = new SimpleDateFormat ("HH:mm:ss"); 164 165 168 private static final DateFormat DATE_FORMAT = new SimpleDateFormat ("dd-MMM-yyyy HH:mm:ss"); 169 170 private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat ("0.00"); 171 172 private static final String DETAIL = "detail"; 173 private static final String DETAIL_MORE = "more"; 174 private static final String DETAIL_LESS = "less"; 175 176 184 private static final String TAB = "tab"; 185 186 189 private static final String TAB_DEFINITION = "definition"; 190 191 194 private static final String TAB_SNAPSHOT = "snapshot"; 195 196 199 private static final String TAB_STATISTICS = "statistics"; 200 201 204 private static final String ALIAS = "alias"; 205 206 211 private static final String CONNECTION_ID = "id"; 212 213 216 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 217 doGet(request, response); 218 } 219 220 223 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 224 225 response.setHeader("Pragma", "no-cache"); 226 String link = request.getRequestURI(); 227 228 String alias = request.getParameter(ALIAS); 231 ConnectionPoolDefinitionIF def = null; 233 if (alias != null) { 234 try { 235 def = ProxoolFacade.getConnectionPoolDefinition(alias); 236 } catch (ProxoolException e) { 237 alias = null; 238 } 239 } 240 String [] aliases = ProxoolFacade.getAliases(); 241 if (alias == null) { 242 if (aliases.length > 0) { 243 alias = aliases[0]; 244 } 245 } 246 if (def == null && alias != null) { 247 try { 248 def = ProxoolFacade.getConnectionPoolDefinition(alias); 249 } catch (ProxoolException e) { 250 throw new ServletException ("Couldn't find pool with alias " + alias); 251 } 252 } 253 254 String tab = request.getParameter(TAB); 255 if (tab == null) { 256 tab = TAB_DEFINITION; 257 } 258 259 String snapshotDetail = request.getParameter(DETAIL); 261 262 String snapshotConnectionId = request.getParameter(CONNECTION_ID); 264 265 try { 266 if (output.equals(OUTPUT_FULL)) { 267 response.setContentType("text/html"); 268 openHtml(response.getOutputStream()); 269 } 270 response.getOutputStream().println("<div class=\"version\">Proxool " + Version.getVersion() + "</div>"); 271 doList(response.getOutputStream(), alias, tab, link); 272 if (aliases != null && aliases.length > 0) { 274 StatisticsIF[] statisticsArray = ProxoolFacade.getStatistics(alias); 275 final boolean statisticsAvailable = (statisticsArray != null && statisticsArray.length > 0); 276 final boolean statisticsComingSoon = def.getStatistics() != null; 277 if (!statisticsComingSoon && tab.equals(TAB_STATISTICS)) { 279 tab = TAB_DEFINITION; 280 } 281 doTabs(response.getOutputStream(), alias, link, tab, statisticsAvailable, statisticsComingSoon); 282 if (tab.equals(TAB_DEFINITION)) { 283 doDefinition(response.getOutputStream(), def); 284 } else if (tab.equals(TAB_SNAPSHOT)) { 285 doSnapshot(response.getOutputStream(), def, link, snapshotDetail, snapshotConnectionId); 286 } else if (tab.equals(TAB_STATISTICS)) { 287 doStatistics(response.getOutputStream(), statisticsArray, def); 288 } else { 289 throw new ServletException ("Unrecognised tab '" + tab + "'"); 290 } 291 } 292 } catch (ProxoolException e) { 293 throw new ServletException ("Problem serving Proxool Admin", e); 294 } 295 296 if (output.equals(OUTPUT_FULL)) { 297 closeHtml(response.getOutputStream()); 298 } 299 300 } 301 302 311 private void doTabs(ServletOutputStream out, String alias, String link, String tab, boolean statisticsAvailable, boolean statisticsComingSoon) throws IOException { 312 out.println("<ul>"); 313 out.println("<li class=\"" + (tab.equals(TAB_DEFINITION) ? "active" : "inactive") + "\"><a class=\"quiet\" HREF=\"" + link + "?alias=" + alias + "&tab=" + TAB_DEFINITION + "\">Definition</a></li>"); 314 out.println("<li class=\"" + (tab.equals(TAB_SNAPSHOT) ? "active" : "inactive") + "\"><a class=\"quiet\" HREF=\"" + link + "?alias=" + alias + "&tab=" + TAB_SNAPSHOT + "\">Snapshot</a></li>"); 315 if (statisticsAvailable) { 316 out.println("<li class=\"" + (tab.equals(TAB_STATISTICS) ? "active" : "inactive") + "\"><a class=\"quiet\" HREF=\"" + link + "?alias=" + alias + "&tab=" + TAB_STATISTICS + "\">Statistics</a></li>"); 317 } else if (statisticsComingSoon) { 318 out.println("<li class=\"disabled\">Statistics</li>"); 319 } 320 out.println("</ul>"); 321 } 322 323 329 private void doStatistics(ServletOutputStream out, StatisticsIF[] statisticsArray, ConnectionPoolDefinitionIF cpd) throws IOException { 330 331 for (int i = 0; i < statisticsArray.length; i++) { 332 StatisticsIF statistics = statisticsArray[i]; 333 334 openDataTable(out); 335 336 printDefinitionEntry(out, ProxoolConstants.ALIAS, cpd.getAlias(), CORE_PROPERTY); 337 338 printDefinitionEntry(out, "Period", TIME_FORMAT.format(statistics.getStartDate()) + " to " + TIME_FORMAT.format(statistics.getStopDate()), STATISTIC); 340 341 printDefinitionEntry(out, "Served", statistics.getServedCount() + " (" + DECIMAL_FORMAT.format(statistics.getServedPerSecond()) + "/s)", STATISTIC); 343 344 printDefinitionEntry(out, "Refused", statistics.getRefusedCount() + " (" + DECIMAL_FORMAT.format(statistics.getRefusedPerSecond()) + "/s)", STATISTIC); 346 347 printDefinitionEntry(out, "Average active time", DECIMAL_FORMAT.format(statistics.getAverageActiveTime() / 1000) + "s", STATISTIC); 349 350 StringBuffer activityLevelBuffer = new StringBuffer (); 352 int activityLevel = (int) (100 * statistics.getAverageActiveCount() / cpd.getMaximumConnectionCount()); 353 activityLevelBuffer.append(activityLevel); 354 activityLevelBuffer.append("%<br/>"); 355 String [] colours = {"0000ff", "eeeeee"}; 356 int[] lengths = {activityLevel, 100 - activityLevel}; 357 drawBarChart(activityLevelBuffer, colours, lengths); 358 printDefinitionEntry(out, "Activity level", activityLevelBuffer.toString(), STATISTIC); 359 360 closeTable(out); 361 } 362 } 363 364 371 private void drawBarChart(StringBuffer out, String [] colours, int[] lengths) { 372 out.append("<table style=\"margin: 8px; font-size: 50%;\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>"); 373 374 int totalLength = 0; 376 for (int i = 0; i < colours.length; i++) { 377 totalLength += lengths[i]; 378 } 379 380 for (int j = 0; j < colours.length; j++) { 382 String colour = colours[j]; 383 int length = lengths[j]; 384 if (length > 0) { 385 out.append("<td style=\"background-color: #"); 386 out.append(colour); 387 out.append("\" width=\""); 388 out.append(100 * length / totalLength); 389 out.append("%\"> </td>"); 390 } 391 } 392 out.append("</tr></table>"); 393 } 394 395 400 private void doDefinition(ServletOutputStream out, ConnectionPoolDefinitionIF cpd) throws IOException { 401 openDataTable(out); 402 403 406 printDefinitionEntry(out, ProxoolConstants.ALIAS, cpd.getAlias(), CORE_PROPERTY); 407 printDefinitionEntry(out, ProxoolConstants.DRIVER_URL, cpd.getUrl(), CORE_PROPERTY); 408 printDefinitionEntry(out, ProxoolConstants.DRIVER_CLASS, cpd.getDriver(), CORE_PROPERTY); 409 printDefinitionEntry(out, ProxoolConstants.MINIMUM_CONNECTION_COUNT, String.valueOf(cpd.getMinimumConnectionCount()), STANDARD_PROPERTY); 410 printDefinitionEntry(out, ProxoolConstants.MAXIMUM_CONNECTION_COUNT, String.valueOf(cpd.getMaximumConnectionCount()), STANDARD_PROPERTY); 411 printDefinitionEntry(out, ProxoolConstants.PROTOTYPE_COUNT, cpd.getPrototypeCount() > 0 ? String.valueOf(cpd.getPrototypeCount()) : null, STANDARD_PROPERTY); 412 printDefinitionEntry(out, ProxoolConstants.SIMULTANEOUS_BUILD_THROTTLE, String.valueOf(cpd.getSimultaneousBuildThrottle()), STANDARD_PROPERTY); 413 printDefinitionEntry(out, ProxoolConstants.MAXIMUM_CONNECTION_LIFETIME, formatMilliseconds(cpd.getMaximumConnectionLifetime()), STANDARD_PROPERTY); 414 printDefinitionEntry(out, ProxoolConstants.MAXIMUM_ACTIVE_TIME, formatMilliseconds(cpd.getMaximumActiveTime()), STANDARD_PROPERTY); 415 printDefinitionEntry(out, ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME, (cpd.getHouseKeepingSleepTime() / 1000) + "s", STANDARD_PROPERTY); 416 printDefinitionEntry(out, ProxoolConstants.HOUSE_KEEPING_TEST_SQL, cpd.getHouseKeepingTestSql(), STANDARD_PROPERTY); 417 printDefinitionEntry(out, ProxoolConstants.TEST_BEFORE_USE, String.valueOf(cpd.isTestBeforeUse()), STANDARD_PROPERTY); 418 printDefinitionEntry(out, ProxoolConstants.TEST_AFTER_USE, String.valueOf(cpd.isTestAfterUse()), STANDARD_PROPERTY); 419 printDefinitionEntry(out, ProxoolConstants.RECENTLY_STARTED_THRESHOLD, formatMilliseconds(cpd.getRecentlyStartedThreshold()), STANDARD_PROPERTY); 420 printDefinitionEntry(out, ProxoolConstants.OVERLOAD_WITHOUT_REFUSAL_LIFETIME, formatMilliseconds(cpd.getOverloadWithoutRefusalLifetime()), STANDARD_PROPERTY); 421 printDefinitionEntry(out, ProxoolConstants.INJECTABLE_CONNECTION_INTERFACE_NAME, String.valueOf(cpd.getInjectableConnectionInterface()), STANDARD_PROPERTY); 422 printDefinitionEntry(out, ProxoolConstants.INJECTABLE_STATEMENT_INTERFACE_NAME, String.valueOf(cpd.getInjectableStatementInterface()), STANDARD_PROPERTY); 423 printDefinitionEntry(out, ProxoolConstants.INJECTABLE_CALLABLE_STATEMENT_INTERFACE_NAME, String.valueOf(cpd.getInjectableCallableStatementInterface()), STANDARD_PROPERTY); 424 printDefinitionEntry(out, ProxoolConstants.INJECTABLE_PREPARED_STATEMENT_INTERFACE_NAME, String.valueOf(cpd.getInjectablePreparedStatementInterface()), STANDARD_PROPERTY); 425 426 String fatalSqlExceptions = null; 428 if (cpd.getFatalSqlExceptions() != null && cpd.getFatalSqlExceptions().size() > 0) { 429 StringBuffer fatalSqlExceptionsBuffer = new StringBuffer (); 430 Iterator i = cpd.getFatalSqlExceptions().iterator(); 431 while (i.hasNext()) { 432 String s = (String ) i.next(); 433 fatalSqlExceptionsBuffer.append(s); 434 fatalSqlExceptionsBuffer.append(i.hasNext() ? ", " : ""); 435 } 436 fatalSqlExceptions = fatalSqlExceptionsBuffer.toString(); 437 } 438 printDefinitionEntry(out, ProxoolConstants.FATAL_SQL_EXCEPTION, fatalSqlExceptions, STANDARD_PROPERTY); 439 printDefinitionEntry(out, ProxoolConstants.FATAL_SQL_EXCEPTION_WRAPPER_CLASS, cpd.getFatalSqlExceptionWrapper(), STANDARD_PROPERTY); 440 printDefinitionEntry(out, ProxoolConstants.STATISTICS, cpd.getStatistics(), STANDARD_PROPERTY); 441 printDefinitionEntry(out, ProxoolConstants.STATISTICS_LOG_LEVEL, cpd.getStatisticsLogLevel(), STANDARD_PROPERTY); 442 printDefinitionEntry(out, ProxoolConstants.VERBOSE, String.valueOf(cpd.isVerbose()), STANDARD_PROPERTY); 443 printDefinitionEntry(out, ProxoolConstants.TRACE, String.valueOf(cpd.isTrace()), STANDARD_PROPERTY); 444 Properties p = cpd.getDelegateProperties(); 446 Iterator i = p.keySet().iterator(); 447 while (i.hasNext()) { 448 String name = (String ) i.next(); 449 String value = p.getProperty(name); 450 if (name.toLowerCase().indexOf("password") > -1 || name.toLowerCase().indexOf("passwd") > -1) { 452 value = "******"; 453 } 454 printDefinitionEntry(out, name + " (delegated)", value, DELEGATED_PROPERTY); 455 } 456 457 closeTable(out); 458 459 } 460 461 469 private void doSnapshot(ServletOutputStream out, ConnectionPoolDefinitionIF cpd, String link, String level, String connectionId) throws IOException , ProxoolException { 470 boolean detail = (level != null && level.equals(DETAIL_MORE)); 471 SnapshotIF snapshot = ProxoolFacade.getSnapshot(cpd.getAlias(), detail); 472 473 if (snapshot != null) { 474 475 openDataTable(out); 476 477 printDefinitionEntry(out, ProxoolConstants.ALIAS, cpd.getAlias(), CORE_PROPERTY); 478 479 printDefinitionEntry(out, "Start date", DATE_FORMAT.format(snapshot.getDateStarted()), SNAPSHOT); 481 482 printDefinitionEntry(out, "Snapshot", TIME_FORMAT.format(snapshot.getSnapshotDate()), SNAPSHOT); 484 485 StringBuffer connectionsBuffer = new StringBuffer (); 487 connectionsBuffer.append(snapshot.getActiveConnectionCount()); 488 connectionsBuffer.append(" (active), "); 489 connectionsBuffer.append(snapshot.getAvailableConnectionCount()); 490 connectionsBuffer.append(" (available), "); 491 if (snapshot.getOfflineConnectionCount() > 0) { 492 connectionsBuffer.append(snapshot.getOfflineConnectionCount()); 493 connectionsBuffer.append(" (offline), "); 494 } 495 connectionsBuffer.append(snapshot.getMaximumConnectionCount()); 496 connectionsBuffer.append(" (max)<br/>"); 497 String [] colours = {"ff9999", "66cc66", "cccccc"}; 498 int[] lengths = {snapshot.getActiveConnectionCount(), snapshot.getAvailableConnectionCount(), 499 snapshot.getMaximumConnectionCount() - snapshot.getActiveConnectionCount() - snapshot.getAvailableConnectionCount()}; 500 drawBarChart(connectionsBuffer, colours, lengths); 501 printDefinitionEntry(out, "Connections", connectionsBuffer.toString(), SNAPSHOT); 502 503 printDefinitionEntry(out, "Served", String.valueOf(snapshot.getServedCount()), SNAPSHOT); 505 506 printDefinitionEntry(out, "Refused", String.valueOf(snapshot.getRefusedCount()), SNAPSHOT); 508 509 if (!detail) { 510 out.println(" <tr>"); 511 out.print(" <td colspan=\"2\" align=\"right\"><form action=\"" + link + "\" method=\"GET\">"); 512 out.print("<input type=\"hidden\" name=\"" + ALIAS + "\" value=\"" + cpd.getAlias() + "\">"); 513 out.print("<input type=\"hidden\" name=\"" + TAB + "\" value=\"" + TAB_SNAPSHOT + "\">"); 514 out.print("<input type=\"hidden\" name=\"" + DETAIL + "\" value=\"" + DETAIL_MORE + "\">"); 515 out.print("<input type=\"submit\" value=\"More information>\">"); 516 out.println("</form></td>"); 517 out.println(" </tr>"); 518 } else { 519 520 out.println(" <tr>"); 521 out.print(" <th width=\"200\" valign=\"top\">"); 522 out.print("Details:<br>(click ID to drill down)"); 523 out.println("</th>"); 524 out.print(" <td>"); 525 526 doSnapshotDetails(out, cpd, snapshot, link, connectionId); 527 528 out.println("</td>"); 529 out.println(" </tr>"); 530 531 long drillDownConnectionId; 532 if (connectionId != null) { 533 drillDownConnectionId = Long.valueOf(connectionId).longValue(); 534 ConnectionInfoIF drillDownConnection = snapshot.getConnectionInfo(drillDownConnectionId); 535 if (drillDownConnection != null) { 536 out.println(" <tr>"); 537 out.print(" <th valign=\"top\">"); 538 out.print("Connection #" + connectionId); 539 out.println("</td>"); 540 out.print(" <td>"); 541 542 doDrillDownConnection(out, drillDownConnection); 543 544 out.println("</td>"); 545 out.println(" </tr>"); 546 } 547 } 548 549 out.println(" <tr>"); 550 out.print(" <td colspan=\"2\" align=\"right\"><form action=\"" + link + "\" method=\"GET\">"); 551 out.print("<input type=\"hidden\" name=\"" + ALIAS + "\" value=\"" + cpd.getAlias() + "\">"); 552 out.print("<input type=\"hidden\" name=\"" + TAB + "\" value=\"" + TAB_SNAPSHOT + "\">"); 553 out.print("<input type=\"hidden\" name=\"" + DETAIL + "\" value=\"" + DETAIL_LESS + "\">"); 554 out.print("<input type=\"submit\" value=\"< Less information\">"); 555 out.println("</form></td>"); 556 out.println(" </tr>"); 557 } 558 559 closeTable(out); 560 } 561 } 562 563 574 private void doSnapshotDetails(ServletOutputStream out, ConnectionPoolDefinitionIF cpd, SnapshotIF snapshot, String link, String connectionId) throws IOException { 575 576 long drillDownConnectionId = 0; 577 if (connectionId != null) { 578 drillDownConnectionId = Long.valueOf(connectionId).longValue(); 579 } 580 581 if (snapshot.getConnectionInfos() != null && snapshot.getConnectionInfos().length > 0) { 582 out.println("<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\">"); 583 out.println(" <tbody>"); 584 585 out.print("<tr>"); 586 out.print("<td>#</td>"); 587 out.print("<td align=\"center\">born</td>"); 588 out.print("<td align=\"center\">last<br>start</td>"); 589 out.print("<td align=\"center\">lap<br>(ms)</td>"); 590 out.print("<td> thread</td>"); 591 out.print("</tr>"); 592 593 ConnectionInfoIF[] connectionInfos = snapshot.getConnectionInfos(); 594 for (int i = 0; i < connectionInfos.length; i++) { 595 ConnectionInfoIF connectionInfo = connectionInfos[i]; 596 597 if (connectionInfo.getStatus() != ConnectionInfoIF.STATUS_NULL) { 598 599 out.print("<tr>"); 600 601 out.print("<td style=\"background-color: #"); 603 if (connectionInfo.getStatus() == ConnectionInfoIF.STATUS_ACTIVE) { 604 out.print("ffcccc"); 605 } else if (connectionInfo.getStatus() == ConnectionInfoIF.STATUS_AVAILABLE) { 606 out.print("ccffcc"); 607 } else if (connectionInfo.getStatus() == ConnectionInfoIF.STATUS_OFFLINE) { 608 out.print("ccccff"); 609 } 610 out.print("\" style=\""); 611 612 if (drillDownConnectionId == connectionInfo.getId()) { 613 out.print("border: 1px solid black;"); 614 out.print("\">"); 615 out.print(connectionInfo.getId()); 616 } else { 617 out.print("border: 1px solid transparent;"); 618 out.print("\"><a HREF=\""); 619 out.print(link); 620 out.print("?"); 621 out.print(ALIAS); 622 out.print("="); 623 out.print(cpd.getAlias()); 624 out.print("&"); 625 out.print(TAB); 626 out.print("="); 627 out.print(TAB_SNAPSHOT); 628 out.print("&"); 629 out.print(DETAIL); 630 out.print("="); 631 out.print(DETAIL_MORE); 632 out.print("&"); 633 out.print(CONNECTION_ID); 634 out.print("="); 635 out.print(connectionInfo.getId()); 636 out.print("\">"); 637 out.print(connectionInfo.getId()); 638 out.print("</a>"); 639 } 640 out.print("</td>"); 641 642 out.print("<td> "); 644 out.print(TIME_FORMAT.format(connectionInfo.getBirthDate())); 645 out.print("</td>"); 646 647 out.print("<td> "); 649 out.print(connectionInfo.getTimeLastStartActive() > 0 ? TIME_FORMAT.format(new Date (connectionInfo.getTimeLastStartActive())) : "-"); 650 out.print("</td>"); 651 652 out.print("<td align=\"right\" class=\""); 654 out.print(getStatusClass(connectionInfo)); 655 out.print("\">"); 656 String active = " "; 657 if (connectionInfo.getTimeLastStopActive() > 0) { 658 active = String.valueOf((int) (connectionInfo.getTimeLastStopActive() - connectionInfo.getTimeLastStartActive())); 659 } else if (connectionInfo.getTimeLastStartActive() > 0) { 660 active = String.valueOf((int) (snapshot.getSnapshotDate().getTime() - connectionInfo.getTimeLastStartActive())); 661 } 662 out.print(active); 663 out.print(" </td>"); 664 665 out.print("<td> "); 667 out.print(connectionInfo.getRequester() != null ? connectionInfo.getRequester() : "-"); 668 out.print("</td>"); 669 670 out.println("</tr>"); 671 } 672 } 673 out.println(" </tbody>"); 674 out.println("</table>"); 675 676 } else { 677 out.println("No connections yet"); 678 } 679 } 680 681 687 private static String getStatusClass(ConnectionInfoIF info) { 688 try { 689 return STATUS_CLASSES[info.getStatus()]; 690 } catch (ArrayIndexOutOfBoundsException e) { 691 LOG.warn("Unknown status: " + info.getStatus()); 692 return "unknown-" + info.getStatus(); 693 } 694 } 695 696 private void doDrillDownConnection(ServletOutputStream out, ConnectionInfoIF drillDownConnection) throws IOException { 697 698 String [] sqlCalls = drillDownConnection.getSqlCalls(); 700 for (int i = 0; sqlCalls != null && i < sqlCalls.length; i++) { 701 String sqlCall = sqlCalls[i]; 702 out.print("<div class=\"drill-down\">"); 703 out.print("sql = "); 704 out.print(sqlCall); 705 out.print("</div>"); 706 } 707 708 out.print("<div class=\"drill-down\">"); 710 out.print("proxy = "); 711 out.print(drillDownConnection.getProxyHashcode()); 712 out.print("</div>"); 713 714 out.print("<div class=\"drill-down\">"); 716 out.print("delegate = "); 717 out.print(drillDownConnection.getDelegateHashcode()); 718 out.print("</div>"); 719 720 out.print("<div class=\"drill-down\">"); 722 out.print("url = "); 723 out.print(drillDownConnection.getDelegateUrl()); 724 out.print("</div>"); 725 726 } 727 728 private void openHtml(ServletOutputStream out) throws IOException { 729 out.println("<html><header><title>Proxool Admin</title>"); 730 out.println("<style media=\"screen\">"); 731 out.println("body {background-color: #93bde6;}\n" + 732 "div.version {font-weight: bold; font-size: 100%; margin-bottom: 8px;}\n" + 733 "h1 {font-weight: bold; font-size: 100%}\n" + 734 "option {padding: 2px 24px 2px 4px;}\n" + 735 "input {margin: 0px 0px 4px 12px;}\n" + 736 "table.data {font-size: 90%; border-collapse: collapse; border: 1px solid black;}\n" + 737 "table.data th {background: #bddeff; width: 25em; text-align: left; padding-right: 8px; font-weight: normal; border: 1px solid black;}\n" + 738 "table.data td {background: #ffffff; vertical-align: top; padding: 0px 2px 0px 2px; border: 1px solid black;}\n" + 739 "td.null {background: yellow;}\n" + 740 "td.available {color: black;}\n" + 741 "td.active {color: red;}\n" + 742 "td.offline {color: blue;}\n" + 743 "div.drill-down {}\n" + 744 "ul {list-style: none; padding: 0px; margin: 0px; position: relative; font-size: 90%;}\n" + 745 "li {padding: 0px; margin: 0px 4px 0px 0px; display: inline; border: 1px solid black; border-width: 1px 1px 0px 1px;}\n" + 746 "li.active {background: #bddeff;}\n" + 747 "li.inactive {background: #eeeeee;}\n" + 748 "li.disabled {background: #dddddd; color: #999999; padding: 0px 4px 0px 4px;}\n" + 749 "a.quiet {color: black; text-decoration: none; padding: 0px 4px 0px 4px; }\n" + 750 "a.quiet:hover {background: white;}\n"); 751 out.println("</style>"); 752 if (cssFile != null) { 754 out.println("<link rel=\"stylesheet\" media=\"screen\" type=\"text/css\" HREF=\"" + cssFile + "\"></script>"); 755 } 756 out.println("</header><body>"); 757 } 758 759 private void closeHtml(ServletOutputStream out) throws IOException { 760 out.println("</body></html>"); 761 } 762 763 private void openDataTable(ServletOutputStream out) throws IOException { 764 out.println("<table cellpadding=\"2\" cellspacing=\"0\" border=\"1\" class=\"data\">"); 765 out.println(" <tbody>"); 766 } 767 768 private void closeTable(ServletOutputStream out) throws IOException { 769 out.println(" </tbody>"); 770 out.println("</table>"); 771 out.println("<br/>"); 772 } 773 774 private void printDefinitionEntry(ServletOutputStream out, String name, String value, String type) throws IOException { 775 out.println(" <tr>"); 776 out.print(" <th valign=\"top\">"); 777 out.print(name); 778 out.println(":</th>"); 779 out.print(" <td class=\"" + type + "\"nowrap>"); 780 if (value != null && !value.equals("null")) { 781 out.print(value); 782 } else { 783 out.print("-"); 784 } 785 out.print("</td>"); 786 out.println(" </tr>"); 787 } 788 789 797 private void doList(ServletOutputStream out, String alias, String tab, String link) throws IOException { 798 799 String [] aliases = ProxoolFacade.getAliases(); 800 801 if (aliases.length == 0) { 802 out.println("<p>No pools have been registered.</p>"); 803 } else if (aliases.length == 1) { 804 } else { 806 out.println("<form action=\"" + link + "\" method=\"GET\" name=\"alias\">"); 807 out.println("<select name=\"alias\" size=\"" + Math.min(aliases.length, 5) + "\">"); 808 for (int i = 0; i < aliases.length; i++) { 809 out.print(" <option value=\""); 810 out.print(aliases[i]); 811 out.print("\""); 812 out.print(aliases[i].equals(alias) ? " selected" : ""); 813 out.print(">"); 814 out.print(aliases[i]); 815 out.println("</option>"); 816 } 817 out.println("</select>"); 818 out.println("<input name=\"" + TAB + "\" value=\"" + tab + "\" type=\"hidden\">"); 819 out.println("<input value=\"Show\" type=\"submit\">"); 820 out.println("</form>"); 821 } 822 } 823 824 831 private String formatMilliseconds(int time) { 832 Calendar c = Calendar.getInstance(); 833 c.clear(); 834 c.add(Calendar.MILLISECOND, time); 835 return TIME_FORMAT.format(c.getTime()); 836 } 837 } 838 839 | Popular Tags |