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.glm.servlet;
028:
029: import java.io.PrintWriter;
030:
031: import org.cougaar.core.servlet.SimpleServletSupport;
032: import org.cougaar.planning.servlet.ServletBase;
033: import org.cougaar.planning.servlet.ServletWorker;
034:
035: /**
036: * <pre>
037: * A servlet that watches for when a batch of tasks have completed
038: * and returns the time it took to complete.
039: *
040: * See the documentation in glm/doc.
041: *
042: * Gordon Vidaver
043: * gvidaver@bbn.com
044: * (617) 873-3558
045: * </pre>
046: */
047: public class CompletionWatcherServlet extends ServletBase {
048: public void setSimpleServletSupport(SimpleServletSupport support) {
049: super .setSimpleServletSupport(support);
050: }
051:
052: public static final String FIRST_INTERVAL = "firstInterval";
053: public static final String SECOND_INTERVAL = "secondInterval";
054: public static final String VERBS_TO_INCLUDE = "verbsToInclude";
055:
056: public static final boolean DEBUG = false;
057: public static boolean VERBOSE = false;
058:
059: static {
060: VERBOSE = Boolean
061: .getBoolean("org.cougaar.glm.servlet.CompletionWatcherServlet.verbose");
062: }
063:
064: protected ServletWorker createWorker() {
065: return new CompletionWatcherWorker();
066: }
067:
068: /** initial page presented when the servlet is called with no arguments */
069: public void getUsage(PrintWriter out, SimpleServletSupport support) {
070: out
071: .print("<HTML><HEAD><TITLE>CompletionWatcherServlet</TITLE></HEAD><BODY>\n"
072: + "<H2><CENTER>CompletionWatcherServlet</CENTER></H2><P>\n"
073: + "<FORM METHOD=\"GET\" ACTION=\"/$");
074: out.print(support.getEncodedAgentName());
075: out.print(support.getPath());
076: out.print("\">\n");
077:
078: out.print("<font size=+1>Wait for agent <b>"
079: + support.getAgentIdentifier()
080: + "</b> to complete.</font><p>\n");
081: String agentPath = support.getEncodedAgentName()
082: + support.getPath();
083: out.print("<img alt='Watcher Servlet Screen Shot' " + "src='/$"
084: + agentPath + "?getImage=true'><br>");
085: out
086: .print("<center><font size=+1>Although typically used to time the period between GLSInit and when the agent is done,<br>");
087: out
088: .print("the servlet measures any busy period between two quiet periods.</font></center><p>");
089: out
090: .print("Note that the servlet may not return if it cannot go through its states.<p>");
091:
092: out.println("<table>\n");
093:
094: // get seconds to wait for initial quiet period
095: out.println("<tr><td>");
096: out.print("First quiet period duration (in seconds)");
097: out.print("</td><td>");
098: out.print("<INPUT TYPE=\"text\" NAME=\"" + FIRST_INTERVAL
099: + "\" " + "VALUE=\"10\">");
100: out.println("</td></tr>");
101:
102: // get seconds to wait for initial quiet period
103: out.print("<tr><td>");
104: out.print("Second quiet period duration (in seconds)");
105: out.print("</td><td>");
106: out.print("<INPUT TYPE=\"text\" NAME=\"" + SECOND_INTERVAL
107: + "\" " + "VALUE=\"10\">");
108: out.println("</td></tr>");
109:
110: // get verbs to include
111: out.print("<tr><td>");
112: out
113: .print("Verbs of tasks to examine (empty means all). Comma separated.");
114: out.print("</td><td>");
115: out.print("<INPUT TYPE=\"text\" NAME=\"" + VERBS_TO_INCLUDE
116: + "\" " + "VALUE=\"\">");
117: out.println("</td></tr>");
118:
119: out.println("</table><p>");
120:
121: // choose data format - html, xml, or java objects
122: out.print("<center>Show results as "
123: + " <INPUT TYPE=\"radio\" NAME=\"format\" "
124: + "VALUE=\"html\" CHECKED>" + " html ");
125: out.print("<INPUT TYPE=\"radio\" NAME=\"format\" "
126: + "VALUE=\"xml\"> xml ");
127: out.print("<INPUT TYPE=\"radio\" NAME=\"format\" "
128: + "VALUE=\"data\">"
129: + " serialized Java objects<p>\n");
130: out.print("<INPUT TYPE=\"submit\" NAME=\"Inject\"></center>\n"
131: + "</FORM></BODY></HTML>");
132: }
133: }
|