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 data response from a successful {@link ClientTransport} {@link
35: * LookupService} lookup to the {@link CacheManager}, which
36: * validates the client's cached {@link Record} and extends the TTL
37: * for the cached data.
38: * <p>
39: * This is only used if the client passed a non-null UID in the
40: * lookup.
41: * <p>
42: * The client sent the UID of the Record, and this "RecordIsValid"
43: * confirms that the Record with that UID hasn't changed and
44: * permits the client to cache the Record for a little longer.
45: * <p>
46: * It's possible for a client to evict the entry before the
47: * "record is valid" is received, e.g. due to a cache size limit.
48: * In this situation the client should send a new lookup (null-UID),
49: * which will incur a second lookup delay.
50: */
51: public final class RecordIsValid implements Serializable {
52:
53: private final UID uid;
54: private final long ttd;
55:
56: public RecordIsValid(UID uid, long ttd) {
57: this .uid = uid;
58: this .ttd = ttd;
59: // validate
60: String s = ((uid == null) ? "null uid"
61: : (ttd < 0) ? "negative ttd" : null);
62: if (s != null) {
63: throw new IllegalArgumentException(s);
64: }
65: }
66:
67: /** The UID of the validated Record. */
68: public UID getUID() {
69: return uid;
70: }
71:
72: /**
73: * The expiration "time-to-death" relative to the base timestamp.
74: */
75: public long getTTD() {
76: return ttd;
77: }
78:
79: public String toString() {
80: return "(record-is-valid uid=" + uid + " ttd=" + ttd + ")";
81: }
82:
83: public String toString(long baseTime, long now) {
84: long ttl = baseTime + ttd;
85: return "(record-is-valid uid=" + uid + " ttd=" + ttd + " ttl="
86: + Timestamp.toString(ttl, now) + ")";
87: }
88: }
|