Class WeakHashClockImpl<K,V>
- java.lang.Object
-
- org.glassfish.hk2.utilities.general.internal.WeakHashClockImpl<K,V>
-
- All Implemented Interfaces:
WeakHashClock<K,V>
public class WeakHashClockImpl<K,V> extends java.lang.Object implements WeakHashClock<K,V>
Implementation of WeakHashClock as needed by the CAR algorithm
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.WeakHashMap<K,DoubleNode<K,V>>
byKey
private java.util.concurrent.ConcurrentHashMap<K,DoubleNode<K,V>>
byKeyNotWeak
private DoubleNode<K,V>
dot
private DoubleNode<K,V>
head
private boolean
isWeak
private java.lang.ref.ReferenceQueue<? super K>
myQueue
private DoubleNode<K,V>
tail
-
Constructor Summary
Constructors Constructor Description WeakHashClockImpl(boolean isWeak)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private DoubleNode<K,V>
addBeforeDot(K key, V value)
void
clear()
Sets the clock size back to zero, no entriesvoid
clearStaleReferences()
Causes stale references to be cleared from the data structures.V
get(K key)
Gets the given key, returning null if not foundboolean
hasWeakKeys()
Tells if this WeakHashClock has Weak keysprivate DoubleNode<K,V>
moveDot()
private DoubleNode<K,V>
moveDotNoWeak()
java.util.Map.Entry<K,V>
next()
Returns the next key/value pair in the clock, or null if the clock has no members.void
put(K key, V value)
Adds the given pair to the clock.void
releaseMatching(CacheKeyFilter<K> filter)
Releases all key/value pairs that match the filterV
remove(K key)
Removes the given key from the clock, if foundprivate void
removeFromDLL(DoubleNode<K,V> removeMe)
private void
removeStale()
int
size()
Returns the number of elements currently in the clock.java.lang.String
toString()
-
-
-
Field Detail
-
isWeak
private final boolean isWeak
-
byKeyNotWeak
private final java.util.concurrent.ConcurrentHashMap<K,DoubleNode<K,V>> byKeyNotWeak
-
byKey
private final java.util.WeakHashMap<K,DoubleNode<K,V>> byKey
-
myQueue
private final java.lang.ref.ReferenceQueue<? super K> myQueue
-
head
private DoubleNode<K,V> head
-
tail
private DoubleNode<K,V> tail
-
dot
private DoubleNode<K,V> dot
-
-
Method Detail
-
addBeforeDot
private DoubleNode<K,V> addBeforeDot(K key, V value)
-
removeFromDLL
private void removeFromDLL(DoubleNode<K,V> removeMe)
-
put
public void put(K key, V value)
Description copied from interface:WeakHashClock
Adds the given pair to the clock. It will be placed at the current tail of the clock- Specified by:
put
in interfaceWeakHashClock<K,V>
- Parameters:
key
- Must not be nullvalue
- May not be null
-
get
public V get(K key)
Description copied from interface:WeakHashClock
Gets the given key, returning null if not found- Specified by:
get
in interfaceWeakHashClock<K,V>
- Parameters:
key
- The key to search for, may not be null- Returns:
- The value found, or null if not found
-
remove
public V remove(K key)
Description copied from interface:WeakHashClock
Removes the given key from the clock, if found- Specified by:
remove
in interfaceWeakHashClock<K,V>
- Parameters:
key
- The key to remove, may not be null- Returns:
- The value removed if found, or null if not found
-
releaseMatching
public void releaseMatching(CacheKeyFilter<K> filter)
Description copied from interface:WeakHashClock
Releases all key/value pairs that match the filter- Specified by:
releaseMatching
in interfaceWeakHashClock<K,V>
- Parameters:
filter
- A non-null filter that can be used to delete every key/value pair that matches the filter
-
size
public int size()
Description copied from interface:WeakHashClock
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- Specified by:
size
in interfaceWeakHashClock<K,V>
- Returns:
- The number of entries currently in the clock
-
moveDot
private DoubleNode<K,V> moveDot()
-
moveDotNoWeak
private DoubleNode<K,V> moveDotNoWeak()
-
next
public java.util.Map.Entry<K,V> next()
Description copied from interface:WeakHashClock
Returns the next key/value pair in the clock, or null if the clock has no members. This will advance the head and tail of the clock to the next element. If the WeakReference for the returned element is null then this element will also have been removed from the clock by this operation- Specified by:
next
in interfaceWeakHashClock<K,V>
- Returns:
- The next key/value pair in the
-
clear
public void clear()
Description copied from interface:WeakHashClock
Sets the clock size back to zero, no entries- Specified by:
clear
in interfaceWeakHashClock<K,V>
-
clearStaleReferences
public void clearStaleReferences()
Description copied from interface:WeakHashClock
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- Specified by:
clearStaleReferences
in interfaceWeakHashClock<K,V>
-
removeStale
private void removeStale()
-
hasWeakKeys
public boolean hasWeakKeys()
Description copied from interface:WeakHashClock
Tells if this WeakHashClock has Weak keys- Specified by:
hasWeakKeys
in interfaceWeakHashClock<K,V>
- Returns:
- true if this map has weak keys, true otherwise
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-