• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 package com.google.common.cache;
16 
17 import com.google.common.annotations.GwtIncompatible;
18 import com.google.common.cache.LocalCache.ValueReference;
19 import javax.annotation.CheckForNull;
20 
21 /**
22  * An entry in a reference map.
23  *
24  * <p>Entries in the map can be in the following states:
25  *
26  * <p>Valid:
27  *
28  * <ul>
29  *   <li>Live: valid key/value are set
30  *   <li>Loading: loading is pending
31  * </ul>
32  *
33  * <p>Invalid:
34  *
35  * <ul>
36  *   <li>Expired: time expired (key/value may still be set)
37  *   <li>Collected: key/value was partially collected, but not yet cleaned up
38  *   <li>Unset: marked as unset, awaiting cleanup or reuse
39  * </ul>
40  */
41 @GwtIncompatible
42 @ElementTypesAreNonnullByDefault
43 interface ReferenceEntry<K, V> {
44   /** Returns the value reference from this entry. */
45   @CheckForNull
getValueReference()46   ValueReference<K, V> getValueReference();
47 
48   /** Sets the value reference for this entry. */
setValueReference(ValueReference<K, V> valueReference)49   void setValueReference(ValueReference<K, V> valueReference);
50 
51   /** Returns the next entry in the chain. */
52   @CheckForNull
getNext()53   ReferenceEntry<K, V> getNext();
54 
55   /** Returns the entry's hash. */
getHash()56   int getHash();
57 
58   /** Returns the key for this entry. */
59   @CheckForNull
getKey()60   K getKey();
61 
62   /*
63    * Used by entries that use access order. Access entries are maintained in a doubly-linked list.
64    * New entries are added at the tail of the list at write time; stale entries are expired from
65    * the head of the list.
66    */
67 
68   /** Returns the time that this entry was last accessed, in ns. */
69   @SuppressWarnings("GoodTime")
getAccessTime()70   long getAccessTime();
71 
72   /** Sets the entry access time in ns. */
73   @SuppressWarnings("GoodTime") // b/122668874
setAccessTime(long time)74   void setAccessTime(long time);
75 
76   /** Returns the next entry in the access queue. */
getNextInAccessQueue()77   ReferenceEntry<K, V> getNextInAccessQueue();
78 
79   /** Sets the next entry in the access queue. */
setNextInAccessQueue(ReferenceEntry<K, V> next)80   void setNextInAccessQueue(ReferenceEntry<K, V> next);
81 
82   /** Returns the previous entry in the access queue. */
getPreviousInAccessQueue()83   ReferenceEntry<K, V> getPreviousInAccessQueue();
84 
85   /** Sets the previous entry in the access queue. */
setPreviousInAccessQueue(ReferenceEntry<K, V> previous)86   void setPreviousInAccessQueue(ReferenceEntry<K, V> previous);
87 
88   /*
89    * Implemented by entries that use write order. Write entries are maintained in a doubly-linked
90    * list. New entries are added at the tail of the list at write time and stale entries are
91    * expired from the head of the list.
92    */
93 
94   @SuppressWarnings("GoodTime")
95   /** Returns the time that this entry was last written, in ns. */
getWriteTime()96   long getWriteTime();
97 
98   /** Sets the entry write time in ns. */
99   @SuppressWarnings("GoodTime") // b/122668874
setWriteTime(long time)100   void setWriteTime(long time);
101 
102   /** Returns the next entry in the write queue. */
getNextInWriteQueue()103   ReferenceEntry<K, V> getNextInWriteQueue();
104 
105   /** Sets the next entry in the write queue. */
setNextInWriteQueue(ReferenceEntry<K, V> next)106   void setNextInWriteQueue(ReferenceEntry<K, V> next);
107 
108   /** Returns the previous entry in the write queue. */
getPreviousInWriteQueue()109   ReferenceEntry<K, V> getPreviousInWriteQueue();
110 
111   /** Sets the previous entry in the write queue. */
setPreviousInWriteQueue(ReferenceEntry<K, V> previous)112   void setPreviousInWriteQueue(ReferenceEntry<K, V> previous);
113 }
114