public class SynchronizedHardReferenceQueueWithTimeout<T> extends Object implements IHardReferenceQueue<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
. The tail of the queue is tested and
any entry on the tail whose age 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.
Modifier and Type | Class and Description |
---|---|
static interface |
SynchronizedHardReferenceQueueWithTimeout.IRef<T>
Interface for something wrapping a reference.
|
DEFAULT_NSCAN
Constructor and Description |
---|
SynchronizedHardReferenceQueueWithTimeout(int capacity,
int nscan,
long timeoutNanos)
Optional timeout.
|
SynchronizedHardReferenceQueueWithTimeout(int capacity,
long timeoutNanos)
Variant with no listener and timeout.
|
Modifier and Type | Method and Description |
---|---|
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.
|
static void |
stopStaleReferenceCleaner()
This method may be invoked by life cycle operations which need to tear
down the bigdata environment.
|
long |
timeout()
The timeout (in nanoseconds) for an entry in the queue.
|
public SynchronizedHardReferenceQueueWithTimeout(int capacity, long timeoutNanos)
capacity
- The maximum #of references that can be stored on the cache.
There is no guarantee that all stored references are distinct.timeoutNanos
- The timeout (in nanoseconds) for an entry in the queue. When
ZERO (0L), the timeout is disabled.public SynchronizedHardReferenceQueueWithTimeout(int capacity, int nscan, long timeoutNanos)
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.timeoutNanos
- The timeout (in nanoseconds) for an entry in the queue. When
ZERO (0L), the timeout is disabled.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>
HardReferenceQueueEvictionListener
public 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>
public static final void stopStaleReferenceCleaner()
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.