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.metrics;
028:
029: import java.io.PrintWriter;
030: import java.text.DecimalFormat;
031: import java.util.Set;
032:
033: import javax.servlet.http.HttpServletRequest;
034:
035: import org.cougaar.core.agent.AgentContainer;
036: import org.cougaar.core.component.ServiceBroker;
037: import org.cougaar.core.node.NodeControlService;
038: import org.cougaar.core.service.wp.WhitePagesService;
039: import org.cougaar.core.servlet.ServletFrameset;
040:
041: /**
042: * Abstract parent class of many Metrics-related servlets. It
043: * provides some useful text formatters, access to services and lists
044: * of local agents, and a standard bottom frame in a FrameSet.
045: */
046: public abstract class MetricsServlet extends ServletFrameset implements
047: Constants {
048:
049: protected WhitePagesService wpService;
050: protected MetricsService metricsService;
051: protected final DecimalFormat f4_2 = new DecimalFormat("#0.00");
052: protected final DecimalFormat f6_3 = new DecimalFormat("##0.000");
053: protected final DecimalFormat f2_0 = new DecimalFormat("#0");
054: protected final DecimalFormat f3_0 = new DecimalFormat("##0");
055: protected final DecimalFormat f4_0 = new DecimalFormat("###0");
056: protected final DecimalFormat f7_0 = new DecimalFormat("#######0");
057:
058: private AgentContainer agentContainer;
059:
060: public MetricsServlet(ServiceBroker sb) {
061: super (sb);
062:
063: wpService = (WhitePagesService) sb.getService(this ,
064: WhitePagesService.class, null);
065:
066: NodeControlService ncs = (NodeControlService) sb.getService(
067: this , NodeControlService.class, null);
068: if (ncs != null) {
069: agentContainer = ncs.getRootContainer();
070: sb.releaseService(this , NodeControlService.class, ncs);
071: }
072:
073: metricsService = (MetricsService) sb.getService(this ,
074: MetricsService.class, null);
075:
076: }
077:
078: /**
079: * @return the message addresses of the agents on this
080: * node, or null if that information is not available.
081: */
082: protected final Set getLocalAgents() {
083: if (agentContainer == null) {
084: return null;
085: } else {
086: return agentContainer.getAgentAddresses();
087: }
088: }
089:
090: public void printBottomPage(HttpServletRequest request,
091: PrintWriter out) {
092: out.print("<p><b>Color key</b>");
093: ServletUtilities.colorTest(out);
094: }
095:
096: public int dataPercentage() {
097: return 70;
098: }
099:
100: public int bottomPercentage() {
101: return 20;
102: }
103:
104: }
|