|
Java EE 5 SDK | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.appserv.util.cache.BaseCache
public class BaseCache
BaseCache Generic in-memory, abstract cache
| Nested Class Summary | |
|---|---|
protected static class |
BaseCache.CacheItem
default CacheItem class implementation |
| Field Summary | |
|---|---|
protected static ResourceBundle |
_rb
The resource bundle containing the localized message strings. |
protected Object[] |
bucketLocks
|
protected BaseCache.CacheItem[] |
buckets
|
protected int |
entryCount
|
protected ArrayList |
listeners
|
protected int |
maxBuckets
|
protected boolean[] |
refreshFlags
|
protected int |
threshold
threshold for the cache; once the threshold is reached entries are removed to accomodate newer inserts |
| Constructor Summary | |
|---|---|
BaseCache()
default constructor for the basic cache |
|
| Method Summary | |
|---|---|
protected Object |
_put(int hashCode,
Object key,
Object value,
int size,
boolean addValue)
cache the given value at the specified key and return previous value |
protected BaseCache.CacheItem |
_remove(int hashCode,
Object key,
Object value)
remove the item stored at the key. |
protected BaseCache.CacheItem |
_removeItem(BaseCache.CacheItem ritem)
remove the item stored at the key. |
void |
add(Object key,
Object value)
add the given value to the cache at the specified key |
void |
add(Object key,
Object value,
int size)
add the given value with specified size to the cache at specified key |
void |
addCacheListener(CacheListener listener)
add the cache module listener |
int |
clear()
clear all the entries from the cache. |
void |
clearStats()
clear the stats |
boolean |
contains(Object key)
check if the cache contains the item at the key |
protected BaseCache.CacheItem |
createItem(int hashCode,
Object key,
Object value,
int size)
create new item |
protected void |
decrementEntryCount()
|
void |
destroy()
Sets all references to null. |
Enumeration |
elements()
get an Enumeration for the keys stored in the cache |
protected boolean |
eq(Object x,
Object y)
Check for equality of non-null reference x and possibly-null y. |
Object |
get(int hashCode,
Object key)
get the item stored at the given pre-computed hash code and the key. |
Object |
get(Object key)
get the item stored at the key. |
Iterator |
getAll(Object key)
get all the items stored at the key. |
int |
getEntryCount()
get the number of entries in the cache |
protected int |
getIndex(int hashCode)
get the index of the item in the cache |
int |
getIndex(Object key)
get the index of the item given a key |
Object |
getStatByName(String key)
get the desired statistic counter |
Map |
getStats()
get the stats snapshot |
protected void |
handleOverflow()
increase the threshold |
protected int |
hash(Object x)
Returns a hash code for non-null Object x. |
protected void |
incrementAddCount()
|
protected void |
incrementEntryCount()
synchronized counter updates |
protected void |
incrementHitCount()
|
protected void |
incrementMissCount()
|
protected void |
incrementOverflowCount()
|
protected void |
incrementRefreshCount()
|
protected void |
incrementRemovalCount()
|
void |
init(int maxEntries,
float loadFactor,
Properties props)
initialize the cache |
void |
init(int maxEntries,
Properties props)
initialize the cache |
boolean |
isEmpty()
is this cache empty? |
protected boolean |
isThresholdReached()
has cache reached its threshold |
protected void |
itemAccessed(BaseCache.CacheItem item)
this item is accessed |
protected BaseCache.CacheItem |
itemAdded(BaseCache.CacheItem item)
this item is just added to the cache |
protected void |
itemRefreshed(BaseCache.CacheItem item,
int oldSize)
item value has been refreshed |
protected void |
itemRemoved(BaseCache.CacheItem item)
item value has been removed from the cache |
Iterator |
keys()
get an Iterator for the keys stored in the cache |
protected Object |
loadValue(Object key,
int hashCode)
Cannot find an item with the given key and hashCode |
void |
notifyRefresh(int index)
notify threads waiting for a refresh on the object associated with the key |
Object |
put(Object key,
Object value)
/** cache the given value at the specified key and return previous value |
Object |
put(Object key,
Object value,
int size)
cache the given value at the specified key and return previous value |
Object |
remove(int hashCode,
Object key)
remove the item stored at the key. |
Object |
remove(Object key)
remove the item stored at the key. |
Object |
remove(Object key,
Object value)
remove the given value stored at the key; value-specific removals. |
void |
removeAll(Object key)
remove all the item with the given key. |
void |
trimExpiredEntries(int maxCount)
trim the expired entries from the cache. |
protected void |
trimItem(BaseCache.CacheItem item)
trim the item from the cache and notify listeners |
Iterator |
values()
get an Iterator for the values stored in the cache |
boolean |
waitRefresh(int index)
wait for a refresh on the object associated with the key |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static ResourceBundle _rb
protected int entryCount
protected int threshold
protected int maxBuckets
protected BaseCache.CacheItem[] buckets
protected Object[] bucketLocks
protected boolean[] refreshFlags
protected ArrayList listeners
| Constructor Detail |
|---|
public BaseCache()
| Method Detail |
|---|
public void init(int maxEntries,
Properties props)
throws Exception
init in interface CachemaxEntries - maximum number of entries expected in the cacheprops - opaque list of properties for a given cache implementation
a - generic Exception if the initialization failed
Exception
public void init(int maxEntries,
float loadFactor,
Properties props)
init in interface CachemaxEntries - maximum number of entries expected in the cacheloadFactor - the load factorprops - opaque list of properties for a given cache implementation
a - generic Exception if the initialization failedpublic void addCacheListener(CacheListener listener)
addCacheListener in interface Cachelistener - CacheListener implementationprotected int hash(Object x)
protected boolean eq(Object x,
Object y)
protected void handleOverflow()
protected BaseCache.CacheItem itemAdded(BaseCache.CacheItem item)
item - CacheItem that was created
protected void itemAccessed(BaseCache.CacheItem item)
item - CacheItem accessed
Cache bucket is already synchronized by the caller
protected void itemRefreshed(BaseCache.CacheItem item,
int oldSize)
item - CacheItem that was refreshedoldSize - size of the previous value that was refreshed
Cache bucket is already synchronized by the callerprotected void itemRemoved(BaseCache.CacheItem item)
item - CacheItem that was just removed
Cache bucket is already synchronized by the caller
protected Object loadValue(Object key,
int hashCode)
key - Object that is not foundhashCode - int its hashCode
protected BaseCache.CacheItem createItem(int hashCode,
Object key,
Object value,
int size)
hashCode - for the entrykey - Object keyvalue - Object valuesize - size in bytes of the item
subclasses may override to provide their own CacheItem extensions
e.g. one that permits persistence.protected boolean isThresholdReached()
protected final int getIndex(int hashCode)
hashCode - of the entry
public final int getIndex(Object key)
getIndex in interface Cachekey - of the entry
public Object get(Object key)
get in interface Cachekey - lookup key
public Object get(int hashCode,
Object key)
key - lookup keypublic boolean contains(Object key)
contains in interface Cachekey - lookup keypublic Iterator getAll(Object key)
getAll in interface Cachekey - lookup keypublic Iterator keys()
keys in interface Cachepublic Enumeration elements()
elements in interface Cachepublic Iterator values()
values in interface Cache
public Object put(Object key,
Object value)
put in interface Cachekey - lookup keyobject - item value to be stored
public Object put(Object key,
Object value,
int size)
put in interface Cachekey - lookup keyobject - item value to be storedsize - in bytes of the value being cached
public void add(Object key,
Object value)
add in interface Cachekey - lookup keyobject - item value to be stored
public void add(Object key,
Object value,
int size)
add in interface Cachekey - lookup keyobject - item value to be storedsize - in bytes of the value being added
This function is suitable for multi-valued keys.
protected Object _put(int hashCode,
Object key,
Object value,
int size,
boolean addValue)
hashCode - previously computed hashCode for the keykey - lookup keyobject - item value to be storedsize - in bytes of the value being cachedaddValue - treate this operation to add (default is to replace)public Object remove(Object key)
remove in interface Cachekey - lookup key
public Object remove(int hashCode,
Object key)
hashCode - a precomputed hashCodekey - lookup key
public Object remove(Object key,
Object value)
remove in interface Cachekey - lookup keyvalue - to match (for a multi-valued keys)
protected BaseCache.CacheItem _remove(int hashCode,
Object key,
Object value)
hashCode - a precomputed hashCodekey - lookup keyvalue - of the item to be matchedprotected BaseCache.CacheItem _removeItem(BaseCache.CacheItem ritem)
item - CacheItem to be removed
public void removeAll(Object key)
removeAll in interface Cachekey - lookup keyprotected void trimItem(BaseCache.CacheItem item)
item - to be trimmedpublic boolean waitRefresh(int index)
waitRefresh in interface Cachekey - lookup keypublic void notifyRefresh(int index)
notifyRefresh in interface Cachekey - lookup keypublic int clear()
clear in interface Cachepublic void trimExpiredEntries(int maxCount)
trimExpiredEntries in interface CachemaxCount - maximum number of invalid entries to trim
specify Integer.MAX_VALUE to trim all timedout entries
This call is to be scheduled by a thread managed by the container.public int getEntryCount()
getEntryCount in interface Cachepublic boolean isEmpty()
isEmpty in interface Cacheprotected final void incrementEntryCount()
protected final void decrementEntryCount()
protected final void incrementHitCount()
protected final void incrementMissCount()
protected final void incrementRemovalCount()
protected final void incrementRefreshCount()
protected final void incrementAddCount()
protected final void incrementOverflowCount()
public Object getStatByName(String key)
getStatByName in interface Cachekey - to corresponding stat
public Map getStats()
getStats in interface Cachepublic void destroy()
destroy in interface Cachepublic void clearStats()
clearStats in interface Cache
|
Java EE 5 SDK | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 2006 Sun Microsystems, Inc. All rights reserved.