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: package org.cougaar.mlm.plugin.organization;
027:
028: import java.io.Serializable;
029:
030: import java.util.Set;
031: import java.util.Collections;
032:
033: import org.cougaar.core.relay.*;
034: import org.cougaar.core.mts.MessageAddress;
035: import org.cougaar.core.util.*;
036:
037: /**
038: * Relay for subordinates to report to their superior
039: * that they & their subordinates are up, with report
040: * chain intact. Used by the ReportChainDetectorPlugin
041: **/
042: public class ReportChainReadyRelay implements Relay.Source,
043: Relay.Target, UniqueObject {
044: private UID uid = null;
045:
046: private MessageAddress source = null;
047: private MessageAddress target = null;
048:
049: private Object content = null;
050: private Object response = null;
051:
052: private transient Set targets = null;
053:
054: public ReportChainReadyRelay(UID uid, MessageAddress source,
055: MessageAddress target, Object content) {
056: this .uid = uid;
057: this .source = source;
058: this .target = target;
059: this .content = content;
060: this .response = new Integer(1);
061: }
062:
063: private static final class OPRFactory implements TargetFactory,
064: Serializable {
065: public static final OPRFactory _instance = new OPRFactory();
066:
067: private OPRFactory() {
068: }
069:
070: public Relay.Target create(UID uid, MessageAddress source,
071: Object content, Token token) {
072: return new ReportChainReadyRelay(uid, source, null, content);
073: }
074:
075: private Object readResolve() {
076: return _instance;
077: }
078: }
079:
080: public TargetFactory getTargetFactory() {
081: return OPRFactory._instance;
082: }
083:
084: public UID getUID() {
085: return uid;
086: }
087:
088: public void setUID(UID uid) {
089: throw new RuntimeException(
090: "Bozo API Exception! Don't set UID.");
091: }
092:
093: public int updateResponse(MessageAddress t, Object response) {
094: return Relay.NO_CHANGE;
095: }
096:
097: public MessageAddress getSource() {
098: return source;
099: }
100:
101: public Object getResponse() {
102: return response;
103: }
104:
105: public Set getTargets() {
106: if (targets == null) {
107: targets = ((target != null) ? Collections.singleton(target)
108: : Collections.EMPTY_SET);
109: }
110:
111: return targets;
112: }
113:
114: public Object getContent() {
115: return content;
116: }
117:
118: public int updateContent(Object content, Token token) {
119: return Relay.NO_CHANGE;
120: }
121:
122: public boolean equals(Object o) {
123: ReportChainReadyRelay opr = (ReportChainReadyRelay) o;
124: return opr.getUID().equals(uid);
125: }
126:
127: public int hashCode() {
128: return uid.hashCode();
129: }
130:
131: public String toString() {
132: return "(" + uid + ", " + content + ", " + response + ")";
133: }
134: }
|