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.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, 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.AsyncCommand
is posted to the background thread so that the newly mapped value will be persisted (eventually)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static interface
Represents an asynchronous command that can be sent to theAsynchronousFileCacheBacking
instance to be executed on it asynchronouslystatic interface
AsynchronousFileCacheBacking.AsynchronousFileCacheBackingCreator<T extends AsynchronousFileCacheBacking>
static class
static class
static class
Base class forAsynchronousFileCacheBacking.AbstractCommand
s that refer to a cache keystatic class
static class
Nested classes/interfaces inherited from class org.aspectj.weaver.tools.cache.AbstractIndexedFileCacheBacking
AbstractIndexedFileCacheBacking.IndexEntry
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map
<String, AbstractIndexedFileCacheBacking.IndexEntry> protected final Map
<String, AbstractIndexedFileCacheBacking.IndexEntry> 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the entire cacheprotected static final <T extends AsynchronousFileCacheBacking>
TcreateBacking
(File cacheDir, AsynchronousFileCacheBacking.AsynchronousFileCacheBackingCreator<T> creator) protected void
protected void
protected void
protected void
protected void
get
(CachedClassReference ref, byte[] originalBytes) Get a cache entryprotected Map
<String, AbstractIndexedFileCacheBacking.IndexEntry> getIndex()
static final boolean
void
put
(CachedClassEntry entry, byte[] originalBytes) Put an entry in the cachereadClassBytes
(Map<String, AbstractIndexedFileCacheBacking.IndexEntry> indexMap, File cacheDir) void
Remove an entry from the cacheprotected abstract void
removeClassBytes
(String key) Helper forexecuteRemoveCommand(RemoveCommand)
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
-
Field Details
-
index
-
exposedIndex
-
bytesMap
-
exposedBytes
-
-
Constructor Details
-
AsynchronousFileCacheBacking
-
-
Method Details
-
getIndex
- Specified by:
getIndex
in classAbstractIndexedFileCacheBacking
-
get
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
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
-
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
-