在Liferay Enterprise中,对于License的使用和控制是十分讲究的,因为lincense决定了产品的使用能力和使用期限,我们现在就来深入分析下license.
License的部署:
首先又要回到Listener了,见所说,在Liferay的MainServlet的启动过程中,当处理全局启动事件时,它会注册所有的antoDeployListener,其中,LicenseAutoDeployListener也位列其中:
auto.deploy.listeners=\ com.liferay.portal.deploy.auto.OSGiAutoDeployListener,\ com.liferay.portal.deploy.auto.ExtAutoDeployListener,\ com.liferay.portal.deploy.auto.HookAutoDeployListener,\ com.liferay.portal.deploy.auto.LayoutTemplateAutoDeployListener,\ com.liferay.portal.deploy.auto.LiferayPackageAutoDeployListener,\ com.liferay.portal.deploy.auto.PortletAutoDeployListener,\ com.liferay.portal.deploy.auto.ThemeAutoDeployListener,\ com.liferay.portal.deploy.auto.WebAutoDeployListener,\ com.liferay.portal.deploy.auto.exploded.tomcat.HookExplodedTomcatListener,\ com.liferay.portal.deploy.auto.exploded.tomcat.LayoutTemplateExplodedTomcatListener,\ com.liferay.portal.deploy.auto.exploded.tomcat.PortletExplodedTomcatListener,\ com.liferay.portal.license.deploy.auto.LicenseAutoDeployListener,com.liferay.portal.deploy.auto.exploded.tomcat.ThemeExplodedTomcatListener所以,当我们初次吧License文件放在$LIFERAY_HOME/deploy目录下,就会触发LicenseAutoDeployListener做出响应,而它实现了AutoDeployListener接口,所以放license文件到deploy目录会触发它的deploy方法:
public void deploy(File paramFile, String paramString) { if (a.isDebugEnabled()) a.debug("Invoking deploy for " + paramFile.getPath()); String str1 = FileUtil.getExtension(paramFile.getName()); if (!str1.equals("xml")) return; try { String str2 = FileUtil.read(paramFile); Document localDocument = SAXReaderUtil.read(str2); Element localElement = localDocument.getRootElement(); String str3 = localElement.getName(); if (!str3.equals("license")) return; } catch (Exception localException) { return; } if (a.isInfoEnabled()) a.info("Copying license for " + paramFile.getPath()); this.b.autoDeploy(paramFile, paramString); }从这里我们可以看到,它05-07行首先会去检查license文件的扩展名是否为xml 。然后第10-13行会利用SAXReadUtil来读取这个文件,并且第14行判定根元素是否为license。然后在22行打印出一行信息(因为默认日志的info级别是开启的,所以我们可以看到这行日志):
06:25:14,380 INFO [LicenseAutoDeployListener:?] Copying license for D:\Liferay_Cluster_Enterprise\Node1\liferay-portal-tomcat-6.1.10-ee-ga1\liferay-portal-6.1.10-ee-ga1\deploy\license-portaldevelopment-developer-6.1-triallicenses.xml最后,第23行它去调用autoDeploy方法来进行部署工作,我们继续跟进。