public class ModuleLoader
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
ModuleLoader.FutureModule |
private static interface |
ModuleLoader.MBeanReg |
(package private) static class |
ModuleLoader.MXBeanImpl |
private static class |
ModuleLoader.RealMBeanReg |
private static class |
ModuleLoader.TempMBeanReg |
Modifier and Type | Field and Description |
---|---|
private boolean |
canRedefine |
private java.util.concurrent.atomic.AtomicInteger |
classCount |
private java.util.concurrent.atomic.AtomicLong |
classLoadTime |
private ModuleFinder[] |
finders |
private java.util.concurrent.atomic.AtomicLong |
linkTime |
private java.util.concurrent.atomic.AtomicLong |
loadTime |
private static java.lang.RuntimePermission |
ML_PERM |
private static java.lang.RuntimePermission |
MODULE_ITERATE_PERM |
private static java.lang.RuntimePermission |
MODULE_REDEFINE_ANY_PERM |
private static java.lang.RuntimePermission |
MODULE_REDEFINE_PERM |
private static java.lang.RuntimePermission |
MODULE_UNLOAD_ANY_PERM |
private java.util.concurrent.ConcurrentMap<ModuleIdentifier,ModuleLoader.FutureModule> |
moduleMap |
private ModuleLoaderMXBean |
mxBean |
static ModuleFinder[] |
NO_FINDERS
A constant representing zero module finders.
|
private java.util.concurrent.atomic.AtomicInteger |
raceCount |
private static Reaper<ModuleLoader,javax.management.ObjectName> |
reaper |
private static ModuleLoader.MBeanReg |
REG_REF |
private java.util.concurrent.atomic.AtomicInteger |
scanCount |
private static java.util.concurrent.atomic.AtomicInteger |
SEQ |
Modifier | Constructor and Description |
---|---|
protected |
ModuleLoader()
Construct a new instance.
|
(package private) |
ModuleLoader(boolean canRedefine,
boolean skipRegister) |
(package private) |
ModuleLoader(boolean canRedefine,
boolean skipRegister,
ModuleFinder[] finders) |
|
ModuleLoader(ModuleFinder[] finders)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
addClassLoadTime(long time) |
(package private) void |
addLinkTime(long amount) |
private static boolean |
checkPermissions() |
private Module |
defineModule(ConcreteModuleSpec moduleSpec,
ModuleLoader.FutureModule futureModule)
Defines a Module based on a specification.
|
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(java.lang.Class<?> clazz)
Get the module loader for a class.
|
static ModuleLoader |
forClassLoader(java.lang.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.
|
(package private) void |
incClassCount() |
(package private) void |
incRaceCount() |
(package private) void |
incScanCount() |
(package private) static void |
installMBeanServer() |
java.util.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.
|
private static ModuleFinder[] |
safeClone(ModuleFinder[] finders) |
protected void |
setAndRefreshResourceLoaders(Module module,
java.util.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,
java.util.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.
|
java.lang.String |
toString()
Get the string representation of this module loader.
|
protected void |
unloadModuleLocal(Module module)
Unload a module from this module loader.
|
private static final java.lang.RuntimePermission ML_PERM
private static final java.lang.RuntimePermission MODULE_REDEFINE_PERM
private static final java.lang.RuntimePermission MODULE_REDEFINE_ANY_PERM
private static final java.lang.RuntimePermission MODULE_UNLOAD_ANY_PERM
private static final java.lang.RuntimePermission MODULE_ITERATE_PERM
private static final java.util.concurrent.atomic.AtomicInteger SEQ
private static volatile ModuleLoader.MBeanReg REG_REF
public static final ModuleFinder[] NO_FINDERS
private final java.util.concurrent.ConcurrentMap<ModuleIdentifier,ModuleLoader.FutureModule> moduleMap
private final ModuleFinder[] finders
private final boolean canRedefine
private final ModuleLoaderMXBean mxBean
private final java.util.concurrent.atomic.AtomicLong linkTime
private final java.util.concurrent.atomic.AtomicLong loadTime
private final java.util.concurrent.atomic.AtomicLong classLoadTime
private final java.util.concurrent.atomic.AtomicInteger scanCount
private final java.util.concurrent.atomic.AtomicInteger raceCount
private final java.util.concurrent.atomic.AtomicInteger classCount
private static final Reaper<ModuleLoader,javax.management.ObjectName> reaper
ModuleLoader(boolean canRedefine, boolean skipRegister)
ModuleLoader(boolean canRedefine, boolean skipRegister, ModuleFinder[] finders)
protected ModuleLoader()
public ModuleLoader(ModuleFinder[] finders)
finders
- the module finders to search, in orderprivate static ModuleFinder[] safeClone(ModuleFinder[] finders)
private static boolean checkPermissions()
public static ModuleLoader forClass(java.lang.Class<?> clazz)
clazz
- the classnull
if the class's class loader does not belong to a module loader.public static ModuleLoader forClassLoader(java.lang.ClassLoader classLoader)
classLoader
- the class loadernull
if the class loader does not belong to a module loader.public java.lang.String toString()
toString
in class java.lang.Object
static void installMBeanServer()
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 java.util.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 modulesjava.lang.SecurityException
- 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 java.lang.SecurityException
module
- the module to unloadjava.lang.SecurityException
- if an attempt is made to unload a module which does not belong to this module loaderjava.lang.SecurityException
- 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()
private Module defineModule(ConcreteModuleSpec moduleSpec, ModuleLoader.FutureModule futureModule) throws ModuleLoadException
loadModuleLocal(ModuleIdentifier)
.moduleSpec
- The module specification to create the Module fromfutureModule
- the future module to populateModuleLoadException
- If any dependent modules can not be loadedprotected void refreshResourceLoaders(Module module)
module
- the module to refreshjava.lang.SecurityException
- 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, java.util.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 usejava.lang.SecurityException
- 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 failedjava.lang.SecurityException
- 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, java.util.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 failedjava.lang.SecurityException
- 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)
java.lang.SecurityException
- if the module was not defined by this module loadervoid addLinkTime(long amount)
void addClassLoadTime(long time)
void incScanCount()
void incRaceCount()
void incClassCount()