001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.core.qos.gossip;
028:
029: import java.io.PrintWriter;
030:
031: import javax.servlet.http.HttpServletRequest;
032:
033: import org.cougaar.core.component.ServiceBroker;
034: import org.cougaar.core.servlet.ServletFrameset;
035:
036: /**
037: * Servlet to display Gossip overhead statistics.
038: */
039: public class GossipServlet extends ServletFrameset {
040:
041: private GossipStatisticsService statisticsService;
042:
043: public GossipServlet(ServiceBroker sb) {
044: super (sb);
045: statisticsService = (GossipStatisticsService) sb.getService(
046: this , GossipStatisticsService.class, null);
047: }
048:
049: public String getPath() {
050: return "/metrics/gossip";
051: }
052:
053: public String getTitle() {
054: return getNodeID() + " Gossip Statistics";
055: }
056:
057: private void printRow(PrintWriter out, String label, int count) {
058: out.print("<tr><b>");
059: out.print("<td><b>");
060: out.print(label);
061: out.print("</b></td>");
062: out.print("<td><b>");
063: out.print(count);
064: out.print("</b></td>");
065: out.print("</b></tr>");
066: }
067:
068: public void printPage(HttpServletRequest request, PrintWriter out) {
069: // String reset_string = request.getParameter("reset");
070: // boolean reset = reset_string != null &&
071: // reset_string.equalsIgnoreCase("true");
072:
073: GossipTrafficRecord stats = null;
074: if (statisticsService != null) {
075: stats = statisticsService.getStatistics();
076: }
077: if (stats == null) {
078: out.print("<p><b>");
079: out
080: .print("ERROR: Gossip Statistics Service is not Available\n");
081: out
082: .print("</b><p> org.cougaar.core.mts.GossipStatisticsServiceAspect ");
083: out.print("should be loaded into Node \n");
084: return;
085: }
086: out.print("<h2>Gossip for node ");
087: out.print(getNodeID());
088: out.println("</h2>");
089: out.print("<table border=1>\n");
090:
091: printRow(out, "Requests Sent", stats.getRequestsSent());
092: printRow(out, "Requests Received", stats.getRequestsReceived());
093: printRow(out, "Values Sent", stats.getValuesSent());
094: printRow(out, "Values Received", stats.getValuesReceived());
095: printRow(out, "Messages with Gossip Sent", stats
096: .getMessagesWithGossipSent());
097: printRow(out, "Messages with Gossip Received", stats
098: .getMessagesWithGossipReceived());
099: printRow(out, "Total Messages Sent", stats.getMessagesSent());
100: printRow(out, "Total Messages Received", stats
101: .getMessagesReceived());
102: out.println("</table>");
103:
104: }
105: }
|