01: /*
02: * <copyright>
03: *
04: * Copyright 2002-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.core.wp.resolver;
28:
29: import java.io.Serializable;
30: import org.cougaar.core.util.UID;
31: import org.cougaar.core.wp.Timestamp;
32:
33: /**
34: * A "successful lease" response from the {@link ClientTransport}'s
35: * {@link ModifyService}, indicating to the {@link LeaseManager}
36: * that either a new {@link Record} was successfully bound or an
37: * existing {@link Lease} was extended.
38: * <p>
39: * The LeaseManager client must renew this lease before it expires,
40: * otherwise the server(s) will automatically remove it.
41: * <p>
42: * Renewals can pass the UID of the Record, as documented in
43: * the ModifyService.
44: * <p>
45: * A relative "TTD" for the expiration data is also specified,
46: * which is relative to the base time passed by the
47: * "modifyAnswer" method.
48: */
49: public final class Lease implements Serializable {
50:
51: private final UID uid;
52: private final long ttd;
53:
54: public Lease(UID uid, long ttd) {
55: this .uid = uid;
56: this .ttd = ttd;
57: // validate
58: String s = ((uid == null) ? "null uid"
59: : (ttd < 0) ? "negative ttd" : null);
60: if (s != null) {
61: throw new IllegalArgumentException(s);
62: }
63: }
64:
65: /**
66: * The UID of the lease, as selected by the View.
67: * <p>
68: * This is the "in response to" field.
69: */
70: public UID getUID() {
71: return uid;
72: }
73:
74: /**
75: * The lease time-to-death relative to the base timestamp.
76: * <p>
77: * This is the lease expiration date. A negative number
78: * indicates a failed bind or renewal, in which case the
79: * result field will be non-null.
80: */
81: public long getTTD() {
82: return ttd;
83: }
84:
85: public String toString() {
86: return "(lease uid=" + uid + " ttd=" + ttd + ")";
87: }
88:
89: public String toString(long baseTime, long now) {
90: long ttl = baseTime + ttd;
91: return "(lease uid=" + uid + " ttd=" + ttd + " ttl="
92: + (0 < ttl ? Timestamp.toString(ttl, now) : "N/A")
93: + ")";
94: }
95: }
|