Class CachingModuleScriptProviderBase
- java.lang.Object
-
- org.htmlunit.corejs.javascript.commonjs.module.provider.CachingModuleScriptProviderBase
-
- All Implemented Interfaces:
java.io.Serializable,ModuleScriptProvider
- Direct Known Subclasses:
SoftCachingModuleScriptProvider,StrongCachingModuleScriptProvider
public abstract class CachingModuleScriptProviderBase extends java.lang.Object implements ModuleScriptProvider, java.io.Serializable
Abstract base class that implements caching of loaded module scripts. It uses aModuleSourceProviderto obtain the source text of the scripts. It supports a cache revalidation mechanism based on validator objects returned from theModuleSourceProvider. Instances of this class and its subclasses are thread safe (and written to perform decently under concurrent access).- Version:
- $Id: CachingModuleScriptProviderBase.java,v 1.3 2011/04/07 20:26:12 hannes%helma.at Exp $
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCachingModuleScriptProviderBase.CachedModuleScriptInstances of this class represent a loaded and cached module script.
-
Field Summary
Fields Modifier and Type Field Description private static intloadConcurrencyLevelprivate static intloadLockCountprivate static intloadLockMaskprivate java.lang.Object[]loadLocksprivate static intloadLockShiftprivate ModuleSourceProvidermoduleSourceProviderprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description protectedCachingModuleScriptProviderBase(ModuleSourceProvider moduleSourceProvider)Creates a new module script provider with the specified source.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private static booleanequal(java.lang.Object o1, java.lang.Object o2)protected static intgetConcurrencyLevel()Returns the internal concurrency level utilized by caches in this JVM.protected abstract CachingModuleScriptProviderBase.CachedModuleScriptgetLoadedModule(java.lang.String moduleId)Retrieves an already loaded moduleScript stored usingputLoadedModule(String, ModuleScript, Object).ModuleScriptgetModuleScript(Context cx, java.lang.String moduleId, java.net.URI moduleUri, java.net.URI baseUri, Scriptable paths)Returns a module script.private static java.lang.ObjectgetValidator(CachingModuleScriptProviderBase.CachedModuleScript cachedModule)protected abstract voidputLoadedModule(java.lang.String moduleId, ModuleScript moduleScript, java.lang.Object validator)Store a loaded module script for later retrieval usinggetLoadedModule(String).
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
loadConcurrencyLevel
private static final int loadConcurrencyLevel
-
loadLockShift
private static final int loadLockShift
-
loadLockMask
private static final int loadLockMask
-
loadLockCount
private static final int loadLockCount
-
loadLocks
private final java.lang.Object[] loadLocks
-
moduleSourceProvider
private final ModuleSourceProvider moduleSourceProvider
-
-
Constructor Detail
-
CachingModuleScriptProviderBase
protected CachingModuleScriptProviderBase(ModuleSourceProvider moduleSourceProvider)
Creates a new module script provider with the specified source.- Parameters:
moduleSourceProvider- provider for modules' source code
-
-
Method Detail
-
getModuleScript
public ModuleScript getModuleScript(Context cx, java.lang.String moduleId, java.net.URI moduleUri, java.net.URI baseUri, Scriptable paths) throws java.lang.Exception
Description copied from interface:ModuleScriptProviderReturns a module script. It should attempt to load the module script if it is not already available to it, or return an already loaded module script instance if it is available to it.- Specified by:
getModuleScriptin interfaceModuleScriptProvider- Parameters:
cx- current context. Can be used to compile module scripts.moduleId- the ID of the module. An implementation must only accept an absolute ID, starting with a term.moduleUri- the URI of the module. If this is not null, resolution ofmoduleIdis bypassed and the script is directly loaded frommoduleUribaseUri- the module path base URI from whichmoduleUriwas derived.paths- the value of the require() function's "paths" attribute. If the require() function is sandboxed, it will be null, otherwise it will be a JavaScript Array object. It is up to the provider implementation whether and how it wants to honor the contents of the array.- Returns:
- a module script representing the compiled code of the module. Null should be returned if the script could not found.
- Throws:
java.lang.Exception- if there was an unrecoverable problem obtaining the scriptjava.lang.IllegalArgumentException- if the module ID is syntactically not a valid absolute module identifier.
-
putLoadedModule
protected abstract void putLoadedModule(java.lang.String moduleId, ModuleScript moduleScript, java.lang.Object validator)Store a loaded module script for later retrieval usinggetLoadedModule(String).- Parameters:
moduleId- the ID of the modulemoduleScript- the module scriptvalidator- the validator for the module's source text entity
-
getLoadedModule
protected abstract CachingModuleScriptProviderBase.CachedModuleScript getLoadedModule(java.lang.String moduleId)
Retrieves an already loaded moduleScript stored usingputLoadedModule(String, ModuleScript, Object).- Parameters:
moduleId- the ID of the module- Returns:
- a cached module script, or null if the module is not loaded.
-
getValidator
private static java.lang.Object getValidator(CachingModuleScriptProviderBase.CachedModuleScript cachedModule)
-
equal
private static boolean equal(java.lang.Object o1, java.lang.Object o2)
-
getConcurrencyLevel
protected static int getConcurrencyLevel()
Returns the internal concurrency level utilized by caches in this JVM.- Returns:
- the internal concurrency level utilized by caches in this JVM.
-
-