Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

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

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

public abstract static class Maps.CacheStrategy<K,V>
extends java.lang.Object
implements java.io.Serializable

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:

Two methods that are of particular use in implementing an eviction strategy are Maps.CacheMap.getEldestEntry() and Maps.CacheMap.evictEntry(oracle.javatools.util.Maps.LinkedEntry).

See Also:
Serialized Form

Field Summary
static Maps.CacheMap.Canonicity CANONICAL
           
static int DEFAULT_INITIAL_CAPACITY
           
static float DEFAULT_LOAD_FACTOR
           
static Maps.CacheMap.Strength HARD
          Deprecated. Use STRONG.
static Maps.CacheMap.Canonicity NONCANONICAL
          Deprecated. Use NOT_CANONICAL.
static Maps.CacheMap.Canonicity NOT_CANONICAL
           
static Maps.CacheMap.Strength SOFT
           
static Maps.CacheMap.Strength STRONG
           
static Maps.CacheMap.Strength WEAK
           
 
Constructor Summary
protected Maps.CacheStrategy(int initialCapacity, float loadFactor, Maps.CacheMap.Canonicity canonicity, Maps.CacheMap.Strength defaultStrength)
          Constructs a cache strategy.
 
Method Summary
protected  Maps.LinkedEntry<K,V> createDefaultEntry(int hashCode, K key, V value, Maps.LinkedEntry<K,V> next)
           
protected  Maps.LinkedEntry<K,V> createEntry(int hashCode, K key, V value, Maps.LinkedEntry<K,V> next, java.lang.ref.ReferenceQueue<V> queue)
          
protected  Maps.LinkedEntry<K,V> createEvictedEntry(int hashCode, K key, V value, Maps.LinkedEntry<K,V> next, java.lang.ref.ReferenceQueue<V> queue)
           
protected  Maps.LinkedEntry<K,V> createSoftEntry(int hashCode, K key, V value, Maps.LinkedEntry<K,V> next, java.lang.ref.ReferenceQueue<V> queue)
           
protected  Maps.LinkedEntry<K,V> createWeakEntry(int hashCode, K key, V value, Maps.LinkedEntry<K,V> next, java.lang.ref.ReferenceQueue<V> queue)
           
protected  void entryAccessed(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> entry)
          Invoked when the value of an existing entry is accessed by Maps.AbstractHashMap.get(java.lang.Object).
protected  void entryAdded(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> 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.CacheMap<K,V> map, Maps.LinkedEntry<K,V> oldEntry, V oldValue, Maps.LinkedEntry<K,V> newEntry)
          Invoked when the value of an existing entry is changed or when entries are changed by Maps.AbstractHashMap.put(K, V).
protected  void entryEvicted(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> entry)
          Invoked when an existing entry is evicted by Maps.AbstractLinkedHashMap.evictEntry(E).
protected  void entryPurged(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> entry)
          Invoked when an existing entry is purged after its value has been garbage collected.
