SolarMetric Kodo JDO 2.5.0 Reverse Schema Tool

com.solarmetric.rd.kodo.util
Class CacheMap

java.lang.Object
  |
  +--com.solarmetric.rd.kodo.util.CacheMap
All Implemented Interfaces:
java.util.Map

public class CacheMap
extends java.lang.Object
implements java.util.Map

A map that keeps hard references to a fixed number of elements and moves expired references to a soft reference map. Additionally, objects that are pinned are not counted towards the max size of the map.


Constructor Summary
CacheMap()
          Create a new CacheMap with an initial maximum unpinned object size of 1000.
CacheMap(int size)
          Create a new CacheMap with an initial maximum unpinned object size of size.
CacheMap(int size, float load)
          Create a new CacheMap with an initial maximum unpinned object size of size and a load factor of load.
 
Method Summary
 void clear()
          Removes pinned objects as well as unpinned ones.
 boolean containsKey(java.lang.Object o)
           
 boolean containsValue(java.lang.Object o)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 int getCacheSize()
          Returns the maximum number of unpinned objects to keep hard references to.
 java.util.Set getPinnedKeys()
          Returns the keys to the objects currently pinned into memory.
 boolean isEmpty()
           
 java.util.Set keySet()
           
 boolean pin(java.lang.Object key)
          Locks the key-value pair identified by key into the map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map map)
           
 java.lang.Object remove(java.lang.Object key)
          If key is pinned into the cache, the pin is cleared and the object is removed.
 void setCacheSize(int size)
          Sets the maximum number of unpinned objects to keep hard references to.
 int size()
           
 boolean unpin(java.lang.Object key)
          Removes the key-value pair identified by key from the set of pinned objects.
 java.util.Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

CacheMap

public CacheMap()
Create a new CacheMap with an initial maximum unpinned object size of 1000.


CacheMap

public CacheMap(int size)
Create a new CacheMap with an initial maximum unpinned object size of size.


CacheMap

public CacheMap(int size,
                float load)
Create a new CacheMap with an initial maximum unpinned object size of size and a load factor of load.

Method Detail

setCacheSize

public void setCacheSize(int size)
Sets the maximum number of unpinned objects to keep hard references to. If the map contains more unpinned objects than size, then this method will result in the cache flushing old values.


getCacheSize

public int getCacheSize()
Returns the maximum number of unpinned objects to keep hard references to.


getPinnedKeys

public java.util.Set getPinnedKeys()
Returns the keys to the objects currently pinned into memory.


pin

public boolean pin(java.lang.Object key)

Locks the key-value pair identified by key into the map. Objects pinned into the map are not counted towards the maximum size of the map, and are never removed except by explicit calls to remove(java.lang.Object) or clear().

If a key that is not currently in the cache is pinned, it will not be considered pinned once that key is used in the cache.

Returns:
true if key's value was pinned into the cache; false if the key is not in the cache.

unpin

public boolean unpin(java.lang.Object key)
Removes the key-value pair identified by key from the set of pinned objects. This key becomes a candidate for removal from the LRU map if the map exceeds the maximum size.

Returns:
true if key's value was unpinned from the cache; false if the key is not in the cache.

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map

putAll

public void putAll(java.util.Map map)
Specified by:
putAll in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
If key is pinned into the cache, the pin is cleared and the object is removed.

Specified by:
remove in interface java.util.Map

clear

public void clear()
Removes pinned objects as well as unpinned ones.

Specified by:
clear in interface java.util.Map

size

public int size()
Specified by:
size in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object o)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object o)
Specified by:
containsValue in interface java.util.Map

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map

SolarMetric Kodo JDO 2.5.0 Reverse Schema Tool

Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.