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.wp.resolver;
028:
029: import java.util.Map;
030: import org.cougaar.core.mts.MessageAddress;
031: import org.cougaar.core.wp.Timestamp;
032: import org.cougaar.core.wp.WhitePagesMessage;
033:
034: /**
035: * A message from a white pages cache to a server, or between
036: * servers.
037: */
038: public final class WPQuery extends WhitePagesMessage {
039:
040: public static final int LOOKUP = 0;
041: public static final int MODIFY = 1;
042: public static final int FORWARD = 2;
043: public static final int PING = 3;
044:
045: private final long sendTime;
046: private final int action;
047: private final Map m;
048:
049: public WPQuery(MessageAddress source, MessageAddress target,
050: long sendTime, int action, Map m) {
051: super (source, target);
052: this .sendTime = sendTime;
053: this .action = action;
054: this .m = m;
055: // validate
056: String s = ((sendTime < 0) ? "invalid send time: " + sendTime
057: : (m == null && action != PING) ? "null map"
058: : (action != LOOKUP && action != MODIFY
059: && action != FORWARD && action != PING) ? "invalid action: "
060: + action
061: : null);
062: if (s != null) {
063: throw new IllegalArgumentException(s);
064: }
065: }
066:
067: /**
068: * The time on the client's clock when this was sent.
069: */
070: public long getSendTime() {
071: return sendTime;
072: }
073:
074: /**
075: * @return the action of request
076: */
077: public int getAction() {
078: return action;
079: }
080:
081: /**
082: * The content of this message.
083: */
084: public Map getMap() {
085: return m;
086: }
087:
088: public String toString() {
089: long now = System.currentTimeMillis();
090: return toString(now);
091: }
092:
093: public String toString(long now) {
094: return "("
095: + (action == LOOKUP ? "lookup"
096: : action == MODIFY ? "modify"
097: : action == FORWARD ? "forward"
098: : "ping") + " from="
099: + getOriginator() + " to=" + getTarget() + " sent="
100: + Timestamp.toString(sendTime, now) + " " + m + ")";
101: }
102: }
|