protected  void entryRemoved(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> 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.CacheMap implementation never invokes entryRemoved(oracle.javatools.util.Maps.CacheMap, oracle.javatools.util.Maps.LinkedEntry) when entries are removed by the Maps.CacheMap.clear() method of this map, or of a view collection of this map.

 Maps.CacheMap.Canonicity getCanonicity()
          Gets whether the cache maps canonically.
 Maps.CacheMap.Strength getDefaultStrength()
          Gets the value reference type of the cache map.
 int getInitialCapacity()
          Gets the initial capacity of the cache map.
 float getLoadFactor()
          Gets the load factor of the cache map.
protected  void mapChanged(Maps.CacheMap<K,V> map)
          Invoked when the map has changed, when entries are added, removed, or accessed.
protected  void mapConstructed(Maps.CacheMap<K,V> map)
          Invoked when the map has constructed.
 
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

STRONG

public static final Maps.CacheMap.Strength STRONG

SOFT

public static final Maps.CacheMap.Strength SOFT

WEAK

public static final Maps.CacheMap.Strength WEAK

HARD

public static final Maps.CacheMap.Strength HARD
Deprecated. Use STRONG.

CANONICAL

public static final Maps.CacheMap.Canonicity CANONICAL

NOT_CANONICAL

public static final Maps.CacheMap.Canonicity NOT_CANONICAL

NONCANONICAL

public static final Maps.CacheMap.Canonicity NONCANONICAL
Deprecated. Use NOT_CANONICAL.
Constructor Detail

Maps.CacheStrategy

protected Maps.CacheStrategy(int initialCapacity,
                             float loadFactor,
                             Maps.CacheMap.Canonicity canonicity,
                             Maps.CacheMap.Strength defaultStrength)
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.


getCanonicity

public Maps.CacheMap.Canonicity getCanonicity()
Gets whether the cache maps canonically.


getDefaultStrength

public Maps.CacheMap.Strength getDefaultStrength()
Gets the value reference type of the cache map.


createEntry

protected Maps.LinkedEntry<K,V> createEntry(int hashCode,
                                            K key,
                                            V value,
                                            Maps.LinkedEntry<K,V> next,
                                            java.lang.ref.ReferenceQueue<V> queue)

The Maps.CacheMap implementation delegates to createDefaultEntry(int, K, V, oracle.javatools.util.Maps.LinkedEntry), createSoftEntry(int, K, V, oracle.javatools.util.Maps.LinkedEntry, java.lang.ref.ReferenceQueue), or createWeakEntry(int, K, V, oracle.javatools.util.Maps.LinkedEntry, java.lang.ref.ReferenceQueue) as indicated by getDefaultStrength().


createDefaultEntry

protected Maps.LinkedEntry<K,V> createDefaultEntry(int hashCode,
                                                   K key,
                                                   V value,
                                                   Maps.LinkedEntry<K,V> next)

createSoftEntry

protected Maps.LinkedEntry<K,V> createSoftEntry(int hashCode,
                                                K key,
                                                V value,
                                                Maps.LinkedEntry<K,V> next,
                                                java.lang.ref.ReferenceQueue<V> queue)

createWeakEntry

protected Maps.LinkedEntry<K,V> createWeakEntry(int hashCode,
                                                K key,
                                                V value,
                                                Maps.LinkedEntry<K,V> next,
                                                java.lang.ref.ReferenceQueue<V> queue)

createEvictedEntry

protected Maps.LinkedEntry<K,V> createEvictedEntry(int hashCode,
                                                   K key,
                                                   V value,
                                                   Maps.LinkedEntry<K,V> next,
                                                   java.lang.ref.ReferenceQueue<V> queue)

mapConstructed

protected void mapConstructed(Maps.CacheMap<K,V> map)
Invoked when the map has constructed.

The Maps.CacheStrategy implementation does nothing.


mapChanged

protected void mapChanged(Maps.CacheMap<K,V> 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.CacheMap, oracle.javatools.util.Maps.LinkedEntry), entryRemoved(oracle.javatools.util.Maps.CacheMap, oracle.javatools.util.Maps.LinkedEntry), or entryAccessed(oracle.javatools.util.Maps.CacheMap, oracle.javatools.util.Maps.LinkedEntry) method is invoked.

The Maps.CacheStrategy implementation does nothing.


entryAdded

protected void entryAdded(Maps.CacheMap<K,V> map,
                          Maps.LinkedEntry<K,V> 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.CacheMap<K,V> map,
                            Maps.LinkedEntry<K,V> oldEntry,
                            V oldValue,
                            Maps.LinkedEntry<K,V> newEntry)
Invoked when the value of an existing entry is changed or when entries are changed by Maps.AbstractHashMap.put(K, V).

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.CacheMap<K,V> map,
                             Maps.LinkedEntry<K,V> 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.CacheMap<K,V> map,
                            Maps.LinkedEntry<K,V> 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.CacheMap implementation never invokes entryRemoved(oracle.javatools.util.Maps.CacheMap, oracle.javatools.util.Maps.LinkedEntry) when entries are removed by the Maps.CacheMap.clear() method of this map, or of a view collection of this map.

The Maps.CacheStrategy implementation does nothing.


entryPurged

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

The Maps.CacheMap implementation only ever invokes entryPurged(oracle.javatools.util.Maps.CacheMap, oracle.javatools.util.Maps.LinkedEntry) 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.CacheMap<K,V> map,
                            Maps.LinkedEntry<K,V> entry)
Invoked when an existing entry is evicted by Maps.AbstractLinkedHashMap.evictEntry(E).

If this map is canonical, eviction means the entry was converted to a weak reference and mapChanged(oracle.javatools.util.Maps.CacheMap) was not invoked. If the map is not canonical, eviction means the entry was removed and mapChanged(oracle.javatools.util.Maps.CacheMap) was invoked.

The Maps.CacheStrategy implementation does nothing.


Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

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