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

public Class WeakHashClockImpl<K, V>

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

Implementation of WeakHashClock as needed by the CAR algorithm
Author
jwells

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
WeakHashClockImpl(boolean isWeak)

Method Summary

Modifier and TypeMethod and Description
private DoubleNode<K, V>
addBeforeDot(K key, V value)

public void
clear()

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

Sets the clock size back to zero, no entries

public void
clearStaleReferences()

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

Causes stale references to be cleared from the data structures.

public V
get(K key)

Implements org.glassfish.hk2.utilities.general.WeakHashClock.get.

Gets the given key, returning null if not found

public boolean
hasWeakKeys()

Implements org.glassfish.hk2.utilities.general.WeakHashClock.hasWeakKeys.

Tells if this WeakHashClock has Weak keys

private DoubleNode<K, V>
private DoubleNode<K, V>
public Map.Entry<K, V>
next()

Implements org.glassfish.hk2.utilities.general.WeakHashClock.next.

Returns the next key/value pair in the clock, or null if the clock has no members.

public void
put(final K key, final V value)

Implements org.glassfish.hk2.utilities.general.WeakHashClock.put.

Adds the given pair to the clock.

public void
releaseMatching(CacheKeyFilter<K> filter)

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

Releases all key/value pairs that match the filter

public V
remove(K key)

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

Removes the given key from the clock, if found

private void
removeFromDLL(DoubleNode<K, V> removeMe)

private void
public int
size()

Implements org.glassfish.hk2.utilities.general.WeakHashClock.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, V>> byKey
byKeyNotWeakback to summary
private final ConcurrentHashMap<K, DoubleNode<K, V>> byKeyNotWeak
dotback to summary
private DoubleNode<K, V> dot
isWeakback to summary
private final boolean isWeak
lockback to summary
private final ReentrantLock lock
myQueueback to summary
private final ReferenceQueue<? super K> myQueue
tailback to summary
private DoubleNode<K, V> tail

Constructor Detail

WeakHashClockImplback to summary
public WeakHashClockImpl(boolean isWeak)

Method Detail

addBeforeDotback to summary
private DoubleNode<K, V> addBeforeDot(K key, V value)
clearback to summary
public void clear()

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

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

Sets the clock size back to zero, no entries

Annotations
@Override
clearStaleReferencesback to summary
public void clearStaleReferences()

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

Doc from org.glassfish.hk2.utilities.general.WeakHashClock.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
getback to summary
public V get(K key)

Implements org.glassfish.hk2.utilities.general.WeakHashClock.get.

Doc from org.glassfish.hk2.utilities.general.WeakHashClock.get.

Gets the given key, returning null if not found

Annotations
@Override
hasWeakKeysback to summary
public boolean hasWeakKeys()

Implements org.glassfish.hk2.utilities.general.WeakHashClock.hasWeakKeys.

Doc from org.glassfish.hk2.utilities.general.WeakHashClock.hasWeakKeys.

Tells if this WeakHashClock has Weak keys

Annotations
@Override
moveDotback to summary
private DoubleNode<K, V> moveDot()
moveDotNoWeakback to summary
private DoubleNode<K, V> moveDotNoWeak()
nextback to summary
public Map.Entry<K, V> next()

Implements org.glassfish.hk2.utilities.general.WeakHashClock.next.

Doc from org.glassfish.hk2.utilities.general.WeakHashClock.next.

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

Annotations
@Override
putback to summary
public void put(final K key, final V value)

Implements org.glassfish.hk2.utilities.general.WeakHashClock.put.

Doc from org.glassfish.hk2.utilities.general.WeakHashClock.put.

Adds the given pair to the clock. It will be placed at the current tail of the clock

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

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

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

Releases all key/value pairs that match the filter

Annotations
@Override
removeback to summary
public V remove(K key)

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

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

Removes the given key from the clock, if found

Annotations
@Override
removeFromDLLback to summary
private void removeFromDLL(DoubleNode<K, V> removeMe)
removeStaleback to summary
private void removeStale()
sizeback to summary
public int size()

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

Doc from org.glassfish.hk2.utilities.general.WeakHashClock.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