001: /*
002:
003: * <copyright>
004: *
005: * Copyright 2002-2007 BBNT Solutions, LLC
006: * under sponsorship of the Defense Advanced Research Projects
007: * Agency (DARPA).
008: *
009: * You can redistribute this software and/or modify it under the
010: * terms of the Cougaar Open Source License as published on the
011: * Cougaar Open Source Website (www.cougaar.org).
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
017: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
018: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
019: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
020: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
021: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
022: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
023: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: *
025: * </copyright>
026:
027: */
028:
029: package org.cougaar.qos.qrs;
030:
031: public class MethodDS extends ResourceContext {
032: static void register() {
033: ContextInstantiater cinst = new AbstractContextInstantiater() {
034: public ResourceContext instantiateContext(
035: String[] parameters, ResourceContext parent)
036: throws ResourceContext.ParameterError {
037: return new MethodDS(parameters, parent);
038: }
039:
040: };
041: registerContextInstantiater("Method", cinst);
042: }
043:
044: private static final String METHOD_NAME = "MethodName";
045:
046: protected DataFormula instantiateFormula(String kind) {
047: if (kind.equals("ReplySizeMean")) {
048: return new ReplySizeMean();
049: } else if (kind.equals("ReplyInstPerByteMean")) {
050: return new ReplyInstPerByteMean();
051: } else if (kind.equals("RequestSizeMean")) {
052: return new RequestSizeMean();
053: } else if (kind.equals("RequestInstPerByteMean")) {
054: return new RequestInstPerByteMean();
055: } else {
056: return null;
057: }
058: }
059:
060: /**
061: * The parameters should contain one string, the name of the method
062: */
063: protected void verifyParameters(String[] parameters)
064: throws ParameterError {
065: if (parameters == null || parameters.length != 1) {
066: throw new ParameterError(
067: "MethodDS: wrong number of parameters");
068: } else {
069: bindSymbolValue(METHOD_NAME, parameters[0]);
070: }
071: }
072:
073: private MethodDS(String[] parameters, ResourceContext parent)
074: throws ParameterError {
075: super (parameters, parent);
076: }
077:
078: abstract static class Formula extends DataFormula implements
079: Constants {
080:
081: abstract String getKey();
082:
083: abstract DataValue defaultValue();
084:
085: protected void initialize(ResourceContext context) {
086: super .initialize(context);
087: String className = (String) context.getValue("ClassName");
088: String methodName = (String) context.getValue("MethodName");
089: String key = "Class" + KEY_SEPR + className + KEY_SEPR
090: + methodName + KEY_SEPR + getKey();
091:
092: String[] parameters = { key };
093: ResourceContext dependency = RSS.instance().resolveSpec(
094: "Integrater", parameters);
095: registerDependency(dependency, "Formula");
096: }
097:
098: protected DataValue doCalculation(DataFormula.Values values) {
099: DataValue computedValue = values.get("Formula");
100: DataValue defaultValue = defaultValue();
101: return DataValue.mostCredible(computedValue, defaultValue);
102: }
103:
104: }
105:
106: public static class ReplySizeMean extends Formula {
107: String getKey() {
108: return "reply" + KEY_SEPR + "size" + KEY_SEPR + "mean";
109: }
110:
111: DataValue defaultValue() {
112: return new DataValue(0);
113: }
114: }
115:
116: public static class ReplyInstPerByteMean extends Formula {
117: String getKey() {
118: return "reply" + KEY_SEPR + "instPerByte" + KEY_SEPR
119: + "mean";
120: }
121:
122: DataValue defaultValue() {
123: return new DataValue(0);
124: }
125: }
126:
127: public static class RequestSizeMean extends Formula {
128: String getKey() {
129: return "request" + KEY_SEPR + "size" + KEY_SEPR + "mean";
130: }
131:
132: DataValue defaultValue() {
133: return new DataValue(0);
134: }
135: }
136:
137: public static class RequestInstPerByteMean extends Formula {
138: String getKey() {
139: return "request" + KEY_SEPR + "instPerByte" + KEY_SEPR
140: + "mean";
141: }
142:
143: DataValue defaultValue() {
144: return new DataValue(0);
145: }
146: }
147:
148: }
|