Top Description Inners Fields Constructors Methods
org.glassfish.hk2.utilities.cache.internal

public Class WeakCARCacheImpl<K, V>

extends Object
implements WeakCARCache<K, V>
Class Inheritance
All Implemented Interfaces
org.glassfish.hk2.utilities.cache.WeakCARCache
Imports
java.util.Map, java.util.concurrent.atomic.AtomicLong, java.util.concurrent.locks.ReentrantLock, org.glassfish.hk2.utilities.cache.CacheKeyFilter, .Computable, .ComputationErrorException, .WeakCARCache, org.glassfish.hk2.utilities.general.GeneralUtilities, .WeakHashClock, .WeakHashLRU

Implements the CAR algorithm as found here: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.105.6057
Author
jwells

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final WeakHashLRU<K>
private final WeakHashLRU<K>
private final Computable<K, V>
private final AtomicLong
private final ReentrantLock
private final int
private int
p

private final WeakHashClock<K, WeakCARCacheImpl.CarValue<V>>
private final WeakHashClock<K, WeakCARCacheImpl.CarValue<V>>
private final AtomicLong

Constructor Summary

AccessConstructor and Description
public
WeakCARCacheImpl(Computable<K, V> computable, int maxSize, boolean isWeak)

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.clear.

Clears the current cache, making the current size zero

public void
clearStaleReferences()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.clearStaleReferences.

Causes stale references to be cleared from the data structures.

public V
compute(K key)

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.compute.

The method used to get or add values to this cache

public String
dumpAllLists()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.dumpAllLists.

Returns a string that will contain all the elements of the four lists

public int
getB1Size()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getB1Size.

Returns the number of items in the B1 LRU

public int
getB2Size()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getB2Size.

Returns the number of items in the B2 LRU

public Computable<K, V>
getComputable()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getComputable.

The computable associated with this cache

public double
getHitRate()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getHitRate.

Returns the hit rate from the last time clear was called

public int
getKeySize()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getKeySize.

Returns the current number of keys in the cache.

public int
getMaxSize()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getMaxSize.

Gets the current maximum size of the cache (the maximum number of values that will be kept by the cache).

public int
getP()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getP.

Returns the value of p from the CAR algorithm, which is the target size of the t1 clock

public int
getT1Size()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getT1Size.

Returns the number of items in the T1 clock

public int
getT2Size()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getT2Size.

Returns the number of items in the T2 clock

private V
public int
getValueSize()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getValueSize.

Returns the current number of values in the cache.

public void
releaseMatching(CacheKeyFilter<K> filter)

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.releaseMatching.

Releases all key/value pairs that match the filter

public boolean
remove(K key)

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.remove.

Used to remove a single key and value from the cache (if the value is available)

private void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

b1back to summary
private final WeakHashLRU<K> b1
b2back to summary
private final WeakHashLRU<K> b2
computableback to summary
private final Computable<K, V> computable
hitsback to summary
private final AtomicLong hits
lockback to summary
private final ReentrantLock lock
maxSizeback to summary
private final int maxSize
pback to summary
private int p
t1back to summary
private final WeakHashClock<K, WeakCARCacheImpl.CarValue<V>> t1
t2back to summary
private final WeakHashClock<K, WeakCARCacheImpl.CarValue<V>> t2
triesback to summary
private final AtomicLong tries

Constructor Detail

WeakCARCacheImplback to summary
public WeakCARCacheImpl(Computable<K, V> computable, int maxSize, boolean isWeak)

Method Detail

clearback to summary
public void clear()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.clear.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.clear.

Clears the current cache, making the current size zero

Annotations
@Override
clearStaleReferencesback to summary
public void clearStaleReferences()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.clearStaleReferences.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.clearStaleReferences.

Causes stale references to be cleared from the data structures. Since this is a weak cache 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
computeback to summary
public V compute(K key)

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.compute.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.compute.

The method used to get or add values to this cache

Annotations
@SuppressWarnings:unchecked
@Override
dumpAllListsback to summary
public String dumpAllLists()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.dumpAllLists.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.dumpAllLists.

Returns a string that will contain all the elements of the four lists

Annotations
@Override
getB1Sizeback to summary
public int getB1Size()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getB1Size.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getB1Size.

Returns the number of items in the B1 LRU

Annotations
@Override
getB2Sizeback to summary
public int getB2Size()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getB2Size.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getB2Size.

Returns the number of items in the B2 LRU

Annotations
@Override
getComputableback to summary
public Computable<K, V> getComputable()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getComputable.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getComputable.

The computable associated with this cache

Annotations
@Override
getHitRateback to summary
public double getHitRate()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getHitRate.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getHitRate.

Returns the hit rate from the last time clear was called

Annotations
@Override
getKeySizeback to summary
public int getKeySize()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getKeySize.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getKeySize.

Returns the current number of keys in the cache. Note that the number of keys can be up to 2x the maximum size of the cache

Annotations
@Override
getMaxSizeback to summary
public int getMaxSize()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getMaxSize.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getMaxSize.

Gets the current maximum size of the cache (the maximum number of values that will be kept by the cache). Note that the number of keys kept will be 2x, where x is the maximum size of the cache (see CAR algorithm which keeps a key history)

Annotations
@Override
getPback to summary
public int getP()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getP.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getP.

Returns the value of p from the CAR algorithm, which is the target size of the t1 clock

Annotations
@Override
getT1Sizeback to summary
public int getT1Size()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getT1Size.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getT1Size.

Returns the number of items in the T1 clock

Annotations
@Override
getT2Sizeback to summary
public int getT2Size()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getT2Size.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getT2Size.

Returns the number of items in the T2 clock

Annotations
@Override
getValueFromTback to summary
private V getValueFromT(K key)
getValueSizeback to summary
public int getValueSize()

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.getValueSize.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.getValueSize.

Returns the current number of values in the cache. Note that the number of values can be up the maximum size of the cache

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

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.releaseMatching.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.releaseMatching.

Releases all key/value pairs that match the filter

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

Implements org.glassfish.hk2.utilities.cache.WeakCARCache.remove.

Doc from org.glassfish.hk2.utilities.cache.WeakCARCache.remove.

Used to remove a single key and value from the cache (if the value is available)

Annotations
@Override
replaceback to summary
private void replace()
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
org.glassfish.hk2.utilities.cache.internal back to summary

private Class WeakCARCacheImpl.CarValue<V>

extends Object
Class Inheritance
  • java.lang.Object
  • org.glassfish.hk2.utilities.cache.internal.WeakCARCacheImpl.CarValue

Field Summary

Modifier and TypeField and Description
private volatile boolean
private final V

Constructor Summary

AccessConstructor and Description
private
CarValue(V value)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

referenceBitback to summary
private volatile boolean referenceBit
valueback to summary
private final V value

Constructor Detail

CarValueback to summary
private CarValue(V value)