public class SynchronizedHardReferenceQueue<T> extends Object implements IHardReferenceQueue<T>
Modifier and Type | Field and Description |
---|---|
protected HardReferenceQueue<T> |
queue
Note: Synchronization for the inner
queue is realized using the
outer reference! |
DEFAULT_NSCAN
Constructor and Description |
---|
SynchronizedHardReferenceQueue(HardReferenceQueueEvictionListener<T> listener,
int capacity)
Defaults the #of references to scan on append requests to 10.
|
SynchronizedHardReferenceQueue(HardReferenceQueueEvictionListener<T> listener,
int capacity,
int nscan)
Core impl.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(T ref)
Add a reference to the cache.
|
protected void |
beforeOffer(T t)
All attempts to add an element to the buffer invoke this hook before
checking the remaining capacity in the buffer.
|
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.
|
HardReferenceQueueEvictionListener<T> |
getListener() |
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.
|
boolean |
scanHead(int nscan,
T ref) |
boolean |
scanTail(int nscan,
T ref) |
int |
size()
The #of references in the cache.
|
protected final HardReferenceQueue<T> queue
queue
is realized using the
outer reference!public SynchronizedHardReferenceQueue(HardReferenceQueueEvictionListener<T> listener, int capacity)
listener
- The listener on which cache evictions are reported.capacity
- The maximum #of references that can be stored on the cache.
There is no guarantee that all stored references are distinct.public SynchronizedHardReferenceQueue(HardReferenceQueueEvictionListener<T> listener, int capacity, int nscan)
listener
- The listener on which cache evictions are reported (optional).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.protected void beforeOffer(T t)
public final int capacity()
IHardReferenceQueue
capacity
in interface IHardReferenceQueue<T>
public HardReferenceQueueEvictionListener<T> getListener()
public 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 boolean scanHead(int nscan, T ref)
public boolean scanTail(int nscan, T ref)
public int size()
IHardReferenceQueue
size
in interface IHardReferenceQueue<T>
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.