读懂tomact源码4:Host
tomact的host,StandardHost,以及HostConfig的源代码阅读
·
Host
一个host在tomact中代表一个虚拟host,一般在下列情况下有用的:
- 你希望用拦截器来查看铁定的虚拟host的所有请求;
- 需要在tomact中用一个connector,但是需要多个虚拟host
StandardHost
Properties
- private String[] aliases = new String[0];
private final Object aliasesLock = new Object();
当前host的别名 - private String appBase = “webapps”;
当前host的应用程序根
private String xmlBase = null;
当前程序的xml的根 - private boolean autoDeploy = true;
host自动部署的标志 - Context相关
private String configClass = “org.apache.catalina.startup.ContextConfig”;
The Java class name of the default context configuration class for deployed web applications.
private String contextClass = “org.apache.catalina.core.StandardContext”;
The Java class name of the default Context implementation class for deployed web applications. - private boolean deployOnStartup = true;
当前host启动的标志 - private boolean deployXML = !Globals.IS_SECURITY_ENABLED;
deploy Context XML config files property. - private boolean copyXML = false;
Should XML files be copied to $CATALINA_BASE/conf/<engine>/<host> by default when a web application is deployed?
一般的情况
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"/>
- private String errorReportValveClass = “org.apache.catalina.valves.ErrorReportValve”;
The Java class name of the default error reporter implementation class
for deployed web applications. - private static final String info = “org.apache.catalina.core.StandardHost/1.0”;
The descriptive information string for this implementation. - private boolean unpackWARs = true;
Unpack WARs property. - private String workDir = null;
Work Directory base for applications. - private boolean createDirs = true;
Should we create directories upon startup for appBase and xmlBase - childClassLoaders
private Map<ClassLoader, String> childClassLoaders = new WeakHashMap<ClassLoader, String>();
Track the class loaders for the child web applications so memory leaks can be detected.
14. private Pattern deployIgnore = null;
Any file or directory in appBase that this pattern matches will be ignored by the automatic deployment process (both deployOnStartup autoDeploy).
15. private boolean undeployOldVersions = false;
16. private boolean failCtxIfServletStartFails = false;
Set Properties
在属性的设置方法里,可以看到同一个方法firePropertyChange,我们来看下这个方法.
Reports a boolean bound property update to listeners that have been registered to track updates of all properties or a property with the specified name. No event is fired if old and new values are equal. This is merely a convenience wrapper around the more general
HostConfig
Startup event listener for a Host< that configures the properties of that Host, and the associated defined contexts.
/**
* Deploy applications for any directories or WAR files that are found
* in our "application root" directory.
*/
protected void deployApps() {
File appBase = appBase();
File configBase = configBase();
String[] filteredAppPaths = filterAppPaths(appBase.list());
// Deploy XML descriptors from configBase
deployDescriptors(configBase, configBase.list());
// Deploy WARs
deployWARs(appBase, filteredAppPaths);
// Deploy expanded folders
deployDirectories(appBase, filteredAppPaths);
}
理一下过程:
- Return a File object representing the “application root” directory for our associated Host.
- Return a File object representing the “configuration root” directory for our associated Host.
- Filter the list of application file paths to remove those that match the regular expression defined by Host.getDeployIgnore()
- Deploy XML context descriptors
- Deploy WAR files
- Deploy directories
HostConfig的内容,以后会详细的学习下.
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献1条内容
所有评论(0)