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 controls the flow of items through the cache. The auxiliary and memory caches are plugged in here.

This is the core of a JCS region.

Version:
$Id: CompositeCache.java,v 1.26 2005/06/11 00:35:27 asmuts Exp $
See Also:
Serialized Form

Field Summary
 IElementAttributes attr
          Region Elemental Attributes, default
 ICompositeCacheAttributes cacheAttr
          Cache Attributes, for hub and memory auxiliary
static IElementEventQueue elementEventQ
          EventQueue for handling element events.
 
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
 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)
          Look in memory, then disk, remote, or laterally for this item.
 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.
 ICacheStats getStatistics()
          This returns data gathered for this region and all the auxiliaries it currently uses.
 java.lang.String getStats()
          Gets stats for debugging.
 int getStatus()
          Gets the status attribute of the Cache object
 ICacheElement localGet(java.io.Serializable key)
          Do not try to go remote or laterally for this get.
 boolean localRemove(java.io.Serializable key)
          Do not propogate removeall laterally or remotely.
 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)
          This sets the list of auxiliary caches for this region.
 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)
          Put an item into the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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.


attr

public IElementAttributes attr
Region Elemental Attributes, default


cacheAttr

public ICompositeCacheAttributes cacheAttr
Cache Attributes, for hub and memory auxiliary

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)
This sets the list of auxiliary caches for this region.

Parameters:
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
Put an item into the cache. If it is localOnly, then do no notify remote or lateral auxiliaries.

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

localGet

public ICacheElement localGet(java.io.Serializable key)
Do not try to go remote or laterally for this get.

Parameters:
key -
Returns:
ICacheElement

get

protected ICacheElement get(java.io.Serializable key,
                            boolean localOnly)
Look in memory, then disk, remote, or laterally for this item. The order is dependent on the order in the cache.ccf file.

Do not try to go remote or laterally for this get if it is localOnly. Otherwise try to go remote or lateral if such an auxiliary is configured for this region.

Parameters:
key -
localOnly -
Returns:
ICacheElement

getGroupKeys

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

Parameters:
group -
Returns:
A Set of keys, or null.

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

localRemove

public boolean localRemove(java.io.Serializable key)
Do not propogate removeall laterally or remotely.

Parameters:
key -
Returns:
true if the item was already in the cache.

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:
true if the item was in the cache, else false

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

localRemoveAll

public void localRemoveAll()
                    throws java.io.IOException
Throws:
java.io.IOException

removeAll

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

Parameters:
localOnly -
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. This return the number of elements, not the byte size.

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

getStats

public java.lang.String getStats()
Gets stats for debugging.

Specified by:
getStats in interface ICache
Returns:
String

getStatistics

public ICacheStats getStatistics()
This returns data gathered for this region and all the auxiliaries it currently uses.

Returns:
Statistics and Info on the Region.

getCacheName

public java.lang.String getCacheName()
Gets the cacheName attribute of the Cache object. This is also known as the region name.

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

Parameters:
attr -

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

getMemoryCache

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

Returns:
the MemoryCache implementation

getHitCountRam

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

Returns:
number of hits in memory

getHitCountAux

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

Returns:
number of auxiliary hits.

getMissCountNotFound

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

Returns:
number of misses.

getMissCountExpired

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

Returns:
number of found but expired gets.

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


Copyright © 2002-2005 Apache Software Foundation. All Rights Reserved.