001: /*
002: * <copyright>
003: *
004: * Copyright 2001-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.mobility;
028:
029: import org.cougaar.core.mts.MessageAddress;
030:
031: /**
032: * A ticket requesting agent removal.
033: */
034: public final class RemoveTicket extends AbstractTicket implements
035: java.io.Serializable {
036:
037: private final Object id;
038: private final MessageAddress mobileAgent;
039: private final MessageAddress destNode;
040:
041: public RemoveTicket(Object id, MessageAddress mobileAgent,
042: MessageAddress destNode) {
043: this .id = id;
044: this .mobileAgent = mobileAgent;
045: this .destNode = destNode;
046: }
047:
048: /**
049: * An optional identifier for this removeticket instance.
050: * <p>
051: * The identifier <u>must</u> be serializable and should be
052: * immutable. A UID is a good identifier.
053: */
054: public Object getIdentifier() {
055: return id;
056: }
057:
058: /**
059: * The agent to be moved.
060: * <p>
061: * An agent can only pass a RemoveTicket to "dispatch(..)" if
062: * the agent <i>is</i> the one moving. Aside from this
063: * sanity check, tagging the ticket with the agent address
064: * aids debugging.
065: * <p>
066: * If the agent is null then the caller of the
067: * MobilityService is assumed.
068: */
069: public MessageAddress getMobileAgent() {
070: return mobileAgent;
071: }
072:
073: /**
074: * Destination node for the mobile agent.
075: * <p>
076: * If the destination node is null then the agent should
077: * remain at its current node. This is is useful for
078: * a "force-restart".
079: */
080: public MessageAddress getDestinationNode() {
081: return destNode;
082: }
083:
084: public int hashCode() {
085: return (((id != null) ? id.hashCode() : 17) ^ ((mobileAgent != null) ? mobileAgent
086: .hashCode()
087: : 53));
088: }
089:
090: public boolean equals(Object o) {
091: if (o == this ) {
092: return true;
093: } else if (!(o instanceof RemoveTicket)) {
094: return false;
095: } else {
096: RemoveTicket t = (RemoveTicket) o;
097: return ((id == null) ? (t.id == null) : (id.equals(t.id)))
098: && ((mobileAgent == null) ? (t.mobileAgent == null)
099: : (mobileAgent.equals(t.mobileAgent)))
100: && ((destNode == null) ? (t.destNode == null)
101: : (destNode.equals(t.destNode)));
102: }
103: }
104:
105: public String toString() {
106: // cache?
107: return "Remove "
108: + ((id != null) ? (id) : (" unidentified "))
109: + " of "
110: + ((mobileAgent != null) ? "agent \"" + mobileAgent
111: + "\"" : "this agent")
112: + " from "
113: + ((destNode != null) ? "node \"" + destNode + "\""
114: : "this node");
115: }
116: }
|