Class CachingModuleScriptProviderBase
java.lang.Object
org.mozilla.javascript.commonjs.module.provider.CachingModuleScriptProviderBase
- All Implemented Interfaces:
Serializable
,ModuleScriptProvider
- Direct Known Subclasses:
SoftCachingModuleScriptProvider
,StrongCachingModuleScriptProvider
public abstract class CachingModuleScriptProviderBase
extends Object
implements ModuleScriptProvider, Serializable
Abstract base class that implements caching of loaded module scripts. It
uses a
ModuleSourceProvider
to obtain the source text of the
scripts. It supports a cache revalidation mechanism based on validator
objects returned from the ModuleSourceProvider
. 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Instances of this class represent a loaded and cached module script. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final int
private final Object[]
private static final int
private final ModuleSourceProvider
private static final long
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CachingModuleScriptProviderBase
(ModuleSourceProvider moduleSourceProvider) Creates a new module script provider with the specified source. -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
protected static int
Returns the internal concurrency level utilized by caches in this JVM.protected abstract CachingModuleScriptProviderBase.CachedModuleScript
getLoadedModule
(String moduleId) Retrieves an already loaded moduleScript stored usingputLoadedModule(String, ModuleScript, Object)
.getModuleScript
(Context cx, String moduleId, URI moduleUri, URI baseUri, Scriptable paths) Returns a module script.private static Object
protected abstract void
putLoadedModule
(String moduleId, ModuleScript moduleScript, Object validator) Store a loaded module script for later retrieval usinggetLoadedModule(String)
.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
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
-
moduleSourceProvider
-
-
Constructor Details
-
CachingModuleScriptProviderBase
Creates a new module script provider with the specified source.- Parameters:
moduleSourceProvider
- provider for modules' source code
-
-
Method Details
-
getModuleScript
public ModuleScript getModuleScript(Context cx, String moduleId, URI moduleUri, URI baseUri, Scriptable paths) throws Exception Description copied from interface:ModuleScriptProvider
Returns 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:
getModuleScript
in 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 ofmoduleId
is bypassed and the script is directly loaded frommoduleUri
baseUri
- the module path base URI from whichmoduleUri
was 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:
Exception
- if there was an unrecoverable problem obtaining the script
-
putLoadedModule
protected abstract void putLoadedModule(String moduleId, ModuleScript moduleScript, 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(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
-
equal
-
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.
-