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
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, byte[]) call, the weaver issues a
put(CachedClassEntry, byte[]) call. This call has 2 side-effects:
-
The in-memory cache is updated so that subsequent calls to
get(CachedClassReference, byte[])will not return the mapped value. -
An "update index"
AsynchronousFileCacheBacking.AsyncCommandis posted to the background thread so that the newly mapped value will be persisted (eventually)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfaceRepresents an asynchronous command that can be sent to theAsynchronousFileCacheBackinginstance to be executed on it asynchronouslystatic interfaceAsynchronousFileCacheBacking.AsynchronousFileCacheBackingCreator<T extends AsynchronousFileCacheBacking>static classstatic classstatic classBase class forAsynchronousFileCacheBacking.AbstractCommands that refer to a cache keystatic classstatic classNested classes/interfaces inherited from class AbstractIndexedFileCacheBacking
AbstractIndexedFileCacheBacking.IndexEntry -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String, AbstractIndexedFileCacheBacking.IndexEntry> protected final Map<String, AbstractIndexedFileCacheBacking.IndexEntry> Fields inherited from class AbstractIndexedFileCacheBacking
EMPTY_INDEX, EMPTY_KEYS, INDEX_FILEFields inherited from class AbstractFileCacheBacking
WEAVED_CLASS_CACHE_DIRFields inherited from class AbstractCacheBacking
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the entire cacheprotected static final <T extends AsynchronousFileCacheBacking>
TcreateBacking(File cacheDir, AsynchronousFileCacheBacking.AsynchronousFileCacheBackingCreator<T> creator) protected voidprotected voidprotected voidprotected voidprotected voidget(CachedClassReference ref, byte[] originalBytes) Get a cache entryprotected Map<String, AbstractIndexedFileCacheBacking.IndexEntry> getIndex()static final booleanvoidput(CachedClassEntry entry, byte[] originalBytes) Put an entry in the cachereadClassBytes(Map<String, AbstractIndexedFileCacheBacking.IndexEntry> indexMap, File cacheDir) voidRemove an entry from the cacheprotected abstract voidremoveClassBytes(String key) Helper forexecuteRemoveCommand(RemoveCommand)toString()Methods inherited from class AbstractIndexedFileCacheBacking
createIndexEntry, getIndexFile, getKeys, readIndex, readIndex, readIndex, resolveIndexMapEntry, writeIndex, writeIndex, writeIndex, writeIndex, writeIndexMethods inherited from class AbstractFileCacheBacking
close, close, delete, getCacheDirectory, writeClassBytesMethods inherited from class AbstractCacheBacking
crc
-
Field Details
-
index
-
exposedIndex
-
bytesMap
-
exposedBytes
-
-
Constructor Details
-
AsynchronousFileCacheBacking
-
-
Method Details
-
getIndex
- Specified by:
getIndexin classAbstractIndexedFileCacheBacking
-
get
Description copied from interface:CacheBackingGet 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
Description copied from interface:CacheBackingPut 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
-
remove
-
getIndexEntries
-
getIndexMap
-
getBytesMap
-
clear
-
executeCommand
- Throws:
Exception
-
executeClearCommand
-
executeUpdateIndexCommand
-
executeInsertCommand
protected void executeInsertCommand(AsynchronousFileCacheBacking.InsertCommand cmd) throws Exception - Throws:
Exception
-
executeRemoveCommand
protected void executeRemoveCommand(AsynchronousFileCacheBacking.RemoveCommand cmd) throws Exception - Throws:
Exception
-
removeClassBytes
Helper forexecuteRemoveCommand(RemoveCommand)- Parameters:
key- The key representing the class whose bytes are to be removed- Throws:
Exception- if failed to remove class bytes
-
readClassBytes
-
toString
-
createBacking
protected static final <T extends AsynchronousFileCacheBacking> T createBacking(File cacheDir, AsynchronousFileCacheBacking.AsynchronousFileCacheBackingCreator<T> creator) -
postCacheCommand
-