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.planning.ldm.lps;
028:
029: import java.util.Collection;
030:
031: import org.cougaar.core.blackboard.EnvelopeTuple;
032: import org.cougaar.core.blackboard.PublishHistory;
033: import org.cougaar.core.domain.EnvelopeLogicProvider;
034: import org.cougaar.core.domain.LogicProvider;
035: import org.cougaar.core.domain.RootPlan;
036: import org.cougaar.core.mts.MessageAddress;
037: import org.cougaar.core.util.UID;
038: import org.cougaar.core.util.UniqueObject;
039: import org.cougaar.util.log.Logger;
040: import org.cougaar.util.log.Logging;
041:
042: /** Watch the LogPlan and complain via logging messages when obvious errors and
043: * other suspicious patterns are detected.
044: * <p>
045: * This particular
046: * implementation is only concerned with vetting Envelopes.
047: * It does not attempt to detect any in-state Blackboard
048: * or Message problems.
049: * <p>
050: * The specific tests that are performed are described by the
051: * execute method.
052: * <p>
053: * @note Cougaar prior to 11.2 used the system property
054: * org.cougaar.planning.ldm.lps.ComplainingLP.level to control
055: * the verbosity. The default levels, however led to people
056: * just turning it off completely. Current tests are logged
057: * at INFO or lower, but warn level messages may be used
058: * in the future.
059: **/
060:
061: public class ComplainingLP implements LogicProvider,
062: EnvelopeLogicProvider {
063: private static final Logger logger = Logging
064: .getLogger(ComplainingLP.class);
065:
066: private final RootPlan rootplan;
067: private final MessageAddress self;
068:
069: public ComplainingLP(RootPlan rootplan, MessageAddress self) {
070: if (System
071: .getProperty("org.cougaar.planning.ldm.lps.ComplainingLP.level") != null) {
072: logger
073: .error("System Property org.cougaar.planning.ldm.lps.ComplainingLP.level is ignored");
074: }
075:
076: this .rootplan = rootplan;
077: this .self = self;
078: }
079:
080: public void init() {
081: }
082:
083: /**
084: * Complain in any of the following cases:
085: * Unique Object Changed but not in blackboard (error).
086: * Unique Object add/removed/changed which has the same UID as an existing object
087: * but that is not identical (warning).
088: **/
089: public void execute(EnvelopeTuple o, Collection changes) {
090: if (logger.isWarnEnabled()) { //skip if not at least at WARN
091: Object obj = o.getObject();
092: if (obj instanceof UniqueObject) {
093: UID objuid = ((UniqueObject) obj).getUID();
094: Object found = rootplan.findUniqueObject(objuid);
095: boolean thereP = (found != null);
096:
097: if ((!thereP) && o.isChange()) {
098: if (logger.isInfoEnabled()) {
099: logger.info("change of non-existent object "
100: + obj);
101: dumpStacks(obj);
102: }
103: }
104:
105: // cannot do these because LPs are applied after subscription updates.
106: // if ((! thereP) && o.isRemove()) {
107: // if (logger.isInfoEnabled()) {
108: // logger.info("redundant remove of object "+obj);
109: // }
110: // }
111: // if ((thereP) && o.isAdd()) {
112: // if (logger.isInfoEnabled()) {
113: // logger.info("redundant add of object "+obj);
114: // }
115: // }
116:
117: if (thereP && found != obj) {
118: if (logger.isInfoEnabled()) {
119: logger.info("action=" + o.getAction() + " on "
120: + obj + " which is not == " + found);
121: dumpStacks(obj);
122: }
123: }
124: }
125: }
126: }
127:
128: private void dumpStacks(Object obj) {
129: PublishHistory history = rootplan.getHistory();
130: if (history != null)
131: history.dumpStacks(obj);
132: }
133: }
|