1. 调试类:

org.jboss.as.server.Main的main方法

断点:

Module.registerURLStreamHandlerFactoryModule(Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.jboss.vfs")));

2.程序过程如下:

2.1 初始化模块加载器(Module.getBootModuleLoader())

org.jboss.modules.LocalModuleLoader的构造方法:

    /**
* Construct a new instance, using the {@code module.path} system property or the {@code JAVA_MODULEPATH} environment variable
* to get the list of module repository roots.
*/
public LocalModuleLoader() {
final String modulePath = System.getProperty("module.path", System.getenv("JAVA_MODULEPATH"));
if (modulePath == null) {
//noinspection ZeroLengthArrayAllocation
repoRoots = new File[0];
} else {
repoRoots = getFiles(modulePath, 0, 0);
}
pathFilter = PathFilters.acceptAll();
}

在此时设置module.path路径的值为:/jboss-home/modules,我自己的路径为:D:\source\jboss-as-7.1.1.Final\modules

2. 2 加载模块:(loadModule(ModuleIdentifier.create("org.jboss.vfs"))

   /**
* Load a module based on an identifier. This method delegates to {@link #preloadModule(ModuleIdentifier)} and then
* links the returned module if necessary.
*
* @param identifier The module identifier
* @return The loaded Module
* @throws ModuleLoadException if the Module can not be loaded
*/
public final Module loadModule(ModuleIdentifier identifier) throws ModuleLoadException {
final Module module = preloadModule(identifier);
if (module == null) {
throw new ModuleNotFoundException(identifier.toString());
}
module.relinkIfNecessary();
return module;
}

2.2.1 预加载模块

    /**
* Preload a module based on an identifier. By default, no delegation is done and this method simply invokes
* {@link #loadModuleLocal(ModuleIdentifier)}. A delegating module loader may delegate to the appropriate module
* loader based on loader-specific criteria (via the {@link #preloadModule(ModuleIdentifier, ModuleLoader)} method).
*
* @param identifier the module identifier
* @return the load result, or {@code null} if the module is not found
* @throws ModuleLoadException if an error occurs
*/
protected Module preloadModule(ModuleIdentifier identifier) throws ModuleLoadException {
return loadModuleLocal(identifier);
}

2.2.2 加载本地模块

    /**
* Try to load a module from this module loader. Returns {@code 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.
*
* @param identifier the module identifier
* @return the module
* @throws ModuleLoadException if an error occurs while loading the module
*/
protected final Module loadModuleLocal(ModuleIdentifier identifier) throws ModuleLoadException {
FutureModule futureModule = moduleMap.get(identifier);
if (futureModule != null) {
return futureModule.getModule();
} FutureModule newFuture = new FutureModule(identifier);
futureModule = moduleMap.putIfAbsent(identifier, newFuture);
if (futureModule != null) {
return futureModule.getModule();
} boolean ok = false;
try {
final ModuleLogger log = Module.log;
log.trace("Locally loading module %s from %s", identifier, this);
final long startTime = Metrics.getCurrentCPUTime();
final ModuleSpec moduleSpec = findModule(identifier);
loadTimeUpdater.addAndGet(this, Metrics.getCurrentCPUTime() - startTime);
if (moduleSpec == null) {
log.trace("Module %s not found from %s", identifier, this);
return null;
}
if (! moduleSpec.getModuleIdentifier().equals(identifier)) {
throw new ModuleLoadException("Module loader found a module with the wrong name");
}
final Module module;
if ( moduleSpec instanceof AliasModuleSpec) {
final ModuleIdentifier aliasTarget = ((AliasModuleSpec) moduleSpec).getAliasTarget();
try {
newFuture.setModule(module = loadModuleLocal(aliasTarget));
} catch (RuntimeException e) {
log.trace(e, "Failed to load module %s (alias for %s)", identifier, aliasTarget);
throw e;
} catch (Error e) {
log.trace(e, "Failed to load module %s (alias for %s)", identifier, aliasTarget);
throw e;
}
} else {
module = defineModule((ConcreteModuleSpec) moduleSpec, newFuture);
}
log.trace("Loaded module %s from %s", identifier, this);
ok = true;
return module;
} finally {
if (! ok) {
newFuture.setModule(null);
moduleMap.remove(identifier, newFuture);
}
}
}

2.2.2.1 查找模块

    protected ModuleSpec findModule(final ModuleIdentifier moduleIdentifier) throws ModuleLoadException {
final String child = toPathString(moduleIdentifier);
if (pathFilter.accept(child)) {
for (File root : repoRoots) {
final File file = new File(root, child);
final File moduleXml = new File(file, "module.xml");
if (moduleXml.exists()) {
return parseModuleInfoFile(moduleIdentifier, file, moduleXml);
}
}
}
throw new ModuleNotFoundException("Module " + moduleIdentifier + " is not found in " + this);
}

2.2.2.1 解析模块

private ModuleSpec parseModuleInfoFile(final ModuleIdentifier moduleIdentifier, final File moduleRoot, final File moduleInfoFile) throws ModuleLoadException {
return ModuleXmlParser.parseModuleXml(moduleIdentifier, moduleRoot, moduleInfoFile);
}

    static ModuleSpec parseModuleXml(final ModuleIdentifier moduleIdentifier, final File root, final File moduleInfoFile) throws ModuleLoadException {
final FileInputStream fis;
try {
fis = new FileInputStream(moduleInfoFile);
} catch (FileNotFoundException e) {
throw new ModuleLoadException("No module.xml file found at " + moduleInfoFile);
}
try {
return parseModuleXml(new ResourceRootFactory() {
public ResourceLoader createResourceLoader(final String rootPath, final String loaderPath, final String loaderName) throws IOException {
File file = new File(rootPath, loaderPath);
if (file.isDirectory()) {
return new FileResourceLoader(loaderName, file);
} else {
final JarFile jarFile = new JarFile(file, true);
return new JarFileResourceLoader(loaderName, jarFile);
}
}
}, root.getPath(), new BufferedInputStream(fis), moduleInfoFile.getPath(), moduleIdentifier);
} finally {
safeClose(fis);
}
}
    static ModuleSpec parseModuleXml(final ResourceRootFactory factory, final String rootPath, InputStream source, final String moduleInfoFile, final ModuleIdentifier moduleIdentifier) throws ModuleLoadException {
try {
final XMLInputFactory inputFactory = INPUT_FACTORY;
setIfSupported(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
setIfSupported(inputFactory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
final XMLStreamReader streamReader = inputFactory.createXMLStreamReader(source);
try {
return parseDocument(factory, rootPath, streamReader, moduleIdentifier);
} finally {
safeClose(streamReader);
}
} catch (XMLStreamException e) {
throw new ModuleLoadException("Error loading module from " + moduleInfoFile, e);
}
}
    private static ModuleSpec parseDocument(final ResourceRootFactory factory, final String rootPath, XMLStreamReader reader, final ModuleIdentifier moduleIdentifier) throws XMLStreamException {
while (reader.hasNext()) {
switch (reader.nextTag()) {
case START_DOCUMENT: {
return parseRootElement(factory, rootPath, reader, moduleIdentifier);
}
case START_ELEMENT: {
final Element element = Element.of(reader.getName());
switch (element) {
case MODULE: {
final ModuleSpec.Builder specBuilder = ModuleSpec.build(moduleIdentifier);
parseModuleContents(factory, rootPath, reader, specBuilder);
parseEndDocument(reader);
return specBuilder.create();
}
case MODULE_ALIAS: {
final ModuleSpec moduleSpec = parseModuleAliasContents(reader, moduleIdentifier);
parseEndDocument(reader);
return moduleSpec;
}
default: {
throw unexpectedContent(reader);
}
}
}
default: {
throw unexpectedContent(reader);
}
}
}
throw endOfDocument(reader.getLocation());
}
   private static void parseModuleContents(final ResourceRootFactory factory, final String rootPath, final XMLStreamReader reader, final ModuleSpec.Builder specBuilder) throws XMLStreamException {
final int count = reader.getAttributeCount();
String name = null;
String slot = null;
final Set<Attribute> required = EnumSet.of(Attribute.NAME);
for (int i = 0; i < count; i ++) {
final Attribute attribute = Attribute.of(reader.getAttributeName(i));
required.remove(attribute);
switch (attribute) {
case NAME: name = reader.getAttributeValue(i); break;
case SLOT: slot = reader.getAttributeValue(i); break;
default: throw unexpectedContent(reader);
}
}
if (! required.isEmpty()) {
throw missingAttributes(reader.getLocation(), required);
}
if (! specBuilder.getIdentifier().equals(ModuleIdentifier.create(name, slot))) {
throw invalidModuleName(reader.getLocation(), specBuilder.getIdentifier());
}
// xsd:all
MultiplePathFilterBuilder exportsBuilder = PathFilters.multiplePathFilterBuilder(true);
Set<Element> visited = EnumSet.noneOf(Element.class);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
specBuilder.addDependency(DependencySpec.createLocalDependencySpec(PathFilters.acceptAll(), exportsBuilder.create()));
return;
}
case START_ELEMENT: {
final Element element = Element.of(reader.getName());
if (visited.contains(element)) {
throw unexpectedContent(reader);
}
visited.add(element);
switch (element) {
case EXPORTS: parseFilterList(reader, exportsBuilder); break;
case DEPENDENCIES: parseDependencies(reader, specBuilder); break;
case MAIN_CLASS: parseMainClass(reader, specBuilder); break;
case RESOURCES: parseResources(factory, rootPath, reader, specBuilder); break;
case PROPERTIES: parseProperties(reader, specBuilder); break;
default: throw unexpectedContent(reader);
}
break;
}
default: {
throw unexpectedContent(reader);
}
}
}
throw endOfDocument(reader.getLocation());
}

jboss7 加载module过程的更多相关文章

  1. 动态加载JS过程中如何判断JS加载完成

    在正常的加载过程中,js文件的加载是同步的,也就是说在js加载的过程中,浏览器会阻塞接下来的内容的解析.这时候,动态加载便显得尤为重要了,由于它是异步加载,因此,它可以在后台自动下载,并不会妨碍其它内 ...

  2. Prism 学习:从配置文件中加载 Module

    之前我们已经了解过,如何从指定的目录中来加载 Module(原文),现在我们来看,如何从应用程序的配置文件中来加载 Module.以这种方式来加载 Module 的优点包括:1. 被加载的 Modul ...

  3. Prism 学习:从本地目录加载 Module

    在 Prism 中,将外部模块加载到主程序有以下几种方式:Code.XAML.配置文件.指定模块目录:其中,如果要使用 Code 方式来加载 Module,则需要将该 Module 引用到当前项目中: ...

  4. linux内核被加载的过程

    二,linux内核被加载的过程 一,linux安装时遇到的概念解析 内核必须模块vmlinz(5M左右)不认识硬盘,原本是需要写跟loader中一样的内容,来加载非必要模块. 内核非必要的功能被编译为 ...

  5. log4j的学习和log4j在程序中使用的加载作用过程

    昨天进行代码评审的时候,大家都纠结在了日志信息应该如何输出上,其实我想大家应该一直都在使用log4j来对日志信息进行输出,但是未想应该有很大一部分人对log4j是不了解的,我遇到这个问题的时候也到网上 ...

  6. FreeSWITCH 加载模块过程解读

    今天来学习FreeSWITCH 加载模块过程. 哪些模块需要编译,是由源码下的 modules.conf 文件决定的. 哪些模块在程序启动时自动加载,是由 freeswitch/conf/autolo ...

  7. 创建控制器的方法、控制器加载view过程、控制器view的生命周期、多控制器组合

    在介绍四大对象的那篇博客中,可以基本了解到程序启动的过程: main-->UIApplicationMain-->创建UIApplication的实例和app代理AppDelegate的实 ...

  8. python 动态加载module、class、function

    python作为一种动态解释型语言,在实现各种框架方面具有很大的灵活性. 最近在研究python web框架,发现各种框架中需要显示的定义各种路由和Handler的映射,如果想要实现并维护复杂的web ...

  9. bash启动时加载配置文件过程

    本文目录: 1.1 判断是否交互式.是否登录式 1.2 几种常见的bash启动方式 1.3 加载bash环境配置文件 当用户登录系统时,会加载各种bash配置文件,还会设置或清空一系列变量,有时还会执 ...

随机推荐

  1. Android热更新开源项目Tinker集成实践总结

    前言 最近项目集成了Tinker,开始认为集成会比较简单,但是在实际操作的过程中还是遇到了一些问题,本文就会介绍在集成过程大家基本会遇到的主要问题. 考虑一:后台的选取 目前后台功能可以通过三种方式实 ...

  2. 《asp.net mvc3 高级编程》第二章 控制器

    一.控制器的角色 MVC模式中的控制器(Controller)主要负责响应用户的输入,并且在响应时通常会修改模型(Model).通过这种方式,MVC模式中的控制器主要关注的是应用程序流,输入数据的处理 ...

  3. phpstorm配置xdebug

    首先配置好xdebug 在php.ini里面加入以下配置(修改完注意重启apache或nginx): [xdebug] zend_extension="/usr/local/opt/php5 ...

  4. Windows环境下 配置memcached (php)

    memcached就不用介绍了-- 1:在Windows下安装memcached服务端软件,已经下载并上传云盘  ---传送门 记得带钥匙:ykrc 解压缩后里面的安装说明内有安装教程. 2:软件安装 ...

  5. 表单数据校检方法 onsubmit()的使用?

    在项目中为一个表单(from)编写onsubmit()脚本的时候,经常需要验证表单中数据的合法性 所以常会写道:<form action="/admin/addUser.do" ...

  6. APP的测试过程和重点

    APP的测试过程和重点 1.首先是测试资源确认及准备 (1)产品需求文档.产品原型图.接口说明文档以及设计说明文档等应齐全: (2)测试设备及工具的准备:IOS和andriod不同版本的真机,以及相关 ...

  7. Scut:SocketListener 的解析

    大致浏览了一遍,Scut 的网络模型采用的是 SAEA 模型, 它是 .NET Framework 3.5 开始支持的一种支持高性能 Socket 通信的实现. 通过分析 Scut 的套接字监听控制, ...

  8. python中快速删除实例对象中的所有属性

    def DeleteObjectAllProperties(objectInstance): if not objectInstance: return listPro =[key for key i ...

  9. JAVA简单的UI设计

    手写代码,还是痛苦点,但对布局有再深入的流程理解, 全IDE会更快速.. package SwingGui.sky.com; import javax.swing.*; import java.awt ...

  10. 主流屏幕对比:IPS/LTPS/CGS/IGZO/AMOLED

    IPS.LTPS.CGS.IGZO.AMOLED都是什么屏幕又有什么区别?目前的手机屏幕技术实在太多,本文旨在介绍各种面板以及屏幕技术,便于大家更好地进行区分. 近年来手机屏幕技术层出不穷,早在几年前 ...