Class Module
ModuleLoader
s which build modules from
various configuration information and resource roots.- Author:
- David M. Lloyd, John Bailey, Flavia Rainone, Jason T. Greene, thomas.diesler@jboss.com
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Iterable
<T> findServices
(Class<T> type, Predicate<Class<?>> filter, ClassLoader loader) Returns an iterable of available and filtered providers of given type.static Module
Get the module for a loaded class, ornull
if the class did not come from any module.static Module
forClassLoader
(ClassLoader cl, boolean search) Get the module for a class loader, ornull
if the class loader is not associated with any module.static ModuleLoader
Gets the boot module loader.static Module
Get the caller's module.static ModuleLoader
Gets the current module loader.Get the class loader for a module.static ModuleLoader
Get the current thread's context module loader.Get the current dependencies of this module.Get all the paths exported by this module.getExportedResource
(String name) Get an exported resource URL.getExportedResource
(String rootPath, String resourcePath) Deprecated.Resource root names are deprecated.getExportedResources
(String name) Get all exported resource URLs for a resource name.Deprecated.UsegetName()
instead.Get the (unmodifiable) set of paths which are imported into this module class loader, including local paths.Get the module with the given identifier from the module loader used by this module.getModule
(ModuleIdentifier identifier) Deprecated.UsegetModule(String)
instead.static Module
Get a module from the current module loader.static Module
getModuleFromCallerModuleLoader
(ModuleIdentifier identifier) Deprecated.UsegetModuleFromCallerModuleLoader(String)
instead.Get the module loader which created this module.static ModuleLogger
Get the logger used by the module system.getName()
Get this module's name.Get the module's configured permission collection.static String
Get the platform identifier.static org.jboss.modules._private.ModulesPrivateAccess
Private access for module internal code.getProperty
(String name) Get the property with the given name, ornull
if none was defined.getProperty
(String name, String defaultVal) Get the property with the given name, or a default value if none was defined.Get a copy of the list of property names.static long
Return the start time in millis when Module.class was loaded.static ModuleLoader
Get the system module loader.Get the module version.globResources
(String glob) Enumerate all imported resources in this module which match the given glob expression.iterateResources
(PathFilter filter) Enumerate all the imported resources in this module, subject to a path filter.static Class
<?> loadClassFromBootModuleLoader
(String name, String className) Load a class from a module in the system module loader.static Class
<?> loadClassFromBootModuleLoader
(ModuleIdentifier moduleIdentifier, String className) Deprecated.UseloadClassFromBootModuleLoader(String, String)
instead.static Class
<?> loadClassFromCallerModuleLoader
(String name, String className) Load a class from a module in the caller's module loader.static Class
<?> loadClassFromCallerModuleLoader
(ModuleIdentifier moduleIdentifier, String className) Deprecated.UseloadClassFromCallerModuleLoader(String, String)
instead.<S> ServiceLoader
<S> loadService
(Class<S> serviceType) Load a service loader from this module.<S> ServiceLoader
<S> loadServiceDirectly
(Class<S> serviceType) Load a service loader from this module, without looking at dependencies.static <S> ServiceLoader
<S> loadServiceFromCallerModuleLoader
(String name, Class<S> serviceType) Load a service loader from a module in the caller's module loader.static <S> ServiceLoader
<S> loadServiceFromCallerModuleLoader
(ModuleIdentifier identifier, Class<S> serviceType) Deprecated.UseloadServiceFromCallerModuleLoader(String, Class)
instead.static void
Register an additional module which contains content handlers.static void
Register an additional module which contains URL handlers.void
Run a module's main class, if any.void
Run the given main class in this module.static void
setModuleLogger
(ModuleLogger logger) Change the logger used by the module system.toString()
Get the string representation of this module.
-
Method Details
-
getPrivateAccess
public static org.jboss.modules._private.ModulesPrivateAccess getPrivateAccess()Private access for module internal code. ThrowsSecurityException
for user code.- Throws:
SecurityException
- always
-
getDependencies
Get the current dependencies of this module.- Returns:
- the current dependencies of this module
- Throws:
SecurityException
- if a security manager is enabled and the caller does not have thegetDependencies
RuntimePermission
-
getExportedResource
Deprecated.Resource root names are deprecated.Get an exported resource from a specific root in this module.- Parameters:
rootPath
- the module root to searchresourcePath
- the path of the resource- Returns:
- the resource
-
run
public void run(String[] args) throws NoSuchMethodException, InvocationTargetException, ClassNotFoundException Run a module's main class, if any.- Parameters:
args
- the arguments to pass- Throws:
NoSuchMethodException
- if there is no main methodInvocationTargetException
- if the main method failedClassNotFoundException
- if the main class is not found
-
run
public void run(String className, String[] args) throws NoSuchMethodException, InvocationTargetException, ClassNotFoundException Run the given main class in this module.- Parameters:
className
- the class name to run (must not benull
)args
- the arguments to pass- Throws:
NoSuchMethodException
- if there is no main methodInvocationTargetException
- if the main method failedClassNotFoundException
- if the main class is not found
-
getIdentifier
Deprecated.UsegetName()
instead.Get this module's identifier.- Returns:
- the identifier
-
getName
Get this module's name.- Returns:
- this module's name
-
getModuleLoader
Get the module loader which created this module.- Returns:
- the module loader of this module
-
loadService
Load a service loader from this module.- Type Parameters:
S
- the service type- Parameters:
serviceType
- the service type class- Returns:
- the service loader
-
loadServiceDirectly
Load a service loader from this module, without looking at dependencies.- Type Parameters:
S
- the service type- Parameters:
serviceType
- the service type class- Returns:
- the service loader
-
loadServiceFromCallerModuleLoader
@Deprecated public static <S> ServiceLoader<S> loadServiceFromCallerModuleLoader(ModuleIdentifier identifier, Class<S> serviceType) throws ModuleLoadException Deprecated.UseloadServiceFromCallerModuleLoader(String, Class)
instead.Load a service loader from a module in the caller's module loader. The caller's module loader refers to the loader of the module of the class that calls this method. Note thatloadService(Class)
is more efficient since it does not need to crawl the stack.- Type Parameters:
S
- the the service type- Parameters:
identifier
- the module identifier containing the service loaderserviceType
- the service type class- Returns:
- the loaded service from the caller's module
- Throws:
ModuleLoadException
- if the named module failed to load
-
loadServiceFromCallerModuleLoader
public static <S> ServiceLoader<S> loadServiceFromCallerModuleLoader(String name, Class<S> serviceType) throws ModuleLoadException Load a service loader from a module in the caller's module loader. The caller's module loader refers to the loader of the module of the class that calls this method. Note thatloadService(Class)
is more efficient since it does not need to crawl the stack.- Type Parameters:
S
- the the service type- Parameters:
name
- the module name containing the service loaderserviceType
- the service type class- Returns:
- the loaded service from the caller's module
- Throws:
ModuleLoadException
- if the named module failed to load
-
getClassLoader
Get the class loader for a module. The class loader can be used to access non-exported classes and resources of the module.If a security manager is present, then this method invokes the security manager's
checkPermission
method with aRuntimePermission("getClassLoader")
permission to verify access to the class loader. If access is not granted, aSecurityException
will be thrown.- Returns:
- the module class loader
-
getExportedPaths
Get all the paths exported by this module.- Returns:
- the paths that are exported by this module
-
forClass
Get the module for a loaded class, ornull
if the class did not come from any module.- Parameters:
clazz
- the class- Returns:
- the module it came from
-
forClassLoader
Get the module for a class loader, ornull
if the class loader is not associated with any module. If the class loader is unknown, it is possible to check the parent class loader up the chain, and so on until a module is found.- Parameters:
cl
- the class loadersearch
-true
to search up the delegation chain- Returns:
- the associated module
-
getBootModuleLoader
Gets the boot module loader. The boot module loader is the initial loader that is established by the module framework. It typically is based off of the environmental module path unless it is overridden by specifying a different class name for theboot.module.loader
system property.- Returns:
- the boot module loader
-
getSystemModuleLoader
Get the system module loader. This is the module loader which contains the Java platform modules, plus a module for JBoss Modules itself, calledorg.jboss.modules
.- Returns:
- the system module loader
-
findServices
public static <T> Iterable<T> findServices(Class<T> type, Predicate<Class<?>> filter, ClassLoader loader) Returns an iterable of available and filtered providers of given type.- Parameters:
type
- service provider typefilter
- to specify which providers to loadloader
- to be used for providers lookup- Returns:
- An iterable of available and filtered providers of given type
-
getCallerModuleLoader
Gets the current module loader. The current module loader is the loader of the module from the calling class. Note that this method must crawl the stack to determine this, so other mechanisms are more efficient.- Returns:
- the current module loader, or
null
if this method is called outside of a module
-
getContextModuleLoader
Get the current thread's context module loader. This loader is the one which defined the module whose class loader is, or is a parent of, the thread's current context class loader. If there is none, thennull
is returned.- Returns:
- the module loader, or
null
if none is set
-
getModuleFromCallerModuleLoader
@Deprecated public static Module getModuleFromCallerModuleLoader(ModuleIdentifier identifier) throws ModuleLoadException Deprecated.UsegetModuleFromCallerModuleLoader(String)
instead.Get a module from the current module loader. Note that this must crawl the stack to determine this, so other mechanisms are more efficient.- Parameters:
identifier
- the module identifier- Returns:
- the module
- Throws:
ModuleLoadException
- if the module could not be loaded- See Also:
-
getModuleFromCallerModuleLoader
Get a module from the current module loader. Note that this must crawl the stack to determine this, so other mechanisms are more efficient.- Parameters:
name
- the module name- Returns:
- the module
- Throws:
ModuleLoadException
- if the module could not be loaded- See Also:
-
getCallerModule
Get the caller's module. The caller's module is the module containing the method that calls this method. Note that this method crawls the stack so other ways of obtaining the module are more efficient.- Returns:
- the current module
-
getModule
Deprecated.UsegetModule(String)
instead.Get the module with the given identifier from the module loader used by this module.- Parameters:
identifier
- the module identifier- Returns:
- the module
- Throws:
ModuleLoadException
- if an error occurs
-
getModule
Get the module with the given identifier from the module loader used by this module.- Parameters:
name
- the module name- Returns:
- the module
- Throws:
ModuleLoadException
- if an error occurs
-
loadClassFromBootModuleLoader
@Deprecated public static Class<?> loadClassFromBootModuleLoader(ModuleIdentifier moduleIdentifier, String className) throws ModuleLoadException, ClassNotFoundException Deprecated.UseloadClassFromBootModuleLoader(String, String)
instead.Load a class from a module in the system module loader.- Parameters:
moduleIdentifier
- the identifier of the module from which the class should be loadedclassName
- the class name to load- Returns:
- the class
- Throws:
ModuleLoadException
- if the module could not be loadedClassNotFoundException
- if the class could not be loaded- See Also:
-
loadClassFromBootModuleLoader
public static Class<?> loadClassFromBootModuleLoader(String name, String className) throws ModuleLoadException, ClassNotFoundException Load a class from a module in the system module loader.- Parameters:
name
- the name of the module from which the class should be loadedclassName
- the class name to load- Returns:
- the class
- Throws:
ModuleLoadException
- if the module could not be loadedClassNotFoundException
- if the class could not be loaded- See Also:
-
loadClassFromCallerModuleLoader
@Deprecated public static Class<?> loadClassFromCallerModuleLoader(ModuleIdentifier moduleIdentifier, String className) throws ModuleLoadException, ClassNotFoundException Deprecated.UseloadClassFromCallerModuleLoader(String, String)
instead.Load a class from a module in the caller's module loader.- Parameters:
moduleIdentifier
- the identifier of the module from which the class should be loadedclassName
- the class name to load- Returns:
- the class
- Throws:
ModuleLoadException
- if the module could not be loadedClassNotFoundException
- if the class could not be loaded- See Also:
-
loadClassFromCallerModuleLoader
public static Class<?> loadClassFromCallerModuleLoader(String name, String className) throws ModuleLoadException, ClassNotFoundException Load a class from a module in the caller's module loader.- Parameters:
name
- the name of the module from which the class should be loadedclassName
- the class name to load- Returns:
- the class
- Throws:
ModuleLoadException
- if the module could not be loadedClassNotFoundException
- if the class could not be loaded- See Also:
-
getExportedResource
Get an exported resource URL.- Parameters:
name
- the resource name- Returns:
- the resource, or
null
if it was not found
-
getExportedResources
Get all exported resource URLs for a resource name.- Parameters:
name
- the resource name- Returns:
- the resource URLs
-
iterateResources
Enumerate all the imported resources in this module, subject to a path filter. The filter applies to the containing path of each resource.- Parameters:
filter
- the filter to apply to the search- Returns:
- the resource iterator (possibly empty)
- Throws:
ModuleLoadException
- if linking a dependency module fails for some reason
-
globResources
Enumerate all imported resources in this module which match the given glob expression. The glob applies to the whole resource name.- Parameters:
glob
- the glob to apply- Returns:
- the iterator
- Throws:
ModuleLoadException
- if linking a dependency module fails for some reason
-
getImportedPaths
Get the (unmodifiable) set of paths which are imported into this module class loader, including local paths. The set will include all paths defined by the module's resource loaders, minus any paths excluded by filters. The set will generally always contain an empty entry (""). The set is unordered and unsorted, and is iterable in O(n) time and accessible in O(1) time.- Returns:
- the set of paths
- Throws:
ModuleLoadException
- if the module was previously unlinked, and there was an exception while linking
-
getProperty
Get the property with the given name, ornull
if none was defined.- Parameters:
name
- the property name- Returns:
- the property value
-
getProperty
Get the property with the given name, or a default value if none was defined.- Parameters:
name
- the property namedefaultVal
- the default value- Returns:
- the property value
-
getPropertyNames
Get a copy of the list of property names.- Returns:
- the property names list
-
getVersion
Get the module version.- Returns:
- the module version, or
null
if none was set
-
toString
Get the string representation of this module. -
getModuleLogger
Get the logger used by the module system.If a security manager is present, then this method invokes the security manager's
checkPermission
method with aRuntimePermission("accessModuleLogger")
permission to verify access to the module logger. If access is not granted, aSecurityException
will be thrown.- Returns:
- the module logger
-
setModuleLogger
Change the logger used by the module system.If a security manager is present, then this method invokes the security manager's
checkPermission
method with aRuntimePermission("accessModuleLogger")
permission to verify access to the module logger. If access is not granted, aSecurityException
will be thrown.- Parameters:
logger
- the new logger, must not benull
-
getStartTime
public static long getStartTime()Return the start time in millis when Module.class was loaded.- Returns:
- start time of Module.class load
-
registerContentHandlerFactoryModule
Register an additional module which contains content handlers.If a security manager is present, then this method invokes the security manager's
checkPermission
method with aRuntimePermission("addContentHandlerFactory")
permission to verify access. If access is not granted, aSecurityException
will be thrown.- Parameters:
module
- the module to add
-
registerURLStreamHandlerFactoryModule
Register an additional module which contains URL handlers.If a security manager is present, then this method invokes the security manager's
checkPermission
method with aRuntimePermission("addURLStreamHandlerFactory")
permission to verify access. If access is not granted, aSecurityException
will be thrown.- Parameters:
module
- the module to add
-
getPlatformIdentifier
Get the platform identifier. This is the string that uniquely identifies the hardware and OS combination for the current running system.- Returns:
- the platform identifier
-
getPermissionCollection
Get the module's configured permission collection.- Returns:
- the module permission collection
-