org.apache.jcs.engine.control
Class CompositeCache

java.lang.Object
  extended byorg.apache.jcs.engine.control.CompositeCache
All Implemented Interfaces:
ICache, ICacheType, java.io.Serializable

public class CompositeCache
extends java.lang.Object
implements ICache, java.io.Serializable

This is the primary hub for a single cache/region. It control the flow of items through the cache. The auxiliary and memory caches are plugged in here.

Version:
$Id: CompositeCache.java,v 1.10 2003/11/17 21:49:28 asmuts Exp $
Author:
Aaron Smuts, James Taylor
See Also:
Serialized Form

Field Summary
private  boolean alive
           
 IElementAttributes attr
          Region Elemental Attributes, default
private  AuxiliaryCache[] auxCaches
           
private  int[] auxHitCountByIndex
          Auxiliary hit counts broken down by auxiliary
 ICompositeCacheAttributes cacheAttr
          Cache Attributes, for hub and memory auxiliary
(package private)  java.lang.String cacheName
           
static IElementEventQueue elementEventQ
          EventQueue for handling element events.
private  int hitCountAux
          Auxiliary cache hit count (number of times found in ANY auxiliary)
private  int hitCountRam
          Memory cache hit count
private static org.apache.commons.logging.Log log
           
(package private)  MemoryCache memCache
          The cache hub can only have one memory cache.
private  int missCountExpired
          Count of misses where element was expired
private  int missCountNotFound
          Count of misses where element was not found
 
Fields inherited from interface org.apache.jcs.engine.behavior.ICacheType
CACHE_HUB, DISK_CACHE, LATERAL_CACHE, REMOTE_CACHE
 
Constructor Summary
CompositeCache(java.lang.String cacheName, ICompositeCacheAttributes cattr, IElementAttributes attr)
          Constructor for the Cache object
 
Method Summary
 void addElementEvent(IElementEventHandler hand, IElementEvent event)
          Adds an ElementEvent to be handled
private  void createMemoryCache(ICompositeCacheAttributes cattr)
          Create the MemoryCache based on the config parameters.
 void dispose()
          Flushes all cache items from memory to auxilliary caches and close the auxilliary caches.
protected  void dispose(boolean fromRemote)
          invoked only by CacheManager.
 ICacheElement get(java.io.Serializable key)
          Gets an item from the cache.
protected  ICacheElement get(java.io.Serializable key, boolean localOnly)
          Description of the Method
 ICompositeCacheAttributes getCacheAttributes()
          Gets the ICompositeCacheAttributes attribute of the Cache object
 java.lang.String getCacheName()
          Gets the cacheName attribute of the Cache object
 int getCacheType()
          Gets the cacheType attribute of the Cache object
 IElementAttributes getElementAttributes()
          Gets the default element attribute of the Cache object Should this return a copy?
 IElementAttributes getElementAttributes(java.io.Serializable key)
          Gets the elementAttributes attribute of the Cache object
 java.util.Set getGroupKeys(java.lang.String group)
          Gets the set of keys of objects currently in the group
 int getHitCountAux()
          Number of times a requested item was found in and auxiliary cache
 int getHitCountRam()
          Number of times a requested item was found in the memory cache
 MemoryCache getMemoryCache()
          Access to the memory cache for instrumentation.
 int getMissCountExpired()
          Number of times a requested element was found but was expired
 int getMissCountNotFound()
          Number of times a requested element was not found
 int getSize()
          Gets the size attribute of the Cache object
 int getStatus()
          Gets the status attribute of the Cache object
private  boolean isExpired(ICacheElement element)
           
 ICacheElement localGet(java.io.Serializable key)
           
 boolean localRemove(java.io.Serializable key)
           
 void localRemoveAll()
           
 void localUpdate(ICacheElement ce)
          Standard update method
 boolean remove(java.io.Serializable key)
          Removes an item from the cache.
protected  boolean remove(java.io.Serializable key, boolean localOnly)
          fromRemote: If a remove call was made on a cache with both, then the remote should have been called.
 void removeAll()
          Removes all cached items from the cache.
protected  void removeAll(boolean localOnly)
          Removes all cached items.
 void save()
          Though this put is extremely fast, this could bog the cache and should be avoided.
 void setAuxCaches(AuxiliaryCache[] auxCaches)
           
 void setCacheAttributes(ICompositeCacheAttributes cattr)
          Sets the ICompositeCacheAttributes attribute of the Cache object
 void setElementAttributes(IElementAttributes attr)
          Sets the default element attribute of the Cache object
 void spoolToDisk(ICacheElement ce)
          Writes the specified element to any disk auxilliaries Might want to rename this "overflow" incase the hub wants to do something else.
 void update(ICacheElement ce)
          Standard update method
protected  void update(ICacheElement ce, boolean localOnly)
          Description of the Method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

elementEventQ

public static IElementEventQueue elementEventQ
EventQueue for handling element events. 1 should be enough for all the regions. Else should create as needed per region.


auxCaches

private AuxiliaryCache[] auxCaches

alive

private boolean alive

cacheName

final java.lang.String cacheName

attr

public IElementAttributes attr
Region Elemental Attributes, default


cacheAttr

public ICompositeCacheAttributes cacheAttr
Cache Attributes, for hub and memory auxiliary


hitCountRam

private int hitCountRam
Memory cache hit count


hitCountAux

private int hitCountAux
Auxiliary cache hit count (number of times found in ANY auxiliary)


auxHitCountByIndex

private int[] auxHitCountByIndex
Auxiliary hit counts broken down by auxiliary


missCountNotFound

private int missCountNotFound
Count of misses where element was not found


missCountExpired

private int missCountExpired
Count of misses where element was expired


memCache

MemoryCache memCache
The cache hub can only have one memory cache. This could be made more flexible in the future, but they are tied closely together. More than one doesn't make much sense.

Constructor Detail

CompositeCache

public CompositeCache(java.lang.String cacheName,
                      ICompositeCacheAttributes cattr,
                      IElementAttributes attr)
Constructor for the Cache object

Parameters:
cacheName - The name of the region
cattr - The cache attribute
attr - The default element attributes
Method Detail

setAuxCaches

public void setAuxCaches(AuxiliaryCache[] auxCaches)

update

public void update(ICacheElement ce)
            throws java.io.IOException
Standard update method

Specified by:
update in interface ICache
Parameters:
ce -
Throws:
java.io.IOException

localUpdate

public void localUpdate(ICacheElement ce)
                 throws java.io.IOException
Standard update method

Parameters:
ce -
Throws:
java.io.IOException

update

protected void update(ICacheElement ce,
                      boolean localOnly)
               throws java.io.IOException
Description of the Method

Parameters:
ce -
Throws:
java.io.IOException

spoolToDisk

public void spoolToDisk(ICacheElement ce)
Writes the specified element to any disk auxilliaries Might want to rename this "overflow" incase the hub wants to do something else.

Parameters:
ce - The CacheElement

get

public ICacheElement get(java.io.Serializable key)
Description copied from interface: ICache
Gets an item from the cache.

Specified by:
get in interface ICache
See Also:
ICache.get(java.io.Serializable)

localGet

public ICacheElement localGet(java.io.Serializable key)
See Also:
ICompositeCache#localGet

get

protected ICacheElement get(java.io.Serializable key,
                            boolean localOnly)
Description of the Method

Parameters:
key -
localOnly -
Returns:

isExpired

private boolean isExpired(ICacheElement element)

getGroupKeys

public java.util.Set getGroupKeys(java.lang.String group)
Gets the set of keys of objects currently in the group


remove

public boolean remove(java.io.Serializable key)
Description copied from interface: ICache
Removes an item from the cache.

Specified by:
remove in interface ICache
See Also:
ICache.remove(java.io.Serializable)

localRemove

public boolean localRemove(java.io.Serializable key)
See Also:
ICompositeCache#localRemove

remove

protected boolean remove(java.io.Serializable key,
                         boolean localOnly)
fromRemote: If a remove call was made on a cache with both, then the remote should have been called. If it wasn't then the remote is down. we'll assume it is down for all. If it did come from the remote then the caceh is remotely configured and lateral removal is unncessary. If it came laterally then lateral removal is unnecessary. Does this assumes that there is only one lateral and remote for the cache? Not really, the intial removal should take care of the problem if the source cache was similiarly configured. Otherwise the remote cache, if it had no laterals, would remove all the elements from remotely configured caches, but if those caches had some other wierd laterals that were not remotely configured, only laterally propagated then they would go out of synch. The same could happen for multiple remotes. If this looks necessary we will need to build in an identifier to specify the source of a removal.

Parameters:
key -
localOnly -
Returns:

removeAll

public void removeAll()
               throws java.io.IOException
Description copied from interface: ICache
Removes all cached items from the cache.

Specified by:
removeAll in interface ICache
Throws:
java.io.IOException
See Also:
ICache.removeAll()

localRemoveAll

public void localRemoveAll()
                    throws java.io.IOException
Throws:
java.io.IOException
See Also:
ICompositeCache#removeAll

removeAll

protected void removeAll(boolean localOnly)
                  throws java.io.IOException
Removes all cached items.

Throws:
java.io.IOException

dispose

public void dispose()
Flushes all cache items from memory to auxilliary caches and close the auxilliary caches.

Specified by:
dispose in interface ICache

dispose

protected void dispose(boolean fromRemote)
invoked only by CacheManager.

Parameters:
fromRemote -

save

public void save()
Though this put is extremely fast, this could bog the cache and should be avoided. The dispose method should call a version of this. Good for testing.


getSize

public int getSize()
Gets the size attribute of the Cache object

Specified by:
getSize in interface ICache
Returns:
The size value

getCacheType

public int getCacheType()
Gets the cacheType attribute of the Cache object

Specified by:
getCacheType in interface ICacheType
Returns:
The cacheType value

getStatus

public int getStatus()
Gets the status attribute of the Cache object

Specified by:
getStatus in interface ICache
Returns:
The status value

getCacheName

public java.lang.String getCacheName()
Gets the cacheName attribute of the Cache object

Specified by:
getCacheName in interface ICache
Returns:
The cacheName value

getElementAttributes

public IElementAttributes getElementAttributes()
Gets the default element attribute of the Cache object Should this return a copy?

Returns:
The attributes value

setElementAttributes

public void setElementAttributes(IElementAttributes attr)
Sets the default element attribute of the Cache object

Returns:
The attributes value

getCacheAttributes

public ICompositeCacheAttributes getCacheAttributes()
Gets the ICompositeCacheAttributes attribute of the Cache object

Returns:
The ICompositeCacheAttributes value

setCacheAttributes

public void setCacheAttributes(ICompositeCacheAttributes cattr)
Sets the ICompositeCacheAttributes attribute of the Cache object

Parameters:
cattr - The new ICompositeCacheAttributes value

getElementAttributes

public IElementAttributes getElementAttributes(java.io.Serializable key)
                                        throws CacheException,
                                               java.io.IOException
Gets the elementAttributes attribute of the Cache object

Parameters:
key -
Returns:
The elementAttributes value
Throws:
CacheException
java.io.IOException

addElementEvent

public void addElementEvent(IElementEventHandler hand,
                            IElementEvent event)
                     throws java.io.IOException
Adds an ElementEvent to be handled

Parameters:
hand - The IElementEventHandler
event - The IElementEventHandler IElementEvent event
Throws:
java.io.IOException - Description of the Exception

createMemoryCache

private void createMemoryCache(ICompositeCacheAttributes cattr)
Create the MemoryCache based on the config parameters. TODO: consider making this an auxiliary, despite its close tie to the CacheHub. TODO: might want to create a memory cache config file separate from that of the hub -- ICompositeCacheAttributes

Parameters:
cattr -

getMemoryCache

public MemoryCache getMemoryCache()
Access to the memory cache for instrumentation.


getHitCountRam

public int getHitCountRam()
Number of times a requested item was found in the memory cache


getHitCountAux

public int getHitCountAux()
Number of times a requested item was found in and auxiliary cache


getMissCountNotFound

public int getMissCountNotFound()
Number of times a requested element was not found


getMissCountExpired

public int getMissCountExpired()
Number of times a requested element was found but was expired