001: /*
002: * <copyright>
003: *
004: * Copyright 2002-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.io.Serializable;
030: import org.cougaar.core.util.UID;
031:
032: /**
033: * A "lease denied" response from the {@link ClientTransport}'s
034: * {@link ModifyService}, indicating to the {@link LeaseManager}
035: * a failed bind or lease renewal.
036: * <p>
037: * The UID will match the UID of the Record that has been denied.
038: * <p>
039: * Currently this can only be caused by server-side deconfliction
040: * over race conditions, primarily based upon agent incarnation
041: * numbers.
042: * <p>
043: * For example, say AgentX moves from NodeA to NodeB.
044: * The following binds may be in progress:<pre>
045: * NodeA sends:
046: * AgentX={..., version=version:///1234/5678, ...}
047: * NodeB sends:
048: * AgentX={..., version=version:///1234/9999, ...}
049: * </pre>
050: * The format of the version entry URI is:<pre>
051: * version:///<i>incarnation</i>/<i>moveId</i>
052: * </pre>
053: * where the incarnation number is incremented per restart
054: * (excluding moves) and the moveId is incremented per move
055: * or restart (i.e. every time the agent is loaded).
056: * The white pages servers will prefer the latest entries,
057: * so it will deny NodeA's lease request.
058: * <p>
059: * Currently (see {@link Record}) this doesn't support bind-only
060: * failures due to "already bound" entries. The javadocs in
061: * Record describe a proposed Map of failed-binds.
062: */
063: public final class LeaseDenied implements Serializable {
064:
065: private final UID uid;
066: private final Object reason;
067: private final Object data;
068:
069: public LeaseDenied(UID uid, Object reason, Object data) {
070: this .uid = uid;
071: this .reason = reason;
072: this .data = data;
073: // validate
074: String s = ((uid == null) ? "null uid"
075: : (reason == null) ? "null reason" : null);
076: if (s != null) {
077: throw new IllegalArgumentException(s);
078: }
079: }
080:
081: /**
082: * The UID of the lease, as selected by the Record.
083: * <p>
084: * This is the "in response to" field.
085: */
086: public UID getUID() {
087: return uid;
088: }
089:
090: /**
091: * The reason(s) for the failure.
092: * <p>
093: * This may indicate an "already bound" message for failed
094: * "bind" requests, or some other failure condition.
095: */
096: public Object getReason() {
097: return reason;
098: }
099:
100: /**
101: * The optional Record data.
102: */
103: public Object getData() {
104: return data;
105: }
106:
107: public String toString() {
108: return "(lease-denied uid=" + uid + " reason=" + reason
109: + " data=" + data + ")";
110: }
111: }
|