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

java.lang.Object
  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 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
 void doDispose()
          Dispose of the disk cache in a background thread.
protected  ICacheElement doGet(java.io.Serializable key)
          Gets the ICacheElement for the key if it is in the cache.
protected  boolean doRemove(java.io.Serializable key)
          Returns true if the removal was succesful; or false if there is nothing to remove.
protected  void doRemoveAll()
          Resets the keyfile, the disk file, and the memory key map.
protected  void doUpdate(ICacheElement element)
          Writes an element to disk.
protected  void freeBlocks(int[] blocksToFree)
          Add these blocks to the emptyBlock list.
 AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
          Returns the attributes.
 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.
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, get, getCacheName, getCacheType, getStatus, remove, removeAll, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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)

getSize

public int getSize()
Returns the number of keys.

(non-Javadoc)

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

doGet

protected ICacheElement doGet(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:
doGet in class AbstractDiskCache
Parameters:
key - Key to locate value for.
Returns:
An object matching key, or null.
See Also:
AbstractDiskCache.doGet(java.io.Serializable)

doUpdate

protected void doUpdate(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:
doUpdate in class AbstractDiskCache
See Also:
AbstractDiskCache.doUpdate(org.apache.jcs.engine.behavior.ICacheElement)

doRemove

protected boolean doRemove(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:
doRemove in class AbstractDiskCache
Parameters:
key - Key of object to remove.
Returns:
whether or no the item was present when removed
See Also:
AbstractDiskCache.doRemove(java.io.Serializable)

doRemoveAll

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

(non-Javadoc)

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

doDispose

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

Specified by:
doDispose in class AbstractDiskCache

getAuxiliaryCacheAttributes

public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
Returns the attributes.

(non-Javadoc)

Returns:
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:
See Also:
AuxiliaryCache.getStatistics()


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