|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.cache.SynchronizedHardReferenceQueueWithTimeout<T>
public class SynchronizedHardReferenceQueueWithTimeout<T>
Thread-safe version with timeout for clearing stale references from the
queue. Clearing of stale entries is accomplished when a value is added to the
SynchronizedHardReferenceQueue. If the value implements the
IValueAge interface, then the tail of the queue is tested and any
entry on the tail whose age as reported by that interface exceeds a timeout
is evicted. This continues until we reach the first value on the tail of the
queue whose age is greater than the timeout. This behavior is enabled if a
non-ZERO timeout is specified. Stales references are also cleared by a
background thread.
| Field Summary | |
|---|---|
protected static boolean |
DEBUG
|
protected static org.apache.log4j.Logger |
log
|
protected com.bigdata.cache.SynchronizedHardReferenceQueueWithTimeout.InnerHardReferenceQueue<com.bigdata.cache.SynchronizedHardReferenceQueueWithTimeout.ValueAge<T>> |
queue
Note: Synchronization for the inner queue is realized using the
outer reference! |
| Fields inherited from interface com.bigdata.cache.IHardReferenceQueue |
|---|
DEFAULT_NSCAN |
| Constructor Summary | |
|---|---|
SynchronizedHardReferenceQueueWithTimeout(int capacity,
int nscan,
long timeout)
Optional timeout. |
|
SynchronizedHardReferenceQueueWithTimeout(int capacity,
long timeout)
Variant with no listener and timeout. |
|
| Method Summary | |
|---|---|
boolean |
add(T ref)
Add a reference to the cache. |
int |
capacity()
The cache capacity. |
void |
clear(boolean clearRefs)
Clears the cache (sets the head, tail and count to zero) without generating eviction notices. |
boolean |
evict()
Evict the LRU reference. |
void |
evictAll(boolean clearRefs)
Evict all references, starting with the LRU reference and proceeding to the MRU reference. |
boolean |
isEmpty()
True iff the cache is empty. |
boolean |
isFull()
True iff the cache is full. |
int |
nscan()
The #of references that are tested on append requests. |
T |
peek()
The reference at the tail of the queue. |
int |
size()
The #of references in the cache. |
long |
timeout()
The timeout (in nanoseconds) for an entry in the queue. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final org.apache.log4j.Logger log
protected static final boolean DEBUG
protected final com.bigdata.cache.SynchronizedHardReferenceQueueWithTimeout.InnerHardReferenceQueue<com.bigdata.cache.SynchronizedHardReferenceQueueWithTimeout.ValueAge<T>> queue
queue is realized using the
outer reference!
| Constructor Detail |
|---|
public SynchronizedHardReferenceQueueWithTimeout(int capacity,
long timeout)
capacity - The maximum #of references that can be stored on the cache.
There is no guarantee that all stored references are distinct.timeout - The timeout (in nanoseconds) for an entry in the queue. When
ZERO (0L), the timeout is disabled.
public SynchronizedHardReferenceQueueWithTimeout(int capacity,
int nscan,
long timeout)
capacity - The maximum #of references that can be stored on the cache.
There is no guarantee that all stored references are distinct.nscan - The #of references to scan from the MRU position before
appended a reference to the cache. Scanning is used to reduce
the chance that references that are touched several times in
near succession from entering the cache more than once. The
#of reference tests trades off against the latency of adding a
reference to the cache.timeout - The timeout (in nanoseconds) for an entry in the queue. When
ZERO (0L), the timeout is disabled.| Method Detail |
|---|
public final long timeout()
public final int capacity()
IHardReferenceQueue
capacity in interface IHardReferenceQueue<T>public final int nscan()
IHardReferenceQueue
nscan in interface IHardReferenceQueue<T>public boolean add(T ref)
IHardReferenceQueue
add in interface IHardReferenceQueue<T>ref - The reference to be added.
public void clear(boolean clearRefs)
IHardReferenceQueue
clear in interface IHardReferenceQueue<T>clearRefs - When true the references are explicitly set to
null which can facilitate garbage collection.public boolean evict()
IHardReferenceQueue
evict in interface IHardReferenceQueue<T>HardReferenceQueueEvictionListenerpublic void evictAll(boolean clearRefs)
IHardReferenceQueue
evictAll in interface IHardReferenceQueue<T>clearRefs - When true, the reference are actually cleared from the cache.
This may be false to force persistence of the references in
the cache without actually clearing the cache.public T peek()
IHardReferenceQueue
peek in interface IHardReferenceQueue<T>public boolean isEmpty()
IHardReferenceQueue
isEmpty in interface IHardReferenceQueue<T>public boolean isFull()
IHardReferenceQueue
isFull in interface IHardReferenceQueue<T>public int size()
IHardReferenceQueue
size in interface IHardReferenceQueue<T>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||