Module org.glassfish.hk2.utilities
Class WeakHashClockImpl<K,V>
java.lang.Object
org.glassfish.hk2.utilities.general.internal.WeakHashClockImpl<K,V>
- All Implemented Interfaces:
WeakHashClock<K,V>
Implementation of WeakHashClock as needed by the CAR algorithm
- Author:
- jwells
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets the clock size back to zero, no entriesvoidCauses stale references to be cleared from the data structures.Gets the given key, returning null if not foundbooleanTells if this WeakHashClock has Weak keysnext()Returns the next key/value pair in the clock, or null if the clock has no members.voidAdds the given pair to the clock.voidreleaseMatching(CacheKeyFilter<K> filter) Releases all key/value pairs that match the filterRemoves the given key from the clock, if foundintsize()Returns the number of elements currently in the clock.toString()
-
Constructor Details
-
WeakHashClockImpl
public WeakHashClockImpl(boolean isWeak)
-
-
Method Details
-
put
Description copied from interface:WeakHashClockAdds the given pair to the clock. It will be placed at the current tail of the clock- Specified by:
putin interfaceWeakHashClock<K,V> - Parameters:
key- Must not be nullvalue- May not be null
-
get
Description copied from interface:WeakHashClockGets the given key, returning null if not found- Specified by:
getin interfaceWeakHashClock<K,V> - Parameters:
key- The key to search for, may not be null- Returns:
- The value found, or null if not found
-
remove
Description copied from interface:WeakHashClockRemoves the given key from the clock, if found- Specified by:
removein 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
Description copied from interface:WeakHashClockReleases all key/value pairs that match the filter- Specified by:
releaseMatchingin 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:WeakHashClockReturns 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:
sizein interfaceWeakHashClock<K,V> - Returns:
- The number of entries currently in the clock
-
next
Description copied from interface:WeakHashClockReturns 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:
nextin interfaceWeakHashClock<K,V> - Returns:
- The next key/value pair in the
-
clear
public void clear()Description copied from interface:WeakHashClockSets the clock size back to zero, no entries- Specified by:
clearin interfaceWeakHashClock<K,V>
-
clearStaleReferences
public void clearStaleReferences()Description copied from interface:WeakHashClockCauses 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:
clearStaleReferencesin interfaceWeakHashClock<K,V>
-
hasWeakKeys
public boolean hasWeakKeys()Description copied from interface:WeakHashClockTells if this WeakHashClock has Weak keys- Specified by:
hasWeakKeysin interfaceWeakHashClock<K,V> - Returns:
- true if this map has weak keys, true otherwise
-
toString
-