Expresso 5-6

com.jcorporate.expresso.core.cache
Class DefaultCacheManager

java.lang.Object
  extended bycom.jcorporate.expresso.kernel.ComponentBase
      extended bycom.jcorporate.expresso.core.cache.DefaultCacheManager
All Implemented Interfaces:
CacheSystem, ComponentLifecycle, Describable, ExpressoComponent, Serializable

public class DefaultCacheManager
extends ComponentBase
implements ComponentLifecycle, CacheSystem

[Currently a placeholder. Will be expanded out soon]

Author:
Michael Rimov
See Also:
Serialized Form

Constructor Summary
DefaultCacheManager()
           
 
Method Summary
 void addItem(String cacheName, Cacheable newItem)
          Adds a Cacheable item into the cache
 void addItem(String cacheName, Cacheable newItem, long expiry)
          Adds an item to the cache named by parameter cacheName
 void addListener(String listener, String listenTo)
          Specify a relationship between caches.
 void adjustForMemory()
          Instructs the cache system to adjust it's usage profile based upon current memory information that the expresso system is telling us.
 void checkMemory()
          

Checks to make sure that there is enough memory available to use for more caches.

 void clear()
          Removes all cache items for a particular data context
 void clear(String cacheName)
          Clear's the named cache.
 boolean clearLowestCache()
          Removed the least used Cache
 void clearNoNotify()
          Clears all caches in this db context but doesn't notify any listeners
 void clearNoNotify(String cacheName)
          Clear the named cache, but don't send the remote system notifications.
 void configure(Configuration newConfig)
          Configure the service.
 Cache createCache(String cacheName, boolean ordered)
          Creates a cache defined by whether the cache is to be ordered, it's name and it's maximum size.
 Cache createCache(String cacheName, boolean ordered, int maxSize)
          Creates a cache as specified by the parameters listed.
 void destroy()
          Called upon destruction of the service.
 void displayStatus()
          Displays the cache status.
 boolean existsCache(String cacheName)
          Checks to see if the cache already exists.
 Set getAllCacheNames()
          Return an iterator over a list of Strings that contain all the names of the caches stored in the system [For dbContext default]
 Cache getCache(String cacheName)
          Retrieve a given cache by name.
 Cacheable getItem(String cacheName, String valueKey)
          Get a particular item in the cache
 int getItemCount(String cacheName)
          Return a count of the number of items in a cache.
 List getItems(String cacheName)
          Return all of the items in a cache.
 void initialize()
          Initialize the component, this is called before the component receives any configuration information.
 void put(String cacheName, Cacheable newItem)
          Adds a Cacheable item into the cache without clearing related caches.
 void put(String cacheName, Cacheable newItem, long expiry)
          Adds a Cacheable item into the cache without clearing related caches.
 void reconfigure(Configuration newConfig)
          Reconfigures the service during runtime without having to restart the container.
 void removeItem(String cacheName, Cacheable itemToRemove)
          Removes an item from the cache
 void removeItemNoNotify(String cacheName, Cacheable itemToRemove)
          Removes an item out of the cache without notifying the cache listeners
 void setItems(String cacheName, List itemList)
          Sets a cache to have the particular items specified in itemList.
 void setItems(String cacheName, List itemList, long expiration)
          Sets a cache to have the particular items specified in itemList.
 
Methods inherited from class com.jcorporate.expresso.kernel.ComponentBase
getMetaData, getMetadataLocation, getParent, setMetaData, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCacheManager

public DefaultCacheManager()
Method Detail

getAllCacheNames

public Set getAllCacheNames()
Return an iterator over a list of Strings that contain all the names of the caches stored in the system [For dbContext default]

Specified by:
getAllCacheNames in interface CacheSystem
Returns:
java.util.Iterator

getItem

public Cacheable getItem(String cacheName,
                         String valueKey)
Get a particular item in the cache

Specified by:
getItem in interface CacheSystem
Parameters:
cacheName - The name of the cache
valueKey - The particular item within the cache to get
Returns:
a Cacheable object or null if it doesn't exist in the cache

getItemCount

public int getItemCount(String cacheName)
Return a count of the number of items in a cache. Return 0 if there is no such item

Specified by:
getItemCount in interface CacheSystem
Parameters:
cacheName - The name of the cache
Returns:
an item count or zero if the cache doesn't exist or is empty;

setItems

public void setItems(String cacheName,
                     List itemList)
              throws CacheException
Sets a cache to have the particular items specified in itemList.

Specified by:
setItems in interface CacheSystem
Parameters:
cacheName - The name of the cache
itemList - The items to set into the cache
Throws:
CacheException - if there's an error setting the items.

setItems

public void setItems(String cacheName,
                     List itemList,
                     long expiration)
              throws CacheException
Sets a cache to have the particular items specified in itemList.

Specified by:
setItems in interface CacheSystem
Parameters:
cacheName - The name of the cache
itemList - The items to set into the cache
expiration - the expiration time in milliseconds for the items.
Throws:
CacheException - if there's an error setting the items.

getItems

public List getItems(String cacheName)
Return all of the items in a cache. If the cache was created as an ordered cache, the items will be in the order they were added. If not, they will be in no particular order. If there is no such cache or no items, null will be returned.

Specified by:
getItems in interface CacheSystem
Parameters:
cacheName - The name of the cache to retrieve
Returns:
java.util.List of Cacheable items

addItem

public void addItem(String cacheName,
                    Cacheable newItem)
             throws CacheException
Adds a Cacheable item into the cache

Specified by:
addItem in interface CacheSystem
Parameters:
cacheName - The name of the cache.
newItem - The new item to add to the cache
Throws:
CacheException - upon error inserting into the system

addItem

public void addItem(String cacheName,
                    Cacheable newItem,
                    long expiry)
             throws CacheException
Adds an item to the cache named by parameter cacheName

Specified by:
addItem in interface CacheSystem
Parameters:
cacheName - The name of the cache to store the object in
newItem - The new item to add to the cache
expiry - The time in miliseconds that this cache item will expire
Throws:
CacheException - if there's an error inserting the item into the cache

put

public void put(String cacheName,
                Cacheable newItem)
         throws CacheException
Adds a Cacheable item into the cache without clearing related caches. This is to differentiate between 'changed' items that are added to the cache via addItem that would require related caches to be cleared to maintain data integrity.

Specified by:
put in interface CacheSystem
Parameters:
cacheName - the name of the cache to add to
newItem - the item to add
Throws:
CacheException - upon error putting the item into the cache

put

public void put(String cacheName,
                Cacheable newItem,
                long expiry)
         throws CacheException
Adds a Cacheable item into the cache without clearing related caches. This is to differentiate between 'changed' items that are added to the cache via addItem that would require related caches to be cleared to maintain data integrity.

Specified by:
put in interface CacheSystem
Parameters:
cacheName - the name of the cache to add to
newItem - the item to add
expiry - The time in miliseconds that this cache item will expire
Throws:
CacheException - upon error putting the item into the cache

addListener

public void addListener(String listener,
                        String listenTo)
Specify a relationship between caches. Whenever an add clear or remove event is sent to the specified cache, the listener is cleared as well. Adding a listener implies the relationship between the caches for the current db context.

Specified by:
addListener in interface CacheSystem
Parameters:
listener - The classname of the listener
listenTo - The name of the cache to listen to.

adjustForMemory

public void adjustForMemory()
Instructs the cache system to adjust it's usage profile based upon current memory information that the expresso system is telling us.

Specified by:
adjustForMemory in interface CacheSystem

clear

public void clear(String cacheName)
           throws CacheException
Clear's the named cache.

Specified by:
clear in interface CacheSystem
Parameters:
cacheName - The name of the cache to clear
Throws:
CacheException - if there's an error clearing the cache.

clear

public void clear()
           throws CacheException
Removes all cache items for a particular data context

Specified by:
clear in interface CacheSystem
Throws:
CacheException - CacheException if there's an error clearing the cache

clearNoNotify

public void clearNoNotify()
Clears all caches in this db context but doesn't notify any listeners

Specified by:
clearNoNotify in interface CacheSystem

clearNoNotify

public void clearNoNotify(String cacheName)
Clear the named cache, but don't send the remote system notifications. This method actually removes the cache from the list of available caches

Specified by:
clearNoNotify in interface CacheSystem
Parameters:
cacheName - The name of the cache

createCache

public Cache createCache(String cacheName,
                         boolean ordered,
                         int maxSize)
                  throws CacheException
Creates a cache as specified by the parameters listed. Creation date: (9/7/00 2:18:09 PM)

Specified by:
createCache in interface CacheSystem
Parameters:
cacheName - java.lang.String the name of the cache
ordered - boolean true if you want an ordered cache such as for ValidValues
maxSize - the maximum size of the cache (zero if boundless)
Returns:
the newly instantiated Cache
Throws:
CacheException

createCache

public Cache createCache(String cacheName,
                         boolean ordered)
                  throws CacheException
Creates a cache defined by whether the cache is to be ordered, it's name and it's maximum size. Creation date: (9/7/00 2:18:09 PM)

Specified by:
createCache in interface CacheSystem
Parameters:
cacheName - java.lang.String The name of the cache
ordered - boolean True if you wish for an ordered cache.
Returns:
the newly instantiated cache
Throws:
CacheException

existsCache

public boolean existsCache(String cacheName)
Checks to see if the cache already exists. One big note about this is that unless you already have a ReadLock, the cache may or may not exist once you go to put your data in the cache. Buyer beware.

Specified by:
existsCache in interface CacheSystem
Parameters:
cacheName - The name of the cache
Returns:
true if the named cache already exists in this data context

getCache

public Cache getCache(String cacheName)
Retrieve a given cache by name.

Specified by:
getCache in interface CacheSystem
Parameters:
cacheName - the name of the cache to retrieve.
Returns:
a Cache instance or null if the Cache does not exist.
See Also:
Cache

removeItem

public void removeItem(String cacheName,
                       Cacheable itemToRemove)
                throws CacheException
Removes an item from the cache

Specified by:
removeItem in interface CacheSystem
Parameters:
cacheName - The name of the cache
itemToRemove - the key of the item to remove
Throws:
CacheException

removeItemNoNotify

public void removeItemNoNotify(String cacheName,
                               Cacheable itemToRemove)
                        throws CacheException
Removes an item out of the cache without notifying the cache listeners

Specified by:
removeItemNoNotify in interface CacheSystem
Parameters:
cacheName - The cache name
itemToRemove - the key in the cache that has been modified
Throws:
CacheException - Upon error removing the item from the cache

initialize

public void initialize()
Description copied from interface: ComponentLifecycle
Initialize the component, this is called before the component receives any configuration information.

Specified by:
initialize in interface ComponentLifecycle

configure

public void configure(Configuration newConfig)
               throws ConfigurationException
Description copied from interface: ComponentLifecycle
Configure the service. This is where any parameter settings will take place.

Specified by:
configure in interface ComponentLifecycle
Parameters:
newConfig - a read only dynabean containing all the needed configuration.
Throws:
ConfigurationException - if for some reason the Component cannot cope with the configuration sent to it. If this exception is thrown then ZERO reconfiguration takes place. Configure() must be an all or nothing 'transaction'

reconfigure

public void reconfigure(Configuration newConfig)
                 throws ConfigurationException
Description copied from interface: ComponentLifecycle

Reconfigures the service during runtime without having to restart the container.

Reconfigure is done this way vs. bean/property setters because sometimes components need special property setting orders and it is not easily possible to determine what order to set things in. This is the responsibility of the component

reConfigure() should be done in a transactional manner.... by that, we mean that if the reconfiguration fails, the component should revert to its previous state and continue operation

Specified by:
reconfigure in interface ComponentLifecycle
Parameters:
newConfig - a read only dynabean containing all the needed configuration.
Throws:
ConfigurationException - if for some reason the Component cannot cope with the configuration sent to it. If this exception is thrown then ZERO reconfiguration takes place. Configure() must be an all or nothing 'transaction'

destroy

public void destroy()
Description copied from interface: ComponentLifecycle
Called upon destruction of the service. This may or may not have anything to do with container shutdown or reloading.

Specified by:
destroy in interface ComponentLifecycle

checkMemory

public void checkMemory()

Checks to make sure that there is enough memory available to use for more caches. If it there isn't enough free memory, then it attempts to clear out the least used cache.

Creation date: (9/7/00 2:44:05 PM)


clearLowestCache

public boolean clearLowestCache()
Removed the least used Cache

Returns:
true if something was able to be removed; false otherwise

displayStatus

public void displayStatus()
Displays the cache status. Currently this is only really used for debugging purposes. Creation date: (9/7/00 2:44:05 PM)

Specified by:
displayStatus in interface CacheSystem

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.