Class FIFOEJBObjectCache
- java.lang.Object
-
- com.sun.appserv.util.cache.BaseCache
-
- com.sun.appserv.util.cache.LruCache
-
- com.sun.ejb.containers.util.cache.LruEJBCache
-
- org.glassfish.persistence.ejb.entitybean.container.cache.FIFOEJBObjectCache
-
- All Implemented Interfaces:
Cache
,EJBObjectCache
public class FIFOEJBObjectCache extends LruEJBCache implements EJBObjectCache
A FIFO EJB(Local)Object cache that maintains reference count- Author:
- Mahesh Kannan
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
FIFOEJBObjectCache.EJBObjectCacheItem
-
Nested classes/interfaces inherited from class com.sun.appserv.util.cache.LruCache
LruCache.LruCacheItem
-
Nested classes/interfaces inherited from class com.sun.appserv.util.cache.BaseCache
BaseCache.CacheItem
-
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
_printRefCount
protected EJBObjectCacheListener
listener
protected int
maxCacheSize
protected String
name
protected Object
refCountLock
protected int
totalRefCount
-
Fields inherited from class com.sun.ejb.containers.util.cache.LruEJBCache
cacheName
-
Fields inherited from class com.sun.appserv.util.cache.LruCache
defaultMaxEntries, head, isUnbounded, listSize, NO_TIMEOUT, tail, timeout, trimCount
-
Fields inherited from class com.sun.appserv.util.cache.BaseCache
bucketLocks, buckets, entryCount, hitCount, listeners, maxBuckets, maxEntries, missCount, refreshFlags, removalCount, threshold
-
-
Constructor Summary
Constructors Constructor Description FIFOEJBObjectCache(String name)
default constructorFIFOEJBObjectCache(String name, long timeout)
constructor with specified timeout
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BaseCache.CacheItem
createItem(int hashCode, Object key, Object value, int size)
create new itemprotected void
decrementReferenceCount()
protected void
decrementReferenceCount(int count)
Object
get(Object key)
get the item stored at the key.Object
get(Object key, boolean incrementRefCount)
Map
getStats()
get the stats snapshotprotected void
incrementReferenceCount()
void
init(int maxEntries, int numberOfVictimsToSelect, long timeout, float loadFactor, Properties props)
protected Object
internalGet(int hashCode, Object key, boolean incrementRefCount)
protected Object
internalPut(int hashCode, Object key, Object value, int size, boolean incrementRefCount)
protected Object
internalRemove(Object key, boolean decrementRefCount)
protected boolean
isThresholdReached()
has cache reached its thresholdprotected void
itemAccessed(BaseCache.CacheItem item)
this item is accessedprotected void
itemRemoved(BaseCache.CacheItem item)
item value has been removed from the cachestatic void
main(String[] args)
void
print()
Object
put(Object key, Object value)
/** cache the given value at the specified key and return previous valueObject
put(Object key, Object value, boolean incrementRefCount)
Object
remove(Object key)
remove the item stored at the key.Object
remove(Object key, boolean decrementRefCount)
void
setEJBObjectCacheListener(EJBObjectCacheListener listener)
void
trimExpiredEntries(int maxCount)
trim the expired entries from the cache.-
Methods inherited from class com.sun.ejb.containers.util.cache.LruEJBCache
itemAdded, setCacheName, trimLru
-
Methods inherited from class com.sun.appserv.util.cache.LruCache
getStatByName, init, itemRefreshed, setTimeout
-
Methods inherited from class com.sun.appserv.util.cache.BaseCache
_put, _remove, _removeItem, add, add, addCacheListener, clear, clearStats, contains, decrementEntryCount, destroy, elements, eq, get, getAll, getEntryCount, getIndex, getIndex, handleOverflow, hash, incrementAddCount, incrementEntryCount, incrementHitCount, incrementMissCount, incrementOverflowCount, incrementRefreshCount, incrementRemovalCount, init, init, isEmpty, keys, loadValue, notifyRefresh, put, remove, remove, removeAll, trimItem, values, waitRefresh
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.sun.appserv.util.cache.Cache
add, add, addCacheListener, clear, clearStats, contains, destroy, elements, getAll, getEntryCount, getIndex, getStatByName, init, init, isEmpty, keys, notifyRefresh, put, remove, removeAll, values, waitRefresh
-
-
-
-
Field Detail
-
maxCacheSize
protected int maxCacheSize
-
name
protected String name
-
listener
protected EJBObjectCacheListener listener
-
refCountLock
protected Object refCountLock
-
totalRefCount
protected int totalRefCount
-
_printRefCount
protected static final boolean _printRefCount
-
-
Method Detail
-
init
public void init(int maxEntries, int numberOfVictimsToSelect, long timeout, float loadFactor, Properties props)
- Specified by:
init
in interfaceEJBObjectCache
-
setEJBObjectCacheListener
public void setEJBObjectCacheListener(EJBObjectCacheListener listener)
- Specified by:
setEJBObjectCacheListener
in interfaceEJBObjectCache
-
get
public Object get(Object key)
Description copied from class:BaseCache
get the item stored at the key.
-
get
public Object get(Object key, boolean incrementRefCount)
- Specified by:
get
in interfaceEJBObjectCache
-
put
public Object put(Object key, Object value)
Description copied from class:BaseCache
/** cache the given value at the specified key and return previous value
-
put
public Object put(Object key, Object value, boolean incrementRefCount)
- Specified by:
put
in interfaceEJBObjectCache
-
remove
public Object remove(Object key)
Description copied from class:BaseCache
remove the item stored at the key.
-
remove
public Object remove(Object key, boolean decrementRefCount)
- Specified by:
remove
in interfaceEJBObjectCache
-
isThresholdReached
protected boolean isThresholdReached()
Description copied from class:BaseCache
has cache reached its threshold- Overrides:
isThresholdReached
in classBaseCache
- Returns:
- true when the cache reached its threshold
-
itemAccessed
protected void itemAccessed(BaseCache.CacheItem item)
Description copied from class:LruCache
this item is accessed- Overrides:
itemAccessed
in classLruCache
- Parameters:
item
-CacheItem
accessed Cache bucket is already synchronized by the caller
-
itemRemoved
protected void itemRemoved(BaseCache.CacheItem item)
Description copied from class:LruCache
item value has been removed from the cache- Overrides:
itemRemoved
in classLruCache
- Parameters:
item
-CacheItem
that was just removed Cache bucket is already synchronized by the caller
-
internalPut
protected Object internalPut(int hashCode, Object key, Object value, int size, boolean incrementRefCount)
-
print
public void print()
-
createItem
protected BaseCache.CacheItem createItem(int hashCode, Object key, Object value, int size)
Description copied from class:LruCache
create new item- Overrides:
createItem
in classLruCache
- Parameters:
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.
-
trimExpiredEntries
public void trimExpiredEntries(int maxCount)
Description copied from class:LruCache
trim the expired entries from the cache.- Specified by:
trimExpiredEntries
in interfaceCache
- Overrides:
trimExpiredEntries
in classLruCache
- Parameters:
maxCount
- maximum number of invalid entries to trim specify Integer.MAX_VALUE to trim all invalid entries This call is to be scheduled by a thread managed by the container. NOTE: this algorithm assumes that all the entries in the cache have identical timeout (otherwise traversing from tail won't be right).
-
incrementReferenceCount
protected void incrementReferenceCount()
-
decrementReferenceCount
protected void decrementReferenceCount()
-
decrementReferenceCount
protected void decrementReferenceCount(int count)
-
-