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: /**
032: * A ResourceContext for a physical Object which is on a Process which is on a
033: * Host. The available formulae ???
034: */
035: public class ObjectDS extends DeflectingContext {
036: static void register() {
037: ContextInstantiater cinst = new AbstractContextInstantiater() {
038: public ResourceContext instantiateContext(
039: String[] parameters, ResourceContext parent)
040: throws ResourceContext.ParameterError {
041: return new ObjectDS(parameters, parent);
042: }
043:
044: };
045: registerContextInstantiater("Object", cinst);
046: }
047:
048: // pseudo-enum
049: private static final String KEY = "key";
050: private static final String INTERFACE_NAME = "interfaceName";
051: private static final String IMPLEMENTATION_NAME = "implementationName";
052:
053: public static final String IMPLEMENTATION_DEF = "implementationDef";
054:
055: protected DataFormula instantiateFormula(String kind) {
056: if (kind.equals("RemoteLoadAverage")) {
057: return new RemoteLoadAverage();
058: } else {
059: return null;
060: }
061: }
062:
063: /**
064: * The parameters should contain three strings: the object key, interface
065: * name and the implementation. The object key is in the Object reference
066: * for both CORBA and RMI. The interface is in the CORBA reference and the
067: * (stub of the) implemention is in the RMI reference.
068: */
069: protected void verifyParameters(String[] parameters)
070: throws ParameterError {
071: if (parameters == null || parameters.length != 3) {
072: throw new ParameterError(
073: "ObjectDS: wrong number of parameters");
074: } else {
075: bindSymbolValue(KEY, parameters[0]);
076: String iface = parameters[1];
077: bindSymbolValue(INTERFACE_NAME, iface);
078: String impl = parameters[2];
079: bindSymbolValue(IMPLEMENTATION_NAME, impl);
080:
081: // find extant class context
082: String[] args = { impl, iface };
083: ResourceContext class_ctxt = RSS.instance().resolveSpec(
084: "Class", args);
085: bindSymbolValue(IMPLEMENTATION_DEF, class_ctxt);
086: // Use class as prototype for Object
087: setDeflector(class_ctxt);
088: }
089: }
090:
091: private ObjectDS(String[] parameters, ResourceContext parent)
092: throws ParameterError {
093: super (parameters, parent);
094: }
095:
096: /***************************************************************************
097: * Only for testing.
098: **************************************************************************/
099: public static class RemoteLoadAverage extends DataFormula {
100:
101: protected void initialize(ResourceContext context) {
102: super .initialize(context);
103: Object raw = context.getValue("calls");
104: ResourceContext remote = (ResourceContext) raw;
105: registerDependency(remote, "LoadAverage");
106: }
107:
108: protected DataValue doCalculation(DataFormula.Values values) {
109: return values.get("LoadAverage");
110: }
111: }
112:
113: // Some Day Object will have formulas to calculate things like
114: // class, version?
115:
116: }
|