01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.core.qos.rss;
28:
29: import org.cougaar.core.qos.metrics.Constants;
30: import org.cougaar.qos.ResourceStatus.ResourceNode;
31: import org.cougaar.qos.qrs.DataFormula;
32: import org.cougaar.qos.qrs.DataValue;
33: import org.cougaar.qos.qrs.RSS;
34: import org.cougaar.qos.qrs.ResourceContext;
35:
36: /**
37: * This RSS formula class encapsules the use of data published into the RSS by
38: * {@link org.cougaar.core.qos.metrics.DecayingHistory}.
39: */
40: public class DecayingHistoryFormula extends DataFormula {
41: private String period;
42: private final String prefix;
43: private final String kind;
44:
45: public DecayingHistoryFormula(String prefix, String kind) {
46: super ();
47: this .prefix = prefix;
48: this .kind = kind;
49: }
50:
51: protected DataValue defaultValue() {
52: return new DataValue(0);
53: }
54:
55: protected void initialize(ResourceContext context) {
56: super .initialize(context);
57:
58: String key = prefix + KEY_SEPR + kind + period
59: + Constants.SecAvgKeySuffix;
60: String[] parameters = { key };
61: ResourceNode node = new ResourceNode();
62: node.kind = "Integrater";
63: node.parameters = parameters;
64: ResourceNode formula = new ResourceNode();
65: formula.kind = "Formula";
66: formula.parameters = new String[0];
67: ResourceNode[] path = { node, formula };
68: DataFormula dependency = RSS.instance().getPathFormula(path);
69: registerDependency(dependency, "Formula");
70: }
71:
72: protected DataValue doCalculation(DataFormula.Values values) {
73: DataValue computedValue = values.get("Formula");
74: DataValue defaultValue = defaultValue();
75: return DataValue.mostCredible(computedValue, defaultValue);
76: }
77:
78: protected void setArgs(String[] args) {
79: super .setArgs(args);
80: this .period = args[0];
81: }
82:
83: }
|