public class ModuleLoader extends Object
Modifier and Type | Field and Description |
---|---|
static ModuleFinder[] |
NO_FINDERS
A constant representing zero module finders.
|
Modifier | Constructor and Description |
---|---|
protected |
ModuleLoader()
Construct a new instance.
|
|
ModuleLoader(ModuleFinder[] finders)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected Module |
findLoadedModuleLocal(ModuleIdentifier identifier)
Find an already-loaded module, returning
null if the module isn't currently loaded. |
protected ModuleSpec |
findModule(ModuleIdentifier moduleIdentifier)
Find a Module's specification in this ModuleLoader by its identifier.
|
static ModuleLoader |
forClass(Class<?> clazz)
Get the module loader for a class.
|
static ModuleLoader |
forClassLoader(ClassLoader classLoader)
Get the module loader for a class loader.
|
protected DependencySpec[] |
getDependencies(Module module)
Get the current dependency list for a module which was defined by this module loader, without any access checks.
|
protected ModuleFinder[] |
getFinders()
Get the module finders configured for this module loader.
|
Iterator<ModuleIdentifier> |
iterateModules(ModuleIdentifier baseIdentifier,
boolean recursive)
Iterate the modules which can be located via this module loader.
|
Module |
loadModule(ModuleIdentifier identifier)
Load a module based on an identifier.
|
protected Module |
loadModuleLocal(ModuleIdentifier identifier)
Try to load a module from this module loader.
|
protected Module |
preloadExportedModule(ModuleIdentifier identifier)
Preload an "exported" module based on an identifier.
|
protected Module |
preloadModule(ModuleIdentifier identifier)
Preload a module based on an identifier.
|
protected static Module |
preloadModule(ModuleIdentifier identifier,
ModuleLoader moduleLoader)
Utility method to delegate to another module loader, accessible from subclasses.
|
protected void |
refreshResourceLoaders(Module module)
Refreshes the paths provided by resource loaders associated with the
specified Module.
|
protected void |
relink(Module module)
Relinks the dependencies associated with the specified Module.
|
protected void |
setAndRefreshResourceLoaders(Module module,
Collection<ResourceLoaderSpec> loaders)
Replaces the resources loaders for the specified module and refreshes the
internal path list that is derived from the loaders.
|
protected void |
setAndRelinkDependencies(Module module,
List<DependencySpec> dependencies)
Replaces the dependencies for the specified module and relinks against
the new modules This is an advanced method that should be used carefully,
since it alters a live module.
|
String |
toString()
Get the string representation of this module loader.
|
protected void |
unloadModuleLocal(Module module)
Unload a module from this module loader.
|
public static final ModuleFinder[] NO_FINDERS
protected ModuleLoader()
public ModuleLoader(ModuleFinder[] finders)
finders
- the module finders to search, in orderpublic static ModuleLoader forClass(Class<?> clazz)
clazz
- the classnull
if the class's class loader does not belong to a module loader.public static ModuleLoader forClassLoader(ClassLoader classLoader)
classLoader
- the class loadernull
if the class loader does not belong to a module loader.public String toString()
public final Module loadModule(ModuleIdentifier identifier) throws ModuleLoadException
preloadModule(ModuleIdentifier)
and then
links the returned module if necessary.identifier
- The module identifierModuleLoadException
- if the Module can not be loadedpublic final Iterator<ModuleIdentifier> iterateModules(ModuleIdentifier baseIdentifier, boolean recursive)
baseIdentifier
- the identifier to start with, or null
to iterate all modulesrecursive
- true
to find recursively nested modules, false
to only find immediately nested modulesSecurityException
- if the caller does not have permission to iterate module loadersprotected Module preloadModule(ModuleIdentifier identifier) throws ModuleLoadException
loadModuleLocal(ModuleIdentifier)
. A delegating module loader may delegate to the appropriate module
loader based on loader-specific criteria (via the preloadModule(ModuleIdentifier, ModuleLoader)
method).identifier
- the module identifiernull
if the module is not foundModuleLoadException
- if an error occursprotected Module preloadExportedModule(ModuleIdentifier identifier) throws ModuleLoadException
preloadModule(ModuleIdentifier)
.identifier
- the module identifiernull
if the module is not foundModuleLoadException
- if an error occursprotected static Module preloadModule(ModuleIdentifier identifier, ModuleLoader moduleLoader) throws ModuleLoadException
identifier
- the module identifiermoduleLoader
- the module loader to delegate toModuleLoadException
- if an error occursprotected final Module loadModuleLocal(ModuleIdentifier identifier) throws ModuleLoadException
null
if the module is not found. The returned
module may not yet be resolved. The returned module may have a different name than the given identifier if
the identifier is an alias for another module.identifier
- the module identifierModuleLoadException
- if an error occurs while loading the moduleprotected final Module findLoadedModuleLocal(ModuleIdentifier identifier)
null
if the module isn't currently loaded. May block
while the loaded state of the module is in question (if the module is being concurrently loaded from another
thread, for example).identifier
- the module identifiernull
if it wasn't foundprotected final void unloadModuleLocal(Module module) throws SecurityException
module
- the module to unloadSecurityException
- if an attempt is made to unload a module which does not belong to this module loaderSecurityException
- if the module was not defined by this module loaderprotected ModuleSpec findModule(ModuleIdentifier moduleIdentifier) throws ModuleLoadException
null
. If the module is found but some problem occurred (for example, a transitive dependency failed to load)
then this method should throw a ModuleLoadException
of the relevant type.moduleIdentifier
- the module identifiernull
if no module is found with the given identifierModuleLoadException
- if any problems occur finding the moduleprotected final ModuleFinder[] getFinders()
protected void refreshResourceLoaders(Module module)
module
- the module to refreshSecurityException
- if the module was not defined by this module loader, or if the module loader does not
have the required permissions associated with itprotected void setAndRefreshResourceLoaders(Module module, Collection<ResourceLoaderSpec> loaders)
relink(Module)
must be called on all of them.module
- the module to update and refreshloaders
- the new collection of loaders the module should useSecurityException
- if the module was not defined by this module loader, or if the module loader does not
have the required permissions associated with itprotected void relink(Module module) throws ModuleLoadException
setAndRelinkDependencies(Module, java.util.List)
.module
- the module to relinkModuleLoadException
- if relinking failedSecurityException
- if the module was not defined by this module loader, or if the module loader does not
have the required permissions associated with itprotected void setAndRelinkDependencies(Module module, List<DependencySpec> dependencies) throws ModuleLoadException
relink(Module)
must be
called on all of them.module
- the module to update and relinkdependencies
- the new dependency listModuleLoadException
- if relinking failedSecurityException
- if the module was not defined by this module loader, or if the module loader does not
have the required permissions associated with itprotected DependencySpec[] getDependencies(Module module)
SecurityException
- if the module was not defined by this module loaderCopyright © 2013 JBoss by Red Hat. All Rights Reserved.