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.util.Observable;
030: import java.util.Observer;
031:
032: import org.cougaar.core.component.ServiceBroker;
033: import org.cougaar.core.mts.MessageAddress;
034:
035: /**
036: * Basic Metric Service Client subscribes to a Metric and prints the
037: * value to standout, when the Metric value ever changes. The path is given as
038: * a parameter when the MetricClientPlugin is loaded. e.g
039: *
040: * <component
041: * name='org.cougaar.core.qos.metrics.MetricsClientPlugin(path=foo)"
042: * class='org.cougaar.core.qos.metrics.MetricsClientPlugin"
043: * insertionpoint='Node.AgentManager.Agent.PluginManager.Plugin'>
044: * <argument>
045: * path=Agent(AgentA):MsgIn100SecAvg
046: * </argument>
047: * </component>
048: */
049: public class MetricsClientPlugin extends
050: org.cougaar.core.plugin.ParameterizedPlugin implements
051: Constants {
052: protected MetricsService metricsService;
053: protected MessageAddress agentID;
054: private String paramPath = null;
055: private VariableEvaluator evaluator;
056:
057: /**
058: * Metric CallBack object
059: */
060: private class MetricsCallback implements Observer {
061: /**
062: * Call back implementation for Observer
063: */
064:
065: public void update(Observable obs, Object arg) {
066: if (arg instanceof Metric) {
067: Metric metric = (Metric) arg;
068: System.out
069: .println("Metric " + paramPath + "=" + metric);
070: }
071: }
072: }
073:
074: /**
075: * load time is when services are lookup
076: */
077: public void load() {
078: super .load();
079: ServiceBroker sb = getServiceBroker();
080:
081: // agentID = getAgentIdentifier();
082:
083: evaluator = new StandardVariableEvaluator(sb);
084:
085: metricsService = (MetricsService) sb.getService(this ,
086: MetricsService.class, null);
087:
088: MetricsCallback cb = new MetricsCallback();
089: paramPath = getParameter("path");
090: if (paramPath == null)
091: paramPath = "$(localagent)" + PATH_SEPR + "LoadAverage";
092: metricsService.subscribeToValue(paramPath, cb, evaluator);
093: }
094:
095: protected void setupSubscriptions() {
096: }
097:
098: public synchronized void execute() {
099: }
100:
101: }
|