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.rss;
028:
029: import org.cougaar.core.qos.metrics.Constants;
030: import org.cougaar.qos.qrs.AbstractContextInstantiater;
031: import org.cougaar.qos.qrs.ContextInstantiater;
032: import org.cougaar.qos.qrs.DataFormula;
033: import org.cougaar.qos.qrs.RSS;
034: import org.cougaar.qos.qrs.ResourceContext;
035:
036: /**
037: * This RSS ResourceContext represents message flow between two Agents. This is
038: * a top-level context in the RSS inheritance tree, and is identified by a pair
039: * of Agent names (source and destination, in that order). It supports two
040: * messaging rate formulas, for byte counst and message counts respectively
041: */
042: public class AgentFlowDS extends CougaarDS {
043:
044: static void register() {
045: ContextInstantiater cinst = new AbstractContextInstantiater() {
046: public ResourceContext instantiateContext(
047: String[] parameters, ResourceContext parent)
048: throws ParameterError {
049: return new AgentFlowDS(parameters, parent);
050: }
051:
052: public Object identifyParameters(String[] parameters) {
053: if (parameters == null || parameters.length != 1) {
054: return null;
055: }
056: String src = parameters[0];
057: String dst = parameters[1];
058: return src + "->" + dst;
059: }
060:
061: };
062: registerContextInstantiater("AgentFlow", cinst);
063: }
064:
065: private static final String SOURCE_AGENT = "sourceAgent".intern();
066: private static final String DESTINATION_AGENT = "destinationAgent"
067: .intern();
068:
069: public AgentFlowDS(String[] parameters, ResourceContext parent)
070: throws ParameterError {
071: super (parameters, parent);
072: }
073:
074: protected boolean useParentPath() {
075: return false;
076: }
077:
078: // AgentFlow should really to have an IpFlow as a Parent so that
079: // they can get the path capacity. Also they need to have the
080: // Source and Destination hosts as perents in order to predict serialization
081: // cost
082: // The Flow Layering needs new Modeling primitives TBD later.
083: // JAZ Standalone for now
084: protected ResourceContext preferredParent(RSS root) {
085: return root;
086: }
087:
088: // Two Parameter which are Agent Names
089: protected void verifyParameters(String[] parameters)
090: throws ParameterError {
091: String source = null;
092: String destination = null;
093: if (parameters == null || parameters.length != 2) {
094: throw new ParameterError(
095: "AgentFlowDS: wrong number of parameters");
096: }
097: if (!(parameters[0] != null)) {
098: throw new ParameterError(
099: "AgentFlowDS: wrong parameter 1 type");
100: } else {
101: source = parameters[0];
102: bindSymbolValue(SOURCE_AGENT, source);
103: }
104: if (!(parameters[1] != null)) {
105: throw new ParameterError(
106: "AgentFlowDS: wrong parameter 2 type");
107: } else {
108: destination = parameters[1];
109: bindSymbolValue(DESTINATION_AGENT, destination);
110: historyPrefix = "AgentFlow" + KEY_SEPR + source + KEY_SEPR
111: + destination;
112: }
113: }
114:
115: protected DataFormula instantiateFormula(String kind) {
116: if (kind.equals(Constants.MSG_RATE)
117: || kind.equals(Constants.BYTE_RATE)) {
118: return new DecayingHistoryFormula(historyPrefix, kind);
119: } else {
120: return null;
121: }
122: }
123:
124: }
|