Host

一个host在tomact中代表一个虚拟host,一般在下列情况下有用的:

  1. 你希望用拦截器来查看铁定的虚拟host的所有请求;
  2. 需要在tomact中用一个connector,但是需要多个虚拟host

StandardHost

Properties

  1. private String[] aliases = new String[0];
    private final Object aliasesLock = new Object();
    当前host的别名
  2. private String appBase = “webapps”;
     当前host的应用程序根
    private String xmlBase = null;
    当前程序的xml的根
  3. private boolean autoDeploy = true;
    host自动部署的标志
  4. 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.
  5. private boolean deployOnStartup = true;
     当前host启动的标志
  6. private boolean deployXML = !Globals.IS_SECURITY_ENABLED;
    deploy Context XML config files property.
  7. 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"/>
  1. private String errorReportValveClass = “org.apache.catalina.valves.ErrorReportValve”;
    The Java class name of the default error reporter implementation class
    for deployed web applications.
  2. private static final String info = “org.apache.catalina.core.StandardHost/1.0”;
    The descriptive information string for this implementation.
  3. private boolean unpackWARs = true;
    Unpack WARs property.
  4. private String workDir = null;
    Work Directory base for applications.
  5. private boolean createDirs = true;
    Should we create directories upon startup for appBase and xmlBase
  6. 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);

    }

理一下过程:

  1. Return a File object representing the “application root” directory for our associated Host.
  2. Return a File object representing the “configuration root” directory for our associated Host.
  3. Filter the list of application file paths to remove those that match the regular expression defined by Host.getDeployIgnore()
  4. Deploy XML context descriptors
  5. Deploy WAR files
  6. Deploy directories
    HostConfig的内容,以后会详细的学习下.
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