org.aspectj.weaver.tools.cache
Class AsynchronousFileCacheBacking

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.AsynchronousFileCacheBacking
All Implemented Interfaces:
CacheBacking
Direct Known Subclasses:
FlatFileCacheBacking, ZippedFileCacheBacking

public abstract class AsynchronousFileCacheBacking
extends AbstractIndexedFileCacheBacking

Uses a background thread to do the actual I/O and for caching "persistence" so that the caching works faster on repeated activations of the application. The class maintains an in-memory cache, and uses a queue of AsynchronousFileCacheBacking.AsyncCommands to signal to a background thread various actions required to "synchronize" the in-memory cache with the persisted copy. Whenever there is a cache miss from the #get(CachedClassReference) call, the weaver issues a #put(CachedClassEntry) call. This call has 2 side-effects:

The actual persistence is implemented by the concrete classes


Nested Class Summary
static class AsynchronousFileCacheBacking.AbstractCommand
           
static interface AsynchronousFileCacheBacking.AsyncCommand
          Represents an asynchronous command that can be sent to the AsynchronousFileCacheBacking instance to be executed on it asynchronously
static interface AsynchronousFileCacheBacking.AsynchronousFileCacheBackingCreator<T extends AsynchronousFileCacheBacking>
           
static class AsynchronousFileCacheBacking.ClearCommand
           
static class AsynchronousFileCacheBacking.InsertCommand
           
static class AsynchronousFileCacheBacking.KeyedCommand
          Base class for AsynchronousFileCacheBacking.AbstractCommands that refer to a cache key
static class AsynchronousFileCacheBacking.RemoveCommand
           
static class AsynchronousFileCacheBacking.UpdateIndexCommand
           
 
Nested classes/interfaces inherited from class org.aspectj.weaver.tools.cache.AbstractIndexedFileCacheBacking
AbstractIndexedFileCacheBacking.IndexEntry
 
Field Summary
protected  java.util.Map<java.lang.String,byte[]> bytesMap
           
protected  java.util.Map<java.lang.String,byte[]> exposedBytes
           
protected  java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> exposedIndex
           
protected  java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> index
           
 
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 AsynchronousFileCacheBacking(java.io.File cacheDir)
           
 
Method Summary
 void clear()
          Clear the entire cache
protected static
<T extends AsynchronousFileCacheBacking>
T
createBacking(java.io.File cacheDir, AsynchronousFileCacheBacking.AsynchronousFileCacheBackingCreator<T> creator)
           
protected  void executeClearCommand()
           
protected  void executeCommand(AsynchronousFileCacheBacking.AsyncCommand cmd)
           
protected  void executeInsertCommand(AsynchronousFileCacheBacking.InsertCommand cmd)
           
protected  void executeRemoveCommand(AsynchronousFileCacheBacking.RemoveCommand cmd)
           
protected  void executeUpdateIndexCommand()
           
 CachedClassEntry get(CachedClassReference ref, byte[] originalBytes)
          Get a cache entry
 java.util.Map<java.lang.String,byte[]> getBytesMap()
           
protected  java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> getIndex()
           
 java.util.List<AbstractIndexedFileCacheBacking.IndexEntry> getIndexEntries()
           
 java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> getIndexMap()
           
static boolean postCacheCommand(AsynchronousFileCacheBacking.AsyncCommand cmd)
           
 void put(CachedClassEntry entry, byte[] originalBytes)
          Put an entry in the cache
protected abstract  java.util.Map<java.lang.String,byte[]> readClassBytes(java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> indexMap, java.io.File cacheDir)
           
 void remove(CachedClassReference ref)
          Remove an entry from the cache
protected  AbstractIndexedFileCacheBacking.IndexEntry remove(java.lang.String key)
           
protected abstract  void removeClassBytes(java.lang.String key)
          Helper for executeRemoveCommand(RemoveCommand)
 java.lang.String toString()
           
 
Methods inherited from class org.aspectj.weaver.tools.cache.AbstractIndexedFileCacheBacking
createIndexEntry, getIndexFile, getKeys, readIndex, readIndex, readIndex, resolveIndexMapEntry, writeIndex, writeIndex, writeIndex, writeIndex, writeIndex
 
Methods inherited from class org.aspectj.weaver.tools.cache.AbstractFileCacheBacking
close, close, delete, 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, wait, wait, wait
 

Field Detail

index

protected final java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> index

exposedIndex

protected final java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> exposedIndex

bytesMap

protected final java.util.Map<java.lang.String,byte[]> bytesMap

exposedBytes

protected final java.util.Map<java.lang.String,byte[]> exposedBytes
Constructor Detail

AsynchronousFileCacheBacking

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

getIndex

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

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


remove

protected AbstractIndexedFileCacheBacking.IndexEntry remove(java.lang.String key)

getIndexEntries

public java.util.List<AbstractIndexedFileCacheBacking.IndexEntry> getIndexEntries()

getIndexMap

public java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> getIndexMap()

getBytesMap

public java.util.Map<java.lang.String,byte[]> getBytesMap()

clear

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


executeCommand

protected void executeCommand(AsynchronousFileCacheBacking.AsyncCommand cmd)
                       throws java.lang.Exception
Throws:
java.lang.Exception

executeClearCommand

protected void executeClearCommand()
                            throws java.lang.Exception
Throws:
java.lang.Exception

executeUpdateIndexCommand

protected void executeUpdateIndexCommand()
                                  throws java.lang.Exception
Throws:
java.lang.Exception

executeInsertCommand

protected void executeInsertCommand(AsynchronousFileCacheBacking.InsertCommand cmd)
                             throws java.lang.Exception
Throws:
java.lang.Exception

executeRemoveCommand

protected void executeRemoveCommand(AsynchronousFileCacheBacking.RemoveCommand cmd)
                             throws java.lang.Exception
Throws:
java.lang.Exception

removeClassBytes

protected abstract void removeClassBytes(java.lang.String key)
                                  throws java.lang.Exception
Helper for executeRemoveCommand(RemoveCommand)

Parameters:
key - The key representing the class whose bytes are to be removed
Throws:
java.lang.Exception - if failed to remove class bytes

readClassBytes

protected abstract java.util.Map<java.lang.String,byte[]> readClassBytes(java.util.Map<java.lang.String,AbstractIndexedFileCacheBacking.IndexEntry> indexMap,
                                                                         java.io.File cacheDir)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

createBacking

protected static final <T extends AsynchronousFileCacheBacking> T createBacking(java.io.File cacheDir,
                                                                                AsynchronousFileCacheBacking.AsynchronousFileCacheBackingCreator<T> creator)

postCacheCommand

public static final boolean postCacheCommand(AsynchronousFileCacheBacking.AsyncCommand cmd)