Package org.apache.openjpa.lib.util
Class LRUMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.apache.openjpa.lib.util.collections.AbstractHashedMap<K,V>
-
- org.apache.openjpa.lib.util.collections.AbstractLinkedMap<K,V>
-
- org.apache.openjpa.lib.util.collections.LRUMap
-
- org.apache.openjpa.lib.util.LRUMap
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map
,BoundedMap
,IterableMap
,OrderedMap
,SizedMap
public class LRUMap extends LRUMap implements SizedMap
Extension of the commonsLRUMap
that can change its maximum size.- Author:
- Abe White
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.openjpa.lib.util.collections.AbstractLinkedMap
AbstractLinkedMap.EntrySetIterator<K,V>, AbstractLinkedMap.KeySetIterator<K>, AbstractLinkedMap.LinkEntry<K,V>, AbstractLinkedMap.LinkIterator<K,V>, AbstractLinkedMap.LinkMapIterator<K,V>, AbstractLinkedMap.ValuesIterator<V>
-
Nested classes/interfaces inherited from class org.apache.openjpa.lib.util.collections.AbstractHashedMap
AbstractHashedMap.EntrySet<K,V>, AbstractHashedMap.HashEntry<K,V>, AbstractHashedMap.HashIterator<K,V>, AbstractHashedMap.HashMapIterator<K,V>, AbstractHashedMap.KeySet<K>, AbstractHashedMap.Values<V>
-
-
Field Summary
-
Fields inherited from class org.apache.openjpa.lib.util.collections.LRUMap
DEFAULT_MAX_SIZE
-
Fields inherited from class org.apache.openjpa.lib.util.collections.AbstractHashedMap
DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, GETKEY_INVALID, GETVALUE_INVALID, MAXIMUM_CAPACITY, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doReadObject(java.io.ObjectInputStream in)
Reads the data necessary forput()
to work in the superclass.protected void
doWriteObject(java.io.ObjectOutputStream out)
Writes the data necessary forput()
to work in deserialization.int
getMaxSize()
The maximum number of entries, or Integer.MAX_VALUE for no limit.boolean
isFull()
Returns true if this map is full and no new mappings can be added.int
maxSize()
Gets the maximum size of the map (the bound).void
overflowRemoved(java.lang.Object key, java.lang.Object value)
Overridable callback for when an overflow entry is automatically removed.protected boolean
removeLRU(AbstractLinkedMap.LinkEntry entry)
Subclass method to control removal of the least recently used entry from the map.void
setMaxSize(int max)
The maximum number of entries, or Integer.MAX_VALUE for no limit.-
Methods inherited from class org.apache.openjpa.lib.util.collections.LRUMap
addMapping, clone, get, get, isScanUntilRemovable, moveToMRU, reuseMapping, updateEntry
-
Methods inherited from class org.apache.openjpa.lib.util.collections.AbstractLinkedMap
addEntry, clear, containsValue, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, entryAfter, entryBefore, firstKey, getEntry, getEntry, init, lastKey, mapIterator, nextKey, previousKey, removeEntry
-
Methods inherited from class org.apache.openjpa.lib.util.collections.AbstractHashedMap
calculateNewCapacity, calculateThreshold, checkCapacity, containsKey, convertKey, destroyEntry, ensureCapacity, entryHashCode, entryKey, entryNext, entrySet, entryValue, equals, hash, hashCode, hashIndex, isEmpty, isEqualKey, isEqualValue, keySet, put, putAll, remove, removeMapping, reuseEntry, size, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.openjpa.lib.util.collections.IterableMap
clear, put, putAll
-
-
-
-
Method Detail
-
getMaxSize
public int getMaxSize()
Description copied from interface:SizedMap
The maximum number of entries, or Integer.MAX_VALUE for no limit.- Specified by:
getMaxSize
in interfaceSizedMap
-
setMaxSize
public void setMaxSize(int max)
Description copied from interface:SizedMap
The maximum number of entries, or Integer.MAX_VALUE for no limit.- Specified by:
setMaxSize
in interfaceSizedMap
-
overflowRemoved
public void overflowRemoved(java.lang.Object key, java.lang.Object value)
Description copied from interface:SizedMap
Overridable callback for when an overflow entry is automatically removed.- Specified by:
overflowRemoved
in interfaceSizedMap
-
maxSize
public int maxSize()
Description copied from class:LRUMap
Gets the maximum size of the map (the bound).- Specified by:
maxSize
in interfaceBoundedMap
- Overrides:
maxSize
in classLRUMap
- Returns:
- the maximum number of elements the map can hold
-
isFull
public boolean isFull()
Description copied from class:LRUMap
Returns true if this map is full and no new mappings can be added.
-
removeLRU
protected boolean removeLRU(AbstractLinkedMap.LinkEntry entry)
Description copied from class:LRUMap
Subclass method to control removal of the least recently used entry from the map.This method exists for subclasses to override. A subclass may wish to provide cleanup of resources when an entry is removed. For example:
protected boolean removeLRU(LinkEntry entry) { releaseResources(entry.getValue()); // release resources held by entry return true; // actually delete entry }
Alternatively, a subclass may choose to not remove the entry or selectively keep certain LRU entries. For example:
protected boolean removeLRU(LinkEntry entry) { if (entry.getKey().toString().startsWith("System.")) { return false; // entry not removed from LRUMap } else { return true; // actually delete entry } }
The effect of returning false is dependent on the scanUntilRemovable flag. If the flag is true, the next LRU entry will be passed to this method and so on until one returns false and is removed, or every entry in the map has been passed. If the scanUntilRemovable flag is false, the map will exceed the maximum size.NOTE: Commons Collections 3.0 passed the wrong entry to this method. This is fixed in version 3.1 onwards.
-
doWriteObject
protected void doWriteObject(java.io.ObjectOutputStream out) throws java.io.IOException
Description copied from class:LRUMap
Writes the data necessary forput()
to work in deserialization.- Overrides:
doWriteObject
in classLRUMap
- Parameters:
out
- the output stream- Throws:
java.io.IOException
- if an error occurs while writing to the stream
-
doReadObject
protected void doReadObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
Description copied from class:LRUMap
Reads the data necessary forput()
to work in the superclass.- Overrides:
doReadObject
in classLRUMap
- Parameters:
in
- the input stream- Throws:
java.io.IOException
- if an error occurs while reading from the streamjava.lang.ClassNotFoundException
- if an object read from the stream can not be loaded
-
-