com.ibm.commerce.registry
Class AbstractManagedDynamicCacheRegistry
java.lang.Object
com.ibm.commerce.registry.AbstractManagedDynamicCacheRegistry
- All Implemented Interfaces:
- ElementUpdate, ManagedDynamicCache, Registry
- Direct Known Subclasses:
- StoreRegistry, TradingAgreementRegistry
- public abstract class AbstractManagedDynamicCacheRegistry
- extends java.lang.Object
- implements Registry, ManagedDynamicCache, ElementUpdate
This is an abstract class that implements the ManagedDynamicCache registry interface.
Field Summary |
static java.lang.String |
COPYRIGHT
IBM copyright notice field. |
Method Summary |
void |
addElement(java.lang.Object key, java.lang.Object cacheObject)
Adds an Element to the cache. |
abstract java.lang.Object |
createKey(java.lang.String strKey)
Creates a cache key for this registry based on a string representation of the key. |
abstract java.lang.String |
createKeyString(TypedProperty prop)
Creates a string representation of a cache key for this registry based on the input properties. |
java.lang.Object |
findObject(java.lang.Object key)
Gets an object from the registry. |
LRUDynamicHashtable |
getCache()
Gets the cache |
int |
getCacheSize()
Returns the total number of cache entries. |
java.lang.Object |
getElement(java.lang.Object key)
Gets an element from the cache. |
int |
getElementCount()
Gets the current number of cached elements. |
java.util.Enumeration |
getElements()
Gets an enumeration of all cached elements. |
long |
getEvictions()
Returns the number of entries that have been removed from the cache by LRU algorithm. |
long |
getHits()
Returns the number of cache hits. |
java.util.Enumeration |
getKeys()
Gets an enumeration of all cached keys. |
long |
getMisses()
Returns the number of cache misses. |
int |
getUsedCacheSize()
Returns the number of currently contained cache entries. |
void |
initialize()
Initializes the registry. |
abstract void |
populate(LRUDynamicHashtable aCache)
Populates the cache object. |
void |
refresh()
Refreshes all the elements in the cache. |
void |
removeAllElements()
Removes all cached elements. |
void |
removeElement(java.lang.Object key)
Removes a element from the cache. |
abstract java.lang.Object |
retrieve(java.lang.Object key)
Retrieves an object from the database and add it to the registry. |
void |
setCache(LRUDynamicHashtable cache)
Sets the cache |
void |
setCacheSize(int size)
Specifies the maximum cache size. |
void |
setInitialCapacity(int initialCapacity)
Sets the initial capacity of the registry. |
void |
setLoadFactor(float loadFactor)
Sets the load factor of the registry. |
void |
update(java.lang.String action, java.lang.Object key)
Updates a cached element. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
COPYRIGHT
public static final java.lang.String COPYRIGHT
- IBM copyright notice field.
- See Also:
- Constant Field Values
AbstractManagedDynamicCacheRegistry
public AbstractManagedDynamicCacheRegistry()
retrieve
public abstract java.lang.Object retrieve(java.lang.Object key)
throws java.lang.Exception
- Retrieves an object from the database and add it to the registry.
-
- Parameters:
- key - - a key used to identify the object to be retrieved
- Returns:
- the object associated with the key
- Throws:
- The - object ccannot be retrieved from database.
- java.lang.Exception
populate
public abstract void populate(LRUDynamicHashtable aCache)
throws java.lang.Exception
- Populates the cache object. This method should be a noop if this registry supports lazy fetch.
-
- Returns:
- the object associated with the key
- Throws:
- If - the object cannot be found in database and populate to the cache.
- java.lang.Exception
createKeyString
public abstract java.lang.String createKeyString(TypedProperty prop)
throws java.lang.Exception
- Creates a string representation of a cache key for this registry based on the input properties.
-
- Specified by:
- createKeyString in interface ElementUpdate
-
- Parameters:
- prop - The input properties used to contruct the string cache key
- Returns:
- The string representation of the cache key
- Throws:
- java.lang.Exception
createKey
public abstract java.lang.Object createKey(java.lang.String strKey)
throws java.lang.Exception
- Creates a cache key for this registry based on a string representation of the key.
-
- Specified by:
- createKey in interface ElementUpdate
-
- Parameters:
- strKey - The string representation of the cache key.
- Returns:
- The cache key
- Throws:
- java.lang.Exception
addElement
public void addElement(java.lang.Object key,
java.lang.Object cacheObject)
- Adds an Element to the cache.
getElement
public java.lang.Object getElement(java.lang.Object key)
- Gets an element from the cache.
-
- Specified by:
- getElement in interface ElementUpdate
-
- Parameters:
- key - The cache key for the element
- Returns:
- a cached element.
getElements
public java.util.Enumeration getElements()
- Gets an enumeration of all cached elements.
-
- Returns:
- an enumeration of all cached elements
getKeys
public java.util.Enumeration getKeys()
- Gets an enumeration of all cached keys.
-
- Returns:
- an enumeration of all cached keys
getElementCount
public int getElementCount()
- Gets the current number of cached elements.
-
- Returns:
- the number of cached elements.
findObject
public java.lang.Object findObject(java.lang.Object key)
throws java.lang.Exception
- Gets an object from the registry. It will first look for the object from the cache, If it is not in the cache, then it will retrieve it from the database and add to the cache.
-
- Parameters:
- key - The cache key.
- Returns:
- an object associated with the key.
- Throws:
- If - the object cannot be found in database.
- java.lang.Exception
initialize
public void initialize()
throws java.lang.Exception
- Initializes the registry. The cache size and/or the initialCapacity if set will be used to construct the dynamic cache. The registry will then be populated by calling the populate method.
-
- Specified by:
- initialize in interface Registry
-
- Throws:
- java.lang.Exception - during initialization.
refresh
public void refresh()
throws java.lang.Exception
- Refreshes all the elements in the cache.
-
- Specified by:
- refresh in interface Registry
-
- Throws:
- java.lang.Exception
update
public void update(java.lang.String action,
java.lang.Object key)
throws java.lang.Exception
- Updates a cached element.
-
- Specified by:
- update in interface ElementUpdate
-
- Parameters:
- action - The action performed on the registry. e.g. delete or update.
- key - The cache key.
- Throws:
- java.lang.Exception
removeAllElements
public void removeAllElements()
- Removes all cached elements.
removeElement
public void removeElement(java.lang.Object key)
- Removes a element from the cache.
getCacheSize
public int getCacheSize()
- Returns the total number of cache entries.
-
- Specified by:
- getCacheSize in interface ManagedDynamicCache
-
- Returns:
- The maximum size of the cache.
getMisses
public long getMisses()
- Returns the number of cache misses.
-
- Specified by:
- getMisses in interface ManagedDynamicCache
-
- Returns:
- Number of cache misses.
getEvictions
public long getEvictions()
- Returns the number of entries that have been removed from the cache by LRU algorithm.
-
- Specified by:
- getEvictions in interface ManagedDynamicCache
-
- Returns:
- Number of entries that have been removed from the cache.
getHits
public long getHits()
- Returns the number of cache hits.
-
- Specified by:
- getHits in interface ManagedDynamicCache
-
- Returns:
- Number of cache hits.
getUsedCacheSize
public int getUsedCacheSize()
- Returns the number of currently contained cache entries.
-
- Specified by:
- getUsedCacheSize in interface ManagedDynamicCache
-
- Returns:
- Number of cached entries.
setCacheSize
public void setCacheSize(int size)
- Specifies the maximum cache size.
setInitialCapacity
public void setInitialCapacity(int initialCapacity)
- Sets the initial capacity of the registry.
-
- Specified by:
- setInitialCapacity in interface ManagedDynamicCache
setLoadFactor
public void setLoadFactor(float loadFactor)
- Sets the load factor of the registry.
getCache
public LRUDynamicHashtable getCache()
- Gets the cache
-
- Returns:
- Returns a LRUDynamicHashtable
setCache
public void setCache(LRUDynamicHashtable cache)
- Sets the cache
-
- Parameters:
- cache - The cache to set
Feedback
(C) Copyright IBM Corporation 1996, 2005. All Rights Reserved.