浅析Tomcat之HostConfig
HostConfig主要承担虚拟主机启动是部署应用的作用.其中可以分解为3个类型的应用.在它的实现中主要分解为3个方法和内部类来解决.部署应用也就是动态在代码中生成Host的子容器Context.也就是一个app和一个Context对应. 我们知道deployApps这个方法把应用的部署分解到deployDescriptors,deployWARs,deployDirectories中.分别对应了3中形式的应用.那么我们先看下deployDescriptors
成都创新互联服务项目包括漳州网站建设、漳州网站制作、漳州网页制作以及漳州网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,漳州网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到漳州省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!/** * Deploy XML context descriptors. */ protected void deployDescriptors(File configBase, String[] files) { if (files == null) return; ExecutorService es = host.getStartStopExecutor(); List
protected void deployDescriptor(ContextName cn, File contextXml) { DeployedApplication deployedApp = new DeployedApplication(cn.getName()); // Assume this is a configuration descriptor and deploy it if(log.isInfoEnabled()) { log.info(sm.getString("hostConfig.deployDescriptor", contextXml.getAbsolutePath())); } Context context = null; boolean isExternalWar = false; boolean isExternal = false; File expandedDocBase = null; try { synchronized (digester) { try { context = (Context) digester.parse(contextXml); } catch (Exception e) { log.error(sm.getString( "hostConfig.deployDescriptor.error", contextXml.getAbsolutePath())); context = new FailedContext(); } finally { digester.reset(); } } Class clazz = Class.forName(host.getConfigClass()); LifecycleListener listener = (LifecycleListener) clazz.newInstance(); context.addLifecycleListener(listener); context.setConfigFile(contextXml.toURI().toURL()); context.setName(cn.getName()); context.setPath(cn.getPath()); context.setWebappVersion(cn.getVersion()); // Add the associated docBase to the redeployed list if it\'s a WAR if (context.getDocBase() != null) { File docBase = new File(context.getDocBase()); if (!docBase.isAbsolute()) { docBase = new File(appBase(), context.getDocBase()); } // If external docBase, register .xml as redeploy first if (!docBase.getCanonicalPath().startsWith( appBase().getAbsolutePath() + File.separator)) { isExternal = true; deployedApp.redeployResources.put( contextXml.getAbsolutePath(), Long.valueOf(contextXml.lastModified())); deployedApp.redeployResources.put(docBase.getAbsolutePath(), Long.valueOf(docBase.lastModified())); if (docBase.getAbsolutePath().toLowerCase(Locale.ENGLISH).endsWith(".war")) { isExternalWar = true; } } else { log.warn(sm.getString("hostConfig.deployDescriptor.localDocBaseSpecified", docBase)); // Ignore specified docBase context.setDocBase(null); } } host.addChild(context); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("hostConfig.deployDescriptor.error", contextXml.getAbsolutePath()), t); } finally { // Get paths for WAR and expanded WAR in appBase ....... } if (context != null && host.findChild(context.getName()) != null) { deployed.put(context.getName(), deployedApp); } } 上述就是在es.submit(new DeployDescriptor(this, cn, contextXml))中的线程中执行的方法.其大意主要也就是把解析出来的app转换成Tomcat中的Context做为Host的子容器.在另外的2个类型的部署应用方法deployWAR,deployDirectory所实现的也是类似的.只不过DeployDescriptor和deployWAR主要解析的是ApplicationContextXml也就是META-INF/context.xml,而deployDirectory主要解析的是ApplicationWebXml也就是/WEB-INF/web.xml其余大体上的流程是一致的.
新闻标题:浅析Tomcat之HostConfig
转载注明:http://scyanting.com/article/cjeeph.html