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.mts.std;
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.mts.AgentStatusService;
035: import org.cougaar.core.mts.BaseServlet;
036: import org.cougaar.core.mts.MessageAddress;
037:
038: /**
039: * This servlet displays MTS statistics for the Agent in which it's
040: * loaded. Depending on the extension, the data displayed could be
041: * either local or remote.
042: */
043: abstract public class AgentStatusServlet extends BaseServlet // ServletFrameset
044: {
045:
046: protected AgentStatusService agentStatusService;
047:
048: public AgentStatusServlet(ServiceBroker sb) {
049: super (sb);
050: agentStatusService = (AgentStatusService) sb.getService(this ,
051: AgentStatusService.class, null);
052: }
053:
054: abstract AgentStatusService.AgentState getState(MessageAddress agent);
055:
056: abstract String getDescription(MessageAddress agent);
057:
058: abstract boolean isRemote();
059:
060: private void row(PrintWriter out, String name, String value) {
061: out.print("<tr><b>");
062: out.print("<td><b>");
063: out.print(name);
064: out.print("</b></td><td><b>");
065: out.print(value);
066: out.print("</b></td>");
067: }
068:
069: private void row(PrintWriter out, String name, int value) {
070: row(out, name, Integer.toString(value));
071: }
072:
073: private void row(PrintWriter out, String name, long value) {
074: row(out, name, Long.toString(value));
075: }
076:
077: private void row(PrintWriter out, String name, double value) {
078: row(out, name, Double.toString(value));
079: }
080:
081: public void printPage(HttpServletRequest request, PrintWriter out) {
082: MessageAddress agent = null;
083: String agentString = request.getParameter("agent");
084: if (agentString != null) {
085: agent = MessageAddress.getMessageAddress(agentString);
086: } else {
087: agent = getNodeID();
088: }
089:
090: AgentStatusService.AgentState state = getState(agent);
091:
092: if (state == null) {
093: out.print("<p><b>");
094: out
095: .print("ERROR: Agent Status Service is not Available for Agent ");
096: out.print(agent + "</b><p>");
097: out
098: .println("<p>To Change Agent use cgi parameter: ?agent=agentname<p>");
099: return;
100: }
101: out.print("<h2>");
102: out.print(getDescription(agent));
103: out.print("</h2>");
104: out.print("<table border=1>\n");
105: row(out, "Status", state.status);
106: row(out, "Messages Received", state.receivedCount);
107: row(out, "Bytes Received", state.receivedBytes);
108: row(out, "Last Received Bytes", state.lastReceivedBytes);
109: row(out, "Messages Sent", state.sendCount);
110: row(out, "Messages Delivered", state.deliveredCount);
111: row(out, "Bytes Delivered", state.deliveredBytes);
112: row(out, "Last Delivered Bytes", state.lastDeliveredBytes);
113: if (isRemote()) {
114: row(out, "Queue Length", state.queueLength);
115: row(out, "Last Delivered Latency",
116: state.lastDeliveredLatency);
117: row(out, "Average Delivered Latency",
118: state.averageDeliveredLatency);
119: row(out, "Unregistered Name Error Count",
120: state.unregisteredNameCount);
121: row(out, "Name Lookup Failure Count",
122: state.nameLookupFailureCount);
123: row(out, "Communication Failure Count",
124: state.commFailureCount);
125: row(out, "Misdelivered Message Count",
126: state.misdeliveredMessageCount);
127: row(out, "Last Link Protocol Tried",
128: state.lastLinkProtocolTried);
129: row(out, "Last Link Protocol Success",
130: state.lastLinkProtocolSuccess);
131: }
132: out.print("</b></tr>");
133: out.println("</table><p>");
134: out
135: .println("<p>To Change Agent use cgi parameter: ?agent=agentname<p>");
136: }
137: }
|