这篇文章继续对Liferay启动过程的processStartupEvents()方法进行分析。

在初始化完集群节点和定时器之后,Liferay开始校验数据库:

 

(12)校验数据库:

 
  
  1. // Verify 
  2.  
  3.         if (_log.isDebugEnabled()) { 
  4.             _log.debug("Verify database"); 
  5.         } 
  6.  
  7.         DBUpgrader.verify(); 

它会去调用DBUpgrader的verify()方法:

 
  
  1. public static void verify() throws Exception { 
  2.  
  3.     // Verify 
  4.  
  5.     Release release = null
  6.  
  7.     try { 
  8.         release = ReleaseLocalServiceUtil.getRelease( 
  9.             ReleaseConstants.DEFAULT_SERVLET_CONTEXT_NAME, 
  10.             ReleaseInfo.getBuildNumber()); 
  11.     } 
  12.     catch (PortalException pe) { 
  13.         release = ReleaseLocalServiceUtil.addRelease( 
  14.             ReleaseConstants.DEFAULT_SERVLET_CONTEXT_NAME, 
  15.             ReleaseInfo.getBuildNumber()); 
  16.     } 
  17.  
  18.     StartupHelperUtil.verifyProcess(release.isVerified()); 
  19.  
  20.     // Update indexes 
  21.  
  22.     if (StartupHelperUtil.isUpgraded()) { 
  23.         StartupHelperUtil.updateIndexes(); 
  24.     } 
  25.  
  26.     // Update release 
  27.  
  28.     boolean verified = StartupHelperUtil.isVerified(); 
  29.  
  30.     if (release.isVerified()) { 
  31.         verified = true
  32.     } 
  33.  
  34.     ReleaseLocalServiceUtil.updateRelease( 
  35.         release.getReleaseId(), ReleaseInfo.getBuildNumber(), 
  36.         ReleaseInfo.getBuildDate(), verified); 
  37.  
  38.     // Enable database caching after verify 
  39.  
  40.     CacheRegistryUtil.setActive(true); 

要展开又没底了,反正从宏观上看,它主要做校验版本,更新索引,设置校验状态位,启用数据库缓存。

 

(13)JSPFactorySwap

 
  
  1. // Liferay JspFactory 
  2.  
  3.         JspFactorySwapper.swap(); 

就是用在Tomcat中,使用JSPFactoryWrapper来代替JSPFactory:

 
  
  1. public static void swap() { 
  2.         if (!ServerDetector.isTomcat()) { 
  3.             return
  4.         } 
  5.  
  6.         JspFactory jspFactory = JspFactory.getDefaultFactory(); 
  7.  
  8.         if (jspFactory instanceof JspFactoryWrapper) { 
  9.             return
  10.         } 
  11.  
  12.         synchronized (JspFactorySwapper.class) { 
  13.             if (_jspFactoryWrapper == null) { 
  14.                 _jspFactoryWrapper = new JspFactoryWrapper(jspFactory); 
  15.             } 
  16.  
  17.             JspFactory.setDefaultFactory(_jspFactoryWrapper); 
  18.         } 
  19.     } 

因为JSPFactoryWrapper比JSPFactory更强大,具体参见JSPFactoryWrapper类。

 

(14)分析HTML的LoggerFactory

 
  
  1. // Jericho 
  2.  
  3.         CachedLoggerProvider.install(); 

它会去使用net.htmlparser.jericho.LoggerFactory这个开源项目的日志器:

 
  
  1. public static void install() throws Exception { 
  2.         Class<?> clazz = Class.forName("net.htmlparser.jericho.LoggerFactory"); 
  3.  
  4.         Method method = ReflectionUtil.getDeclaredMethod( 
  5.             clazz, "getDefaultLoggerProvider"); 
  6.  
  7.         LoggerProvider loggerProvider = (LoggerProvider)method.invoke(null); 
  8.  
  9.         CachedLoggerProvider cachedLoggerProvider = new CachedLoggerProvider( 
  10.             loggerProvider); 
  11.  
  12.         Config.LoggerProvider = cachedLoggerProvider; 
  13.     } 

具体信息参见http://sourceforge.net/projects/jerichohtml/