org.aspectj.weaver.tools.cache
Class DefaultFileCacheBacking

java.lang.Object
  extended by org.aspectj.weaver.tools.cache.AbstractCacheBacking
      extended by org.aspectj.weaver.tools.cache.AbstractFileCacheBacking
          extended by org.aspectj.weaver.tools.cache.AbstractIndexedFileCacheBacking
              extended by org.aspectj.weaver.tools.cache.DefaultFileCacheBacking
All Implemented Interfaces:
CacheBacking

public class DefaultFileCacheBacking
extends AbstractIndexedFileCacheBacking

Naive File-Backed Class Cache with no expiry or application centric invalidation.

Enabled with the system property, "aj.weaving.cache.dir" If this system property is not set, no caching will be performed.

A CRC checksum is stored alongside the class file to verify the bytes on read. If for some reason there is an error reading either the class or crc file, or if the crc does not match the class data the cache entry is deleted.

An alternate implementation of this could store the class file as a jar/zip directly, which would have the required crc; as a first pass however it is somewhat useful to view these files in expanded form for debugging.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.aspectj.weaver.tools.cache.AbstractIndexedFileCacheBacking
AbstractIndexedFileCacheBacking.IndexEntry
 
Field Summary
 
Fields inherited from class org.aspectj.weaver.tools.cache.AbstractIndexedFileCacheBacking
EMPTY_INDEX, EMPTY_KEYS, INDEX_FILE
 
Fields inherited from class org.aspectj.weaver.tools.cache.AbstractFileCacheBacking
WEAVED_CLASS_CACHE_DIR
 
Fields inherited from class org.aspectj.weaver.tools.cache.AbstractCacheBacking
logger
 
Constructor Summary
protected DefaultFileCacheBacking(java.io.File cacheDir)
           
 
Method Summary
 void clear()
          Clear the entire cache
static DefaultFileCacheBacking createBacking(java.io.File cacheDir)
           
static CacheBacking createBacking(java.lang.String scope)
           
protected  void delete(java.io.File file)
           
 CachedClassEntry get(CachedClassReference ref, byte[] originalBytes)
          Get a cache entry
protected  java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> getIndex()
           
 java.lang.String[] getKeys(java.lang.String regex)
          Return a list of keys which match the given regex.
 void put(CachedClassEntry entry, byte[] originalBytes)
          Put an entry in the cache
protected  byte[] read(java.io.File file, long expectedCRC)
           
protected  java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> readIndex()
           
 void remove(CachedClassReference ref)
          Remove an entry from the cache
protected  AbstractIndexedFileCacheBacking.IndexEntry resolveIndexMapEntry(java.io.File cacheDir, AbstractIndexedFileCacheBacking.IndexEntry ie)
           
protected  long write(java.io.File file, byte[] bytes)
           
protected  void writeIndex()
           
 
Methods inherited from class org.aspectj.weaver.tools.cache.AbstractIndexedFileCacheBacking
createIndexEntry, getIndexFile, readIndex, readIndex, writeIndex, writeIndex, writeIndex, writeIndex
 
Methods inherited from class org.aspectj.weaver.tools.cache.AbstractFileCacheBacking
close, close, getCacheDirectory, writeClassBytes
 
Methods inherited from class org.aspectj.weaver.tools.cache.AbstractCacheBacking
crc
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFileCacheBacking

protected DefaultFileCacheBacking(java.io.File cacheDir)
Method Detail

createBacking

public static final DefaultFileCacheBacking createBacking(java.io.File cacheDir)

getIndex

protected java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> getIndex()
Specified by:
getIndex in class AbstractIndexedFileCacheBacking

resolveIndexMapEntry

protected AbstractIndexedFileCacheBacking.IndexEntry resolveIndexMapEntry(java.io.File cacheDir,
                                                                          AbstractIndexedFileCacheBacking.IndexEntry ie)
Overrides:
resolveIndexMapEntry in class AbstractIndexedFileCacheBacking

readIndex

protected java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> readIndex()
Overrides:
readIndex in class AbstractIndexedFileCacheBacking

writeIndex

protected void writeIndex()
Overrides:
writeIndex in class AbstractIndexedFileCacheBacking

clear

public void clear()
Description copied from interface: CacheBacking
Clear the entire cache


createBacking

public static CacheBacking createBacking(java.lang.String scope)

getKeys

public java.lang.String[] getKeys(java.lang.String regex)
Description copied from interface: CacheBacking
Return a list of keys which match the given regex.

Specified by:
getKeys in interface CacheBacking
Overrides:
getKeys in class AbstractIndexedFileCacheBacking
Returns:

get

public CachedClassEntry get(CachedClassReference ref,
                            byte[] originalBytes)
Description copied from interface: CacheBacking
Get a cache entry

Parameters:
ref - entry to retrieve
originalBytes - Pre-weaving class bytes - required in order to ensure that the cached entry refers to the same original class
Returns:
the cached bytes or null, if the entry does not exist

put

public void put(CachedClassEntry entry,
                byte[] originalBytes)
Description copied from interface: CacheBacking
Put an entry in the cache

Parameters:
entry - key of the entry
originalBytes - Pre-weaving class bytes - required in order to ensure that the cached entry refers to the same original class

remove

public void remove(CachedClassReference ref)
Description copied from interface: CacheBacking
Remove an entry from the cache


delete

protected void delete(java.io.File file)
Overrides:
delete in class AbstractFileCacheBacking

read

protected byte[] read(java.io.File file,
                      long expectedCRC)

write

protected long write(java.io.File file,
                     byte[] bytes)