Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-03

oracle.javatools.util
Class Maps.CacheStrategy<K,V,E extends Maps.AbstractLinkedEntry<K,V>>

java.lang.Object
  extended by oracle.javatools.util.Maps.CacheStrategy<K,V,E>
Direct Known Subclasses:
Maps.BoundedLruCacheStrategy, Maps.UnboundedCacheStrategy
Enclosing class:
Maps

public abstract static class Maps.CacheStrategy<K,V,E extends Maps.AbstractLinkedEntry<K,V>>
extends java.lang.Object

An abstract caching strategy for a cache map.

Implementations override one or more methods of this class to configure the cache map, to track its contents, and to evict stale values.

Implementations can configure the following immutable properties of the cache map:


Field Summary
static Maps.AbstractCacheMap.MappingType CANONICAL
           
static int DEFAULT_INITIAL_CAPACITY
           
static float DEFAULT_LOAD_FACTOR
           
static Maps.AbstractCacheMap.ReferenceType HARD
           
static Maps.AbstractCacheMap.MappingType NONCANONICAL
           
static Maps.AbstractCacheMap.ReferenceType SOFT
           
static Maps.AbstractCacheMap.ReferenceType WEAK
           
 
Constructor Summary
protected Maps.CacheStrategy(int initialCapacity, float loadFactor, Maps.AbstractCacheMap.ReferenceType valueReferenceType, Maps.AbstractCacheMap.MappingType mappingType)
          Constructs a cache strategy.
 
Method Summary
protected  void entryAccessed(Maps.AbstractCacheMap<K,V,E> map, E entry)
          Invoked when the value of an existing entry is accessed by Maps.AbstractHashMap.get(java.lang.Object).
protected  void entryAdded(Maps.AbstractCacheMap<K,V,E> map, E entry)
          Invoked when a new entry is added to this map, when entries are added by Maps.AbstractHashMap.put(K, V).
protected  void entryChanged(Maps.AbstractCacheMap<K,V,E> map, E oldEntry, V oldValue, E newEntry)
          Invoked when the value of an existing entry is changed, when entries are changed by Maps.AbstractHashMap.put(K, V) or evicted but not removed by Maps.AbstractCacheMap.evictExistingEntry(E).
protected  void entryEvicted(Maps.AbstractCacheMap<K,V,E> map, E entry)
          Invoked when an existing entry is evicted by Maps.AbstractCacheMap.evictExistingEntry(E) (e.g., because evictEldest(oracle.javatools.util.Maps.AbstractCacheMap, E) returned true) and the map is not canonical.
protected  void entryPurged(Maps.AbstractCacheMap<K,V,E> map, E entry)
          Invoked when an existing entry is purged after its value has been garbage collected.
protected  void entryRemoved(Maps.AbstractCacheMap<K,V,E> map, E entry)
          Invoked when an existing entry is removed by a remove method of this map, of a view collection of this map, or of an iterator of a view collection of this map

The Maps.AbstractCacheMap implementation never invokes entryRemoved(oracle.javatools.util.Maps.AbstractCacheMap, E) when entries are removed by the Maps.AbstractLinkedHashMap.clear() method of this map, or of a view collection of this map.

protected  boolean evictEldest(Maps.AbstractCacheMap<K,V,E> map, E eldest)
          Gets whether to evict the eldest entry from a cache.
 int getInitialCapacity()
          Gets the initial capacity of the cache map.
 float getLoadFactor()
          Gets the load factor of the cache map.
 Maps.AbstractCacheMap.MappingType getMappingType()
          Gets whether the cache maps canonically.
 Maps.AbstractCacheMap.ReferenceType getValueReferenceType()
          Gets the value reference type of the cache map.
protected  void mapChanged(Maps.AbstractCacheMap<K,V,E> map)
          Invoked when the map has changed, when entries are added, removed, or accessed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INITIAL_CAPACITY

public static final int DEFAULT_INITIAL_CAPACITY
See Also:
Constant Field Values

DEFAULT_LOAD_FACTOR

public static final float DEFAULT_LOAD_FACTOR
See Also:
Constant Field Values

HARD

public static final Maps.AbstractCacheMap.ReferenceType HARD

SOFT

public static final Maps.AbstractCacheMap.ReferenceType SOFT

WEAK

public static final Maps.AbstractCacheMap.ReferenceType WEAK

CANONICAL

public static final Maps.AbstractCacheMap.MappingType CANONICAL

NONCANONICAL

public static final Maps.AbstractCacheMap.MappingType NONCANONICAL
Constructor Detail

Maps.CacheStrategy

protected Maps.CacheStrategy(int initialCapacity,
                             float loadFactor,
                             Maps.AbstractCacheMap.ReferenceType valueReferenceType,
                             Maps.AbstractCacheMap.MappingType mappingType)
Constructs a cache strategy.

Method Detail

getInitialCapacity

public int getInitialCapacity()
Gets the initial capacity of the cache map.


getLoadFactor

public float getLoadFactor()
Gets the load factor of the cache map.


getValueReferenceType

public Maps.AbstractCacheMap.ReferenceType getValueReferenceType()
Gets the value reference type of the cache map.


getMappingType

public Maps.AbstractCacheMap.MappingType getMappingType()
Gets whether the cache maps canonically.


mapChanged

protected void mapChanged(Maps.AbstractCacheMap<K,V,E> map)
Invoked when the map has changed, when entries are added, removed, or accessed. This method is invoked before the associated entryAdded(oracle.javatools.util.Maps.AbstractCacheMap, E), entryRemoved(oracle.javatools.util.Maps.AbstractCacheMap, E), or entryAccessed(oracle.javatools.util.Maps.AbstractCacheMap, E) method is invoked.

The Maps.CacheStrategy implementation does nothing.


entryAdded

protected void entryAdded(Maps.AbstractCacheMap<K,V,E> map,
                          E entry)
Invoked when a new entry is added to this map, when entries are added by Maps.AbstractHashMap.put(K, V).

The Maps.CacheStrategy implementation does nothing.


entryChanged

protected void entryChanged(Maps.AbstractCacheMap<K,V,E> map,
                            E oldEntry,
                            V oldValue,
                            E newEntry)
Invoked when the value of an existing entry is changed, when entries are changed by Maps.AbstractHashMap.put(K, V) or evicted but not removed by Maps.AbstractCacheMap.evictExistingEntry(E).

If the entry to change was mutable, its value is changed with Map.Entry#setValue and oldEntry and newEntry are the same object. If the entry to change was not mutable, a new entry must be created and oldEntry and newEntry are different objects.

When a client directly invokes the Map.Entry#setValue method of any of the Map.Entry implementations provided in this class, this method is not invoked (while this could be addressed, it would require each entry instance to hold a reference to its map).

The Maps.CacheStrategy implementation does nothing.

Parameters:
oldEntry - The existing entry that changed.
oldValue - The old value of the entry.
newEntry - The new entry, which may be the same as the old.

entryAccessed

protected void entryAccessed(Maps.AbstractCacheMap<K,V,E> map,
                             E entry)
Invoked when the value of an existing entry is accessed by Maps.AbstractHashMap.get(java.lang.Object). Access to an entry by iterating a view collection of this map does not cause this method to be invoked.

The Maps.CacheStrategy implementation does nothing.


entryRemoved

protected void entryRemoved(Maps.AbstractCacheMap<K,V,E> map,
                            E entry)
Invoked when an existing entry is removed by a remove method of this map, of a view collection of this map, or of an iterator of a view collection of this map

The Maps.AbstractCacheMap implementation never invokes entryRemoved(oracle.javatools.util.Maps.AbstractCacheMap, E) when entries are removed by the Maps.AbstractLinkedHashMap.clear() method of this map, or of a view collection of this map.

The Maps.CacheStrategy implementation does nothing.


entryPurged

protected void entryPurged(Maps.AbstractCacheMap<K,V,E> map,
                           E entry)
Invoked when an existing entry is purged after its value has been garbage collected.

The Maps.AbstractCacheMap implementation only ever invokes entryPurged(oracle.javatools.util.Maps.AbstractCacheMap, E) for entries which extend SoftReference or WeakReference and which register themselves with the ReferenceQueue returned by Maps.AbstractHashMap.getQueue(). Maps provides four such classes: Maps.SoftEntry, Maps.WeakEntry, Maps.SoftLinkedEntry, and Maps.WeakLinkedEntry.

The Maps.CacheStrategy implementation does nothing.


entryEvicted

protected void entryEvicted(Maps.AbstractCacheMap<K,V,E> map,
                            E entry)
Invoked when an existing entry is evicted by Maps.AbstractCacheMap.evictExistingEntry(E) (e.g., because evictEldest(oracle.javatools.util.Maps.AbstractCacheMap, E) returned true) and the map is not canonical.

The Maps.CacheStrategy implementation does nothing.


evictEldest

protected boolean evictEldest(Maps.AbstractCacheMap<K,V,E> map,
                              E eldest)
Gets whether to evict the eldest entry from a cache. Invoked when an entry is added to the map, after entryAdded(oracle.javatools.util.Maps.AbstractCacheMap, E) is invoked, but not if entryAdded(oracle.javatools.util.Maps.AbstractCacheMap, E) modifies the map.

The Maps.CacheStrategy implementation returns false.

Parameters:
eldest - The eldest entry in the map, potentially to be evicted.
Returns:
whether the eldest entry should be evicted.

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-03

Copyright © 1997, 2009, Oracle. All rights reserved.