Klasse WeavedClassCache
To enable the default configuration two system properties must be set:
"-Daj.weaving.cache.enabled=true" "-Daj.weaving.cache.dir=/some/directory"
The class cache is often something that application developers or containers would like to manage, so there are a few interfaces for overriding the default behavior and performing other management functions.
CacheBacking
Provides an interface for implementing a custom backing store for the cache; The default implementation in
DefaultFileCacheBacking
provides a naive file-backed cache. An alternate implementation may ignore
caching until signaled explicitly by the application, or only cache files
for a specific duration. This class delegates the locking and synchronization
requirements to the CacheBacking implementation.
CacheKeyResolver
Provides methods for creating keys from classes to be cached and for
creating the "scope" of the cache itself for a given classloader and aspect
list. The default implementation is provided by DefaultCacheKeyResolver
but an alternate implementation may want to associate a cache with a particular
application running underneath a container.
This naive cache does not normally invalidate *any* classes; the interfaces above must be used to implement more intelligent behavior. Cache invalidation problems may occur in at least three scenarios:
- New aspects are added dynamically somewhere in the classloader hierarchy; affecting other classes elsewhere.
- Use of declare parent in aspects to change the type hierarchy; if the cache has not invalidated the right classes in the type hierarchy aspectj may not be reconstruct the class incorrectly.
- Similarly to (2), the addition of fields or methods on classes which have already been weaved and cached could have inter-type conflicts.
-
Feldübersicht
-
Konstruktorübersicht
ModifiziererKonstruktorBeschreibungprotected
WeavedClassCache
(GeneratedClassHandler existingClassHandler, IMessageHandler messageHandler, String name, CacheBacking backing, CacheKeyResolver resolver) -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
clear()
Clear the entire cachestatic WeavedClassCache
createCache
(ClassLoader loader, List<String> aspects, GeneratedClassHandler existingClassHandler, IMessageHandler messageHandler) Creates a new cache using the resolver and backing returned by the DefaultCacheFactory.createCacheKey
(String className, byte[] originalBytes) Create a key for a normal weaved classcreateGeneratedCacheKey
(String className) Created a key for a generated classprotected void
protected void
get
(CachedClassReference ref, byte[] classBytes) Get a cache valuestatic List<WeavedClassCache>
Return a list of all WeavedClassCaches which have been initializedReturns a generated class handler which wraps the handler this cache was initialized with; this handler should be used to make sure that generated classes are added to the cachegetName()
getStats()
Get the statistics associated with this cache, or null if statistics have not been enabled.void
ignore
(CachedClassReference ref, byte[] classBytes) Put a cache entry to indicate that the class should not be weaved; the original bytes of the class should be used.protected void
static boolean
Has caching been enabled through the System property, WEAVED_CLASS_CACHE_ENABLEDvoid
put
(CachedClassReference ref, byte[] classBytes, byte[] weavedBytes) Put a class in the cachevoid
Invalidate a cache entrystatic void
setDefaultCacheFactory
(CacheFactory factory) The Cache and be extended in two ways, through a specialized CacheKeyResolver and a specialized CacheBacking.
-
Felddetails
-
WEAVED_CLASS_CACHE_ENABLED
- Siehe auch:
-
CACHE_IMPL
- Siehe auch:
-
ZERO_BYTES
public static final byte[] ZERO_BYTES
-
-
Konstruktordetails
-
WeavedClassCache
protected WeavedClassCache(GeneratedClassHandler existingClassHandler, IMessageHandler messageHandler, String name, CacheBacking backing, CacheKeyResolver resolver)
-
-
Methodendetails
-
createCache
public static WeavedClassCache createCache(ClassLoader loader, List<String> aspects, GeneratedClassHandler existingClassHandler, IMessageHandler messageHandler) Creates a new cache using the resolver and backing returned by the DefaultCacheFactory.- Parameter:
loader
- classloader for this cacheaspects
- list of aspects used by the WeavingAdapterexistingClassHandler
- the existing GeneratedClassHandler used by the weavermessageHandler
- the existing messageHandler used by the weaver- Gibt zurück:
-
getName
-
setDefaultCacheFactory
The Cache and be extended in two ways, through a specialized CacheKeyResolver and a specialized CacheBacking. The default factory used to create these classes can be set with this method. Since each weaver will create a cache, this method must be called before the weaver is first initialized.- Parameter:
factory
-
-
createGeneratedCacheKey
Created a key for a generated class- Parameter:
className
- ClassName, e.g. "com.foo.Bar"- Gibt zurück:
- the cache key, or null if no caching should be performed
-
createCacheKey
Create a key for a normal weaved class- Parameter:
className
- ClassName, e.g. "com.foo.Bar"originalBytes
- Original byte array of the class- Gibt zurück:
- a cache key, or null if no caching should be performed
-
getCachingClassHandler
Returns a generated class handler which wraps the handler this cache was initialized with; this handler should be used to make sure that generated classes are added to the cache -
isEnabled
public static boolean isEnabled()Has caching been enabled through the System property, WEAVED_CLASS_CACHE_ENABLED- Gibt zurück:
- true if caching is enabled
-
put
Put a class in the cache- Parameter:
ref
- reference to the entry, as created through createCacheKeyclassBytes
- pre-weaving class bytesweavedBytes
- bytes to cache
-
get
Get a cache value- Parameter:
ref
- reference to the cache entry, created through createCacheKeyclassBytes
- Pre-weaving class bytes - required to ensure that cached aspects refer to an unchanged original class- Gibt zurück:
- the CacheEntry, or null if no entry exists in the cache
-
ignore
Put a cache entry to indicate that the class should not be weaved; the original bytes of the class should be used.- Parameter:
ref
- The cache referenceclassBytes
- The un-weaved class bytes
-
remove
Invalidate a cache entry- Parameter:
ref
-
-
clear
public void clear()Clear the entire cache -
getStats
Get the statistics associated with this cache, or null if statistics have not been enabled.- Gibt zurück:
-
getCaches
Return a list of all WeavedClassCaches which have been initialized- Gibt zurück:
-
error
-
error
-
info
-