org.aspectj.weaver.tools.cache
Class AsynchronousFileCacheBacking
java.lang.Object
org.aspectj.weaver.tools.cache.AbstractCacheBacking
org.aspectj.weaver.tools.cache.AbstractFileCacheBacking
org.aspectj.weaver.tools.cache.AbstractIndexedFileCacheBacking
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.AsyncCommand
s
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 in-memory cache is updated so that subsequent calls to
#get(CachedClassReference)
will not return the mapped value.
-
An "update index"
AsynchronousFileCacheBacking.AsyncCommand
is posted to the background
thread so that the newly mapped value will be persisted (eventually)
The actual persistence is implemented by the concrete classes
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
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
AsynchronousFileCacheBacking
protected AsynchronousFileCacheBacking(java.io.File cacheDir)
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 retrieveoriginalBytes
- 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 entryoriginalBytes
- 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)