org.apache.jcs.auxiliary.disk.block
Class BlockDiskCache

java.lang.Object
  extended by org.apache.jcs.auxiliary.AbstractAuxiliaryCache
      extended by org.apache.jcs.auxiliary.AbstractAuxiliaryCacheEventLogging
          extended by org.apache.jcs.auxiliary.disk.AbstractDiskCache
              extended by org.apache.jcs.auxiliary.disk.block.BlockDiskCache
All Implemented Interfaces:
java.io.Serializable, AuxiliaryCache, ICache, ICacheType

public class BlockDiskCache
extends AbstractDiskCache

There is one BlockDiskCache per region. It manages the key and data store.

Author:
Aaron Smuts
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache
alive, cacheEventQueue, cacheName, purgatory, purgHits
 
Fields inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache
cacheEventLogger, elementSerializer, keyMatcher
 
Fields inherited from interface org.apache.jcs.engine.behavior.ICacheType
CACHE_HUB, DISK_CACHE, LATERAL_CACHE, REMOTE_CACHE
 
Constructor Summary
BlockDiskCache(BlockDiskCacheAttributes cacheAttributes)
          Constructs the BlockDisk after setting up the root directory.
 
Method Summary
protected  void freeBlocks(int[] blocksToFree)
          Add these blocks to the emptyBlock list.
 AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
          Returns the attributes.
protected  java.lang.String getDiskLocation()
          This is used by the event logging.
 java.util.Set getGroupKeys(java.lang.String groupName)
          This requires a full iteration through the keys.
 int getSize()
          Returns the number of keys.
 IStats getStatistics()
          Returns info about the disk cache.
 java.lang.String getStats()
          Gets basic stats for the disk cache.
 void processDispose()
          Dispose of the disk cache in a background thread.
protected  ICacheElement processGet(java.io.Serializable key)
          Gets the ICacheElement for the key if it is in the cache.
 java.util.Map processGetMatching(java.lang.String pattern)
          Gets matching items from the cache.
protected  boolean processRemove(java.io.Serializable key)
          Returns true if the removal was succesful; or false if there is nothing to remove.
protected  void processRemoveAll()
          Resets the keyfile, the disk file, and the memory key map.
protected  void processUpdate(ICacheElement element)
          Writes an element to disk.
protected  boolean verifyDisk()
          We need to verify that the file on disk uses the same block size and that the file is the proper size.
 
Methods inherited from class org.apache.jcs.auxiliary.disk.AbstractDiskCache
dispose, doDispose, doGet, doGetMatching, doRemove, doRemoveAll, doUpdate, get, getCacheName, getCacheType, getEventLoggingExtraInfo, getMatching, getStatus, processGetMultiple, remove, removeAll, update
 
Methods inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCacheEventLogging
disposeWithEventLogging, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, removeAllWithEventLogging, removeWithEventLogging, updateWithEventLogging
 
Methods inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache
createICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, setCacheEventLogger, setElementSerializer, setKeyMatcher
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.jcs.auxiliary.AuxiliaryCache
setCacheEventLogger, setElementSerializer
 
Methods inherited from interface org.apache.jcs.engine.behavior.ICache
getMultiple, setKeyMatcher
 

Constructor Detail

BlockDiskCache

public BlockDiskCache(BlockDiskCacheAttributes cacheAttributes)
Constructs the BlockDisk after setting up the root directory.

Parameters:
cacheAttributes -
Method Detail

verifyDisk

protected boolean verifyDisk()
We need to verify that the file on disk uses the same block size and that the file is the proper size.

Returns:
true if it looks ok

getGroupKeys

public java.util.Set getGroupKeys(java.lang.String groupName)
This requires a full iteration through the keys.

(non-Javadoc)

Specified by:
getGroupKeys in interface AuxiliaryCache
Specified by:
getGroupKeys in class AbstractDiskCache
Returns:
a set of group keys
See Also:
AbstractDiskCache.getGroupKeys(java.lang.String)

processGetMatching

public java.util.Map processGetMatching(java.lang.String pattern)
Gets matching items from the cache.

Specified by:
processGetMatching in class AbstractAuxiliaryCacheEventLogging
Parameters:
pattern -
Returns:
a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache matching keys

getSize

public int getSize()
Returns the number of keys.

(non-Javadoc)

Specified by:
getSize in interface ICache
Specified by:
getSize in class AbstractDiskCache
Returns:
the number of items.
See Also:
AbstractDiskCache.getSize()

processGet

protected ICacheElement processGet(java.io.Serializable key)
Gets the ICacheElement for the key if it is in the cache. The program flow is as follows:
  1. Make sure the disk cache is alive.
  2. Get a read lock.
  3. See if the key is in the key store.
  4. If we found a key, ask the BlockDisk for the object at the blocks..
  5. Release the lock.
(non-Javadoc)

Specified by:
processGet in class AbstractAuxiliaryCacheEventLogging
Parameters:
key -
Returns:
ICacheElement
See Also:
AbstractDiskCache.doGet(java.io.Serializable)

processUpdate

protected void processUpdate(ICacheElement element)
Writes an element to disk. The program flow is as follows:
  1. Aquire write lock.
  2. See id an item exists for this key.
  3. If an itme already exists, add its blocks to the remove list.
  4. Have the Block disk write the item.
  5. Create a descriptor and add it to the key map.
  6. Release the write lock.
(non-Javadoc)

Specified by:
processUpdate in class AbstractAuxiliaryCacheEventLogging
Parameters:
element -
See Also:
AbstractDiskCache.doUpdate(org.apache.jcs.engine.behavior.ICacheElement)

processRemove

protected boolean processRemove(java.io.Serializable key)
Returns true if the removal was succesful; or false if there is nothing to remove. Current implementation always result in a disk orphan.

(non-Javadoc)

Specified by:
processRemove in class AbstractAuxiliaryCacheEventLogging
Parameters:
key -
Returns:
true if removed anything
See Also:
AbstractDiskCache.doRemove(java.io.Serializable)

processRemoveAll

protected void processRemoveAll()
Resets the keyfile, the disk file, and the memory key map.

(non-Javadoc)

Specified by:
processRemoveAll in class AbstractAuxiliaryCacheEventLogging
See Also:
AbstractDiskCache.doRemoveAll()

processDispose

public void processDispose()
Dispose of the disk cache in a background thread. Joins against this thread to put a cap on the disposal time.

TODO make dispose window configurable.

Specified by:
processDispose in class AbstractAuxiliaryCacheEventLogging

getAuxiliaryCacheAttributes

public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
Returns the attributes.

(non-Javadoc)

Returns:
the attributes for the auxiliary cache
See Also:
AuxiliaryCache.getAuxiliaryCacheAttributes()

freeBlocks

protected void freeBlocks(int[] blocksToFree)
Add these blocks to the emptyBlock list.

Parameters:
blocksToFree -

getStats

public java.lang.String getStats()
Gets basic stats for the disk cache.

Specified by:
getStats in interface ICache
Overrides:
getStats in class AbstractDiskCache
Returns:
String

getStatistics

public IStats getStatistics()
Returns info about the disk cache.

(non-Javadoc)

Specified by:
getStatistics in interface AuxiliaryCache
Overrides:
getStatistics in class AbstractDiskCache
Returns:
the historical and statistical data for a region's auxiliary cache.
See Also:
AuxiliaryCache.getStatistics()

getDiskLocation

protected java.lang.String getDiskLocation()
This is used by the event logging.

Specified by:
getDiskLocation in class AbstractDiskCache
Returns:
the location of the disk, either path or ip.


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