| java.lang.Object org.apache.openjpa.util.CacheMap
CacheMap | public class CacheMap implements Map(Code) | | Fixed-size map that has ability to pin/unpin entries and move overflow to
a backing soft map.
author: Patrick Linskey author: Abe White |
Field Summary | |
final protected SizedMap | cacheMap The map for non-expired and non-pinned references. | final protected Map | pinnedMap The set of objects pinned into the cache. | final protected SizedMap | softMap The map for expired references. |
Constructor Summary | |
public | CacheMap() Create a non-LRU (and therefore highly concurrent) cache map with a
size of 1000. | public | CacheMap(boolean lru, int max) Create a cache map with the given properties. | public | CacheMap(boolean lru, int max, int size, float load) Create a cache map with the given properties. |
Method Summary | |
protected void | cacheMapOverflowRemoved(Object key, Object value) Called from
SizedMap.overflowRemoved in the cache map. | public void | clear() Removes pinned objects as well as unpinned ones. | public boolean | containsKey(Object key) | public boolean | containsValue(Object val) | protected void | entryAdded(Object key, Object value) Invoked when an entry is added to the cache. | protected void | entryRemoved(Object key, Object value, boolean expired) Invoked when a key-value pair is evicted from this data
structure. | public Set | entrySet() | public Object | get(Object key) | public int | getCacheSize() The maximum number of hard references to maintain, or -1 for no limit. | public Set | getPinnedKeys() The keys pinned into the map. | public int | getSoftReferenceSize() The maximum number of soft references to maintain, or -1 for no limit. | public boolean | isEmpty() | public boolean | isLRU() Whether this cache map uses LRU eviction. | public Set | keySet() | public boolean | pin(Object key) Locks the given key and its value into the map. | protected Object | put(Map map, Object key, Object value) Put the given entry into the given map. | public Object | put(Object key, Object value) | public void | putAll(Map map) | public void | readLock() Acquire read lock. | public void | readUnlock() Release read lock. | protected Object | remove(Map map, Object key) Remove the given key from the given map. | public Object | remove(Object key) If key is pinned into the cache, the pin is
cleared and the object is removed. | public void | setCacheSize(int size) The maximum number of hard references to maintain, or -1 for no limit. | public void | setSoftReferenceSize(int size) The maximum number of soft references to maintain, or -1 for no limit. | public int | size() | protected void | softMapOverflowRemoved(Object key, Object value) Called from
SizedMap.overflowRemoved in the soft map. | protected void | softMapValueExpired(Object key) Called when a value expires from the soft map. | public String | toString() | public boolean | unpin(Object key) Undo a pinning. | public Collection | values() | public void | writeLock() Acquire write lock. | public void | writeUnlock() Release write lock. |
cacheMap | final protected SizedMap cacheMap(Code) | | The map for non-expired and non-pinned references.
|
pinnedMap | final protected Map pinnedMap(Code) | | The set of objects pinned into the cache.
|
softMap | final protected SizedMap softMap(Code) | | The map for expired references.
|
CacheMap | public CacheMap()(Code) | | Create a non-LRU (and therefore highly concurrent) cache map with a
size of 1000.
|
CacheMap | public CacheMap(boolean lru, int max)(Code) | | Create a cache map with the given properties.
|
CacheMap | public CacheMap(boolean lru, int max, int size, float load)(Code) | | Create a cache map with the given properties.
|
clear | public void clear()(Code) | | Removes pinned objects as well as unpinned ones.
|
entryAdded | protected void entryAdded(Object key, Object value)(Code) | | Invoked when an entry is added to the cache. This may be invoked
more than once for an entry.
|
entryRemoved | protected void entryRemoved(Object key, Object value, boolean expired)(Code) | | Invoked when a key-value pair is evicted from this data
structure. This is invoked with expired set to
true when an object is dropped because of space
requirements or through garbage collection of soft references.
It is invoked with expired set to false
when an object is explicitly removed via the
CacheMap.remove or
CacheMap.clear methods. This may be invoked more than once for a
given entry.
Parameters: value - may be null if the value was a soft reference that hasbeen GCd since: 0.2.5.0 |
getCacheSize | public int getCacheSize()(Code) | | The maximum number of hard references to maintain, or -1 for no limit.
|
getPinnedKeys | public Set getPinnedKeys()(Code) | | The keys pinned into the map.
|
getSoftReferenceSize | public int getSoftReferenceSize()(Code) | | The maximum number of soft references to maintain, or -1 for no limit.
|
isEmpty | public boolean isEmpty()(Code) | | |
isLRU | public boolean isLRU()(Code) | | Whether this cache map uses LRU eviction.
|
pin | public boolean pin(Object key)(Code) | | Locks the given key and its value into the map. Objects pinned into
the map are not counted towards the maximum cache size, and are never
evicted implicitly. You may pin keys for which no value is in the map.
true if the givne key's value was pinned; false if no valuefor the given key is cached |
put | protected Object put(Map map, Object key, Object value)(Code) | | Put the given entry into the given map. Allows subclasses to
take additional actions.
|
readLock | public void readLock()(Code) | | Acquire read lock.
|
readUnlock | public void readUnlock()(Code) | | Release read lock.
|
remove | protected Object remove(Map map, Object key)(Code) | | Remove the given key from the given map. Allows subclasses to
take additional actions.
|
remove | public Object remove(Object key)(Code) | | If key is pinned into the cache, the pin is
cleared and the object is removed.
|
setCacheSize | public void setCacheSize(int size)(Code) | | The maximum number of hard references to maintain, or -1 for no limit.
|
setSoftReferenceSize | public void setSoftReferenceSize(int size)(Code) | | The maximum number of soft references to maintain, or -1 for no limit.
|
softMapValueExpired | protected void softMapValueExpired(Object key)(Code) | | Called when a value expires from the soft map.
|
writeLock | public void writeLock()(Code) | | Acquire write lock.
|
writeUnlock | public void writeUnlock()(Code) | | Release write lock.
|
|
|