Liferay 启动过程分析3-处理启动事件(第一部分)
2012-06-22 11:48
513 查看
在MainServlet启动Struts中央控制器之后第一件事情就是去处理启动事件:
它会去调用StartupAction中的run方法,进而调用doRun()方法,这里又做了很多事情:
(1)它在控制台打印出产品版本信息:
这个版本信息,可以从ReleaseInfo类中得到:
[/code]
这些常量都可以在ReleaseInfo类找到:所以控制台中显示:
(2)清空锁信息:
它会调用LockLocalServiceUtil中的clear()方法:
进而调用LockLocalServiceImpl类中的clear()方法:
进而调用LocalPersistenceImpl类的removeByLtExpirationDate方法:
它会从数据库中移除所有到期的锁,以当前日期为标准,下面就不展开了。
(3)关闭所有的hook:
它让当前应用的运行时去关闭所有的Hook:
每个Hook都开启一个新的Thread来关闭,它实现Runnable接口,仅仅做一些打印工作:
而这些hook都会添加到Liferay应用的运行时中,运行时会先检查是否有shutdown hook的权限,然后再做shutdown hook的事情:
递归找下去,会发现这个permission定义在%LIFERAY_HOME%/tomcat-7.0.23/conf/catalina.policy中,所以我们拥有这个权限:
之后,就把hook添加到ApplicationShutdownHooks的hashmap中来关闭:
(4)配置Security Manager
它会先检查SecurityManager的策略:
它的key来自PropsKeys接口:
最终我们去访问portal.properties可以看到:
所以,它用的是"smart"策略,所以执行下面代码:
因为我们的Server用的是tomcat,而不是websphere,所以我们执行else代码段,也就是我们的portalSecurityManagerStrategy用的是"default",这种情况下使用tomcat应用服务器的安全策略。
protected void processStartupEvents() throws Exception { StartupAction startupAction = new StartupAction(); startupAction.run(null); }
它会去调用StartupAction中的run方法,进而调用doRun()方法,这里又做了很多事情:
(1)它在控制台打印出产品版本信息:
// Print release information System.out.println("Starting " + ReleaseInfo.getReleaseInfo());
这个版本信息,可以从ReleaseInfo类中得到:
public static final String getReleaseInfo() { return releaseInfo; } [code]static String releaseInfo = releaseInfoPrefix + name + " " + versionDisplayName + " (" + codeName + " / Build " + build + " / " + date + ")" + releaseInfoSuffix;
[/code]
这些常量都可以在ReleaseInfo类找到:所以控制台中显示:
Starting Liferay Portal Community Edition 6.1.0 CE (Paton / Build 6100 / January 6, 2012)
(2)清空锁信息:
try { LockLocalServiceUtil.clear(); }
它会调用LockLocalServiceUtil中的clear()方法:
public static void clear() throws com.liferay.portal.kernel.exception.SystemException { getService().clear(); }
进而调用LockLocalServiceImpl类中的clear()方法:
public void clear() throws SystemException { lockPersistence.removeByLtExpirationDate(new Date()); }
进而调用LocalPersistenceImpl类的removeByLtExpirationDate方法:
/** * Removes all the locks where expirationDate < ? from the database. * * @param expirationDate the expiration date * @throws SystemException if a system exception occurred */ public void removeByLtExpirationDate(Date expirationDate) throws SystemException { for (Lock lock : findByLtExpirationDate(expirationDate)) { remove(lock); } }
它会从数据库中移除所有到期的锁,以当前日期为标准,下面就不展开了。
(3)关闭所有的hook:
它让当前应用的运行时去关闭所有的Hook:
Runtime runtime = Runtime.getRuntime(); runtime.addShutdownHook(new Thread(new ShutdownHook()));
每个Hook都开启一个新的Thread来关闭,它实现Runnable接口,仅仅做一些打印工作:
public class ShutdownHook implements Runnable { public void run() { if (GetterUtil.getBoolean( System.getProperty("shutdown.hook.print.full.thread.dump"))) { printFullThreadDump(); } } ...
而这些hook都会添加到Liferay应用的运行时中,运行时会先检查是否有shutdown hook的权限,然后再做shutdown hook的事情:
public void addShutdownHook(Thread hook) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new RuntimePermission("shutdownHooks")); } ApplicationShutdownHooks.add(hook); }
递归找下去,会发现这个permission定义在%LIFERAY_HOME%/tomcat-7.0.23/conf/catalina.policy中,所以我们拥有这个权限:
... permission java.io.FilePermission "${catalina.base}${file.separator}logs${file.separator}*", "read, write"; permission java.lang.RuntimePermission "shutdownHooks"; permission java.lang.RuntimePermission "getClassLoader"; permission java.lang.RuntimePermission "setContextClassLoader"; ...
之后,就把hook添加到ApplicationShutdownHooks的hashmap中来关闭:
static { Shutdown.add(1 /* shutdown hook invocation order */, new Runnable() { public void run() { runHooks(); } }); }
(4)配置Security Manager
// Security manager String portalSecurityManagerStrategy = PropsValues.PORTAL_SECURITY_MANAGER_STRATEGY; if (portalSecurityManagerStrategy.equals("smart")) { if (ServerDetector.isWebSphere()) { portalSecurityManagerStrategy = "none"; } else { portalSecurityManagerStrategy = "default"; } } if (portalSecurityManagerStrategy.equals("liferay")) { if (System.getSecurityManager() == null) { System.setSecurityManager(new PortalSecurityManager()); } } else if (portalSecurityManagerStrategy.equals("none")) { System.setSecurityManager(null); }
它会先检查SecurityManager的策略:
public static final String PORTAL_SECURITY_MANAGER_STRATEGY = PropsUtil.get(PropsKeys.PORTAL_SECURITY_MANAGER_STRATEGY);
它的key来自PropsKeys接口:
public static final String PORTAL_SECURITY_MANAGER_STRATEGY = "portal.security.manager.strategy";
最终我们去访问portal.properties可以看到:
## ## Security Manager ## # # Set this property to "default" to use the default security manager # configured by the application server. A security manager will not be used # if the application server did not configure one. # # Set this property to "liferay" to use Liferay's security manager if the # application server has not configured a security manager. # # Set this property to "none" to explicitly remove the security manager # regardless of whether one is configured. This ensures that the portal is # run in a JVM without a security manager. # # Set this property to "smart" to allow the portal decide which strategy to # use based on which application server it is on. # portal.security.manager.strategy=smart
所以,它用的是"smart"策略,所以执行下面代码:
if (portalSecurityManagerStrategy.equals("smart")) { if (ServerDetector.isWebSphere()) { portalSecurityManagerStrategy = "none"; } else { portalSecurityManagerStrategy = "default"; } }
因为我们的Server用的是tomcat,而不是websphere,所以我们执行else代码段,也就是我们的portalSecurityManagerStrategy用的是"default",这种情况下使用tomcat应用服务器的安全策略。
相关文章推荐
- Liferay 启动过程分析3-处理启动事件(第三部分)
- Liferay 启动过程分析3-处理启动事件(第四部分)
- Liferay 启动过程分析3-处理启动事件(第二部分)
- Liferay 启动过程分析12-处理全局启动事件
- Android系统之事件处理子系统启动过程的学习和分析
- Windows XP \Windows 2003启动过程的学习及故障分析处理(一)
- Windows XP \Windows 2003启动过程的学习及故障分析处理(六B)
- Spring Boot启动过程源码分析(二)事件监听器
- Windows XP \Windows 2003启动过程的学习及故障分析处理(八)终极篇
- linux input子系统分析--子系统核心.事件处理层.事件传递过程
- Windows XP \Windows 2003启动过程的学习及故障分析处理(二)
- Windows XP \Windows 2003启动过程的学习及故障分析处理(六D)
- android 4.0.1 webkit Event 事件处理过程分析
- Liferay 启动过程分析6-初始化Portlets
- Liferay 启动过程分析7-初始化布局模板
- Liferay 启动过程分析13-初始化Resource Action
- 从爬取微博中搜索的热门事件到数据分析处理全过程(一)
- Android事件处理过程分析
- input子系统四之事件处理过程分析
- Liferay 启动过程分析4-初始化Servlet上下文池