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.core.agent;
028:
029: import java.io.IOException;
030: import java.io.ObjectInput;
031: import java.io.ObjectOutput;
032:
033: import org.cougaar.core.mts.Message;
034: import org.cougaar.core.mts.MessageAddress;
035:
036: /**
037: * The base class for blackboard messages, which pass through the agent's
038: * {@link QueueHandler} before entering the blackboard.
039: * <p>
040: * This should really be abstract and only used by the
041: * {@link org.cougaar.core.blackboard.DirectiveMessage} subclass.
042: */
043: public class ClusterMessage extends Message {
044: protected long theIncarnationNumber;
045:
046: /**
047: * @param s The MessageAddress of creator agent
048: * @param d The MessageAddress of the target agent
049: */
050: public ClusterMessage(MessageAddress s, MessageAddress d,
051: long incarnationNumber) {
052: super (s, d);
053: theIncarnationNumber = incarnationNumber;
054: }
055:
056: public ClusterMessage() {
057: super ();
058: }
059:
060: // the agent's incarnation number, which is not typically used
061: public long getIncarnationNumber() {
062: return theIncarnationNumber;
063: }
064:
065: public void setIncarnationNumber(long incarnationNumber) {
066: theIncarnationNumber = incarnationNumber;
067: }
068:
069: // for backwards compatibility, rename a couple methods:
070: // originator --> source
071: // target --> destination
072: public final MessageAddress getSource() {
073: return getOriginator();
074: }
075:
076: public final MessageAddress getDestination() {
077: return getTarget();
078: }
079:
080: public final void setSource(MessageAddress asource) {
081: setOriginator(asource);
082: }
083:
084: public final void setDestination(MessageAddress adestination) {
085: setTarget(adestination);
086: }
087:
088: public String toString() {
089: return "<ClusterMessage " + getSource() + " - "
090: + getDestination() + ">";
091: }
092:
093: public void writeExternal(ObjectOutput out) throws IOException {
094: super .writeExternal(out);
095: out.writeLong(theIncarnationNumber);
096: }
097:
098: public void readExternal(ObjectInput in)
099: throws ClassNotFoundException, IOException {
100: super.readExternal(in);
101: theIncarnationNumber = in.readLong();
102: }
103: }
|