public abstract class CachedFileProvider extends BaseFileProvider implements CacheSupport
CachedFileProvider
is an abstract starting point for an implementation of the JavaFileProvider
interface that adds cache support to the BaseFileProvider
.Modifier and Type | Class and Description |
---|---|
protected class |
CachedFileProvider.SourceFileTracker
The SourceFileTracker just listens to SourceFile instances that we create/cache, expiring them from our cache when they get modified outside of a transaction.
|
BaseFileProvider.BaseClass, BaseFileProvider.BasePackage
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,JavaType> |
_arrayCacheMap
Our cache of array types.
|
protected java.lang.Object |
_cacheLock
Our cache lock for synchronization
|
protected int |
_cacheRefCount
The ref count of cache use calls.
|
protected java.util.Map<java.lang.String,JavaClass> |
_classCacheMap
Our cache of class instances.
|
protected java.util.Map<java.net.URL,JavaFile> |
_classFileCacheMap
Our cache of *.class JavaFile instances.
|
protected java.lang.ClassLoader |
_defaultClassLoader
The (cached) default class loader instance.
|
protected long |
_lastCacheFlushedTime |
protected java.util.Map<java.net.URL,JavaFile> |
_lightSourceFileCacheMap
Our cache of "light" SourceFiles
|
protected java.lang.ClassLoader |
_nullClassLoader
The (cached) null-parent class loader instance.
|
protected java.util.Map<java.lang.String,JavaPackage> |
_packageCacheMap
Our cache of packages.
|
protected java.util.Map<java.net.URL,SourceFile> |
_sourceFileCacheMap
Our cache of *.java SourceFile instances.
|
protected static JavaClass |
CLASS_NOT_FOUND
Marker for class not found in the class cache
|
context
CLASS_TYPE, EMPTY_COLLECTION, SOURCE_TYPE, UNKNOWN_TYPE
Constructor and Description |
---|
CachedFileProvider(ProviderContext environment, java.lang.String scopeDescription) |
Modifier and Type | Method and Description |
---|---|
void |
beginCacheUse()
Instructs the data provider to enable the cache support.
|
protected void |
clearAllData()
Instructs this data provider to clear all cached data, and stop all trackers.
|
protected void |
clearArrayCache()
Utility routine to clean out our package cache.
|
protected void |
clearClassCache()
Utility routine to clean out our class caches.
|
protected void |
clearClassFileCache()
Utility routine to clean out our class file caches.
|
protected void |
clearClassLoader()
Internal method to allow clearing of the class loader (for example, in case a subclass changes the class locator instance.)
|
protected void |
clearCompiledInfo()
Utility routine to clear all compiled info.
|
protected void |
clearLightSourceFileCache()
Utility routine to clean out our light source file caches.
|
protected void |
clearPackageCache()
Utility routine to clean out our package cache.
|
protected void |
clearSourceFileCache()
Utility routine to clean out our source file caches.
|
SourceFile |
createSourceFile(java.net.URL url)
Creates a new SourceFile for the given Java source URL (*.java).
|
void |
endCacheUse()
Instructs the data provider to release the cache support.
|
protected void |
expireAllSourceFiles()
Utility routine to expire all SourceFile instances that we have cached currently.
|
void |
flushCache()
Instructs the data provider to force a cache flush.
|
protected void |
flushFoundCache()
Instructs the data provider to flush the resolution part of the cache (i.e., the found or not found) part of the cache.
|
protected JavaType |
getArrayTypeImpl(java.lang.String typeKey, JavaType component, int dimensions)
Fetch the array type represented by the given type and dimensions.
|
protected JavaClass |
getClassExactImpl(java.lang.String fqOuterClassName)
Utility routine to try to locate the given outer class.
|
protected JavaClass |
getClassExactImplInterruptibly(java.lang.String fqOuterClassName)
Utility routine to try to locate the given outer class.
|
protected JavaFile |
getClassFileImpl(java.net.URL classURL)
Fetch the JavaFile for the given Java class URL (*.class).
|
java.lang.ClassLoader |
getClassLoader()
Fetch a ClassLoader instance that can load classes based on the same class locator as this file provider instance.
|
java.lang.ClassLoader |
getClassLoader(java.lang.ClassLoader parentLoader)
Fetch a ClassLoader instance that can load classes based on the same class locator as this file provider instance.
|
protected JavaFile |
getLightSourceFileImpl(java.net.URL sourceURL)
Fetch a "light" SourceFile for the given Java source URL (*.java), packaged as a JavaFile.
|
protected BaseFileProvider.BasePackage |
getPackageImpl(java.lang.String fqName)
Fetch the JavaPackage instance for the given package.
|
java.lang.String |
getScopeDescription() |
protected SourceFile |
getSourceFileImpl(java.net.URL sourceURL)
Fetch the SourceFile for the given Java source URL (*.java).
|
long |
lastCacheFlushed() |
protected JavaFile |
lookupCachedLightSourceFile(java.net.URL sourceURL)
Utility routine which looks up the cached LightSourceFile entry in our cache map, which uses SoftReference values.
|
protected SourceFile |
lookupCachedSourceFile(java.net.URL sourceURL)
Utility routine which looks up the cached SourceFile entry in our cache map, which uses SoftReference values.
|
void |
notifyOfChange(java.net.URL url)
Called by the ProviderEnvironment when a change has happened to an URL that we were tracking.
|
protected JavaFile |
removeCachedLightSourceFile(java.net.URL sourceURL, JavaFile javaFile)
Utility routine which removes the cached LightSourceFile (if any) from our cache map.
|
protected void |
removeCachedSourceFile(java.net.URL sourceURL)
Deprecated.
use removeCachedSourceFile( URL, SourceFile ) instead
|
protected void |
removeCachedSourceFile(java.net.URL sourceURL, SourceFile sourceFile)
Utility routine which removes the cached SourceFile from our cache map.
|
protected void |
storeCachedLightSourceFile(java.net.URL sourceURL, JavaFile sourceFile)
Utility routine which stores the given sourcefile into our cache using SoftReferences.
|
protected void |
storeCachedSourceFile(java.net.URL sourceURL, SourceFile sourceFile)
Utility routine which stores the given sourcefile into our cache using SoftReferences.
|
checkInterrupt, getArrayType, getClass, getClass, getClassByVMName, getClassByVMNameImpl, getClassByVMNameInterruptibly, getClassImpl, getClassImpl, getClassInterruptibly, getClassInterruptibly, getClassLeftToRight, getClassLeftToRightImpl, getClassLeftToRightInterruptibly, getClassLocator, getClassLocatorInterruptibly, getConteXt, getFile, getFileType, getInnerClassByVMName, getJavaFile, getJdkVersion, getPackage, getPackage, getPrimitiveClass, getSourceClass, getSourceClassByHint, getSourceClassImpl, getSourceClassInterruptibly, getSourceFile, getSourceFile, getTargetJdkVersion, getTextBuffer, locateClass, locateClass, locateClassByVMName, locateSourceClass, locateSourceClass, setConteXt, setJdkVersion, setTargetJdkVersion
protected final java.lang.Object _cacheLock
protected java.lang.ClassLoader _nullClassLoader
protected java.lang.ClassLoader _defaultClassLoader
protected long _lastCacheFlushedTime
protected java.util.Map<java.lang.String,JavaPackage> _packageCacheMap
protected java.util.Map<java.net.URL,SourceFile> _sourceFileCacheMap
protected java.util.Map<java.lang.String,JavaType> _arrayCacheMap
protected java.util.Map<java.lang.String,JavaClass> _classCacheMap
protected java.util.Map<java.net.URL,JavaFile> _classFileCacheMap
protected java.util.Map<java.net.URL,JavaFile> _lightSourceFileCacheMap
protected static final JavaClass CLASS_NOT_FOUND
protected int _cacheRefCount
public CachedFileProvider(ProviderContext environment, java.lang.String scopeDescription)
public java.lang.ClassLoader getClassLoader(java.lang.ClassLoader parentLoader)
Only one null-parent class loader will be created per cached file provider. For non-null parent loaders, this always creates a new instance.
parentLoader
- The ClassLoader to use as the parent. May be null.public java.lang.ClassLoader getClassLoader()
protected void clearClassLoader()
public SourceFile createSourceFile(java.net.URL url) throws java.io.IOException, java.lang.IllegalArgumentException
BaseFileProvider
createSourceFile
in interface JavaFileProvider
createSourceFile
in class BaseFileProvider
url
- the source URL to create a new Java file forjava.io.IOException
- if the new file cannot be createdjava.lang.IllegalArgumentException
- if the URL is not recognized as a Java source fileprotected SourceFile getSourceFileImpl(java.net.URL sourceURL)
getSourceFileImpl
in class BaseFileProvider
sourceURL
- the source URL to get the SourceFile forprotected JavaFile getLightSourceFileImpl(java.net.URL sourceURL)
BaseFileProvider
getLightSourceFileImpl
in class BaseFileProvider
sourceURL
- the source URL from which to get the sourcepublic void beginCacheUse()
endCacheUse()
when finished to ensure that the cache can be freed when it is no longer needed.beginCacheUse
in interface CacheSupport
public void endCacheUse()
endCacheUse
in interface CacheSupport
public long lastCacheFlushed()
public void flushCache()
flushCache
in interface CacheSupport
protected void flushFoundCache()
protected void clearAllData()
protected JavaFile getClassFileImpl(java.net.URL classURL)
getClassFileImpl
in class BaseFileProvider
classURL
- the class URL to get the Java file forprotected void clearClassFileCache()
protected SourceFile lookupCachedSourceFile(java.net.URL sourceURL)
@Deprecated protected void removeCachedSourceFile(java.net.URL sourceURL)
protected void removeCachedSourceFile(java.net.URL sourceURL, SourceFile sourceFile)
sourceURL
- - the URL used as the key to find the SourceFilesourceFile
- - if null, the key/value pair is always removed if it exists; if not null, the key/value pair is ONLY removed if the value is equal to the incoming sourceFileprotected void storeCachedSourceFile(java.net.URL sourceURL, SourceFile sourceFile)
protected void expireAllSourceFiles()
protected void clearSourceFileCache()
protected void clearCompiledInfo()
public void notifyOfChange(java.net.URL url)
BaseFileProvider
notifyOfChange
in class BaseFileProvider
protected JavaFile lookupCachedLightSourceFile(java.net.URL sourceURL)
protected JavaFile removeCachedLightSourceFile(java.net.URL sourceURL, JavaFile javaFile)
sourceURL
- - The source URL used as a key to find the LightSourceFilejavaFile
- - if null, the key/value pair stored using the sourceURL is removed without any checks; if not null, the key/value pair is ONLY removed if the value matches the incoming javaFileprotected void storeCachedLightSourceFile(java.net.URL sourceURL, JavaFile sourceFile)
protected void clearLightSourceFileCache()
protected JavaClass getClassExactImpl(java.lang.String fqOuterClassName)
getClassExactImpl
in class BaseFileProvider
fqOuterClassName
- the name of the fully-qualified outer class name we are searching forprotected JavaClass getClassExactImplInterruptibly(java.lang.String fqOuterClassName) throws java.lang.InterruptedException
getClassExactImplInterruptibly
in class BaseFileProvider
fqOuterClassName
- the name of the fully-qualified outer class name we are searching forjava.lang.InterruptedException
- if the search was interruptedprotected void clearClassCache()
protected JavaType getArrayTypeImpl(java.lang.String typeKey, JavaType component, int dimensions)
getArrayTypeImpl
in class BaseFileProvider
typeKey
- the qualified name of the type followed by the '[]'s for the dimensioncomponent
- the java typedimensions
- the array dimensionprotected void clearArrayCache()
protected BaseFileProvider.BasePackage getPackageImpl(java.lang.String fqName)
getPackageImpl
in class BaseFileProvider
protected void clearPackageCache()
public java.lang.String getScopeDescription()