Top Description Fields Constructors Methods
org.glassfish.hk2.utilities.general.internal

public Class WeakHashLRUImpl<K>

extends Object
implements WeakHashLRU<K>
Class Inheritance
All Implemented Interfaces
org.glassfish.hk2.utilities.general.WeakHashLRU
Imports
java.lang.ref.ReferenceQueue, java.util.LinkedList, .WeakHashMap, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.locks.ReentrantLock, org.glassfish.hk2.utilities.cache.CacheKeyFilter, org.glassfish.hk2.utilities.general.WeakHashLRU

An implementation of the WeakHashLRU as needed by the CAR algorithm
Author
jwells

Field Summary

Modifier and TypeField and Description
private final WeakHashMap<K, DoubleNode<K, Object>>
private final ConcurrentHashMap<K, DoubleNode<K, Object>>
private final boolean
private final ReentrantLock
private DoubleNode<K, Object>
private DoubleNode<K, Object>
private final ReferenceQueue<? super K>
private static final Object

Constructor Summary

AccessConstructor and Description
public
WeakHashLRUImpl(boolean isWeak)

Method Summary

Modifier and TypeMethod and Description
public void
add(K key)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.add.

Adds the given key to the LRU.

private DoubleNode<K, Object>
addToHead(K key)

public void
clear()

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.clear.

Removes all entries from this LRU

private void
public void
clearStaleReferences()

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.clearStaleReferences.

Causes stale references to be cleared from the data structures.

public boolean
contains(K key)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.contains.

Tells if the given key is in the LRU

public void
releaseMatching(CacheKeyFilter<K> filter)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.releaseMatching.

Releases all keys that match the filter

private K
remove(DoubleNode<K, Object> removeMe)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.remove.

Removes the given key from the LRU, if found

public boolean
remove(K key)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.remove.

Removes the given key from the LRU, if found

public K
remove()

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.remove.

Removes the key that was Least Recently Used

private boolean
public int
size()

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.size.

Returns the number of elements currently in the clock.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

byKeyback to summary
private final WeakHashMap<K, DoubleNode<K, Object>> byKey
byKeyNotWeakback to summary
private final ConcurrentHashMap<K, DoubleNode<K, Object>> byKeyNotWeak
isWeakback to summary
private final boolean isWeak
lockback to summary
private final ReentrantLock lock
lruback to summary
private DoubleNode<K, Object> lru
mruback to summary
private DoubleNode<K, Object> mru
myQueueback to summary
private final ReferenceQueue<? super K> myQueue
VALUEback to summary
private static final Object VALUE

Constructor Detail

WeakHashLRUImplback to summary
public WeakHashLRUImpl(boolean isWeak)

Method Detail

addback to summary
public void add(K key)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.add.

Doc from org.glassfish.hk2.utilities.general.WeakHashLRU.add.

Adds the given key to the LRU. It will be placed at the MRU of the LRU. If this key already exists in the LRU it will be moved to the MRU

Annotations
@Override
addToHeadback to summary
private DoubleNode<K, Object> addToHead(K key)
clearback to summary
public void clear()

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.clear.

Doc from org.glassfish.hk2.utilities.general.WeakHashLRU.clear.

Removes all entries from this LRU

Annotations
@Override
clearStaleback to summary
private void clearStale()
clearStaleReferencesback to summary
public void clearStaleReferences()

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.clearStaleReferences.

Doc from org.glassfish.hk2.utilities.general.WeakHashLRU.clearStaleReferences.

Causes stale references to be cleared from the data structures. Since this is a weak clock the references can go away at any time, which happens whenever any operation has been performed. However, it may be the case that no operation will be performed for a while and so this method is provided to have a no-op operation to call in order to clear out any stale references

Annotations
@Override
containsback to summary
public boolean contains(K key)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.contains.

Doc from org.glassfish.hk2.utilities.general.WeakHashLRU.contains.

Tells if the given key is in the LRU

Annotations
@Override
releaseMatchingback to summary
public void releaseMatching(CacheKeyFilter<K> filter)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.releaseMatching.

Doc from org.glassfish.hk2.utilities.general.WeakHashLRU.releaseMatching.

Releases all keys that match the filter

Annotations
@Override
removeback to summary
private K remove(DoubleNode<K, Object> removeMe)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.remove.

Doc from org.glassfish.hk2.utilities.general.WeakHashLRU.remove.

Removes the given key from the LRU, if found

removeback to summary
public boolean remove(K key)

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.remove.

Doc from org.glassfish.hk2.utilities.general.WeakHashLRU.remove.

Removes the given key from the LRU, if found

Annotations
@Override
removeback to summary
public K remove()

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.remove.

Doc from org.glassfish.hk2.utilities.general.WeakHashLRU.remove.

Removes the key that was Least Recently Used

Annotations
@Override
removeNoClearback to summary
private boolean removeNoClear(K key)
sizeback to summary
public int size()

Implements org.glassfish.hk2.utilities.general.WeakHashLRU.size.

Doc from org.glassfish.hk2.utilities.general.WeakHashLRU.size.

Returns the number of elements currently in the clock. References that have gone away because they were weakly referenced will not be counted in the size

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override