1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.events;
16  
17  import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
18  import com.liferay.portal.kernel.events.ActionException;
19  import com.liferay.portal.kernel.events.SimpleAction;
20  import com.liferay.portal.kernel.freemarker.FreeMarkerEngineUtil;
21  import com.liferay.portal.kernel.log.Log;
22  import com.liferay.portal.kernel.log.LogFactoryUtil;
23  import com.liferay.portal.kernel.messaging.MessageBus;
24  import com.liferay.portal.kernel.messaging.MessageBusUtil;
25  import com.liferay.portal.kernel.messaging.sender.MessageSender;
26  import com.liferay.portal.kernel.messaging.sender.SynchronousMessageSender;
27  import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
28  import com.liferay.portal.kernel.util.ReleaseInfo;
29  import com.liferay.portal.kernel.velocity.VelocityEngineUtil;
30  import com.liferay.portal.scheduler.SchedulerEngineProxy;
31  import com.liferay.portal.security.lang.PortalSecurityManager;
32  import com.liferay.portal.service.LockLocalServiceUtil;
33  import com.liferay.portal.tools.DBUpgrader;
34  import com.liferay.portal.util.PropsValues;
35  
36  /**
37   * <a href="StartupAction.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   * @author Alexander Chow
41   * @author Raymond Augé
42   */
43  public class StartupAction extends SimpleAction {
44  
45      public void run(String[] ids) throws ActionException {
46          try {
47              doRun(ids);
48          }
49          catch (RuntimeException re) {
50              throw re;
51          }
52          catch (Exception e) {
53              throw new ActionException(e);
54          }
55      }
56  
57      protected void doRun(String[] ids) throws Exception {
58  
59          // Print release information
60  
61          System.out.println("Starting " + ReleaseInfo.getReleaseInfo());
62  
63          // Clear locks
64  
65          try {
66              LockLocalServiceUtil.clear();
67          }
68          catch (Exception e) {
69              if (_log.isWarnEnabled()) {
70                  _log.warn(
71                      "Unable to clear locks because Lock table does not exist");
72              }
73          }
74  
75          // Shutdown hook
76  
77          Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook()));
78  
79          // Security manager
80  
81          if ((System.getSecurityManager() == null) &&
82              (PropsValues.PORTAL_SECURITY_MANAGER_ENABLE)) {
83  
84              System.setSecurityManager(new PortalSecurityManager());
85          }
86  
87          // FreeMarker
88  
89          FreeMarkerEngineUtil.init();
90  
91          // Velocity
92  
93          VelocityEngineUtil.init();
94  
95          // Upgrade
96  
97          DBUpgrader.upgrade();
98  
99          // Messaging
100 
101         MessageBus messageBus = (MessageBus)PortalBeanLocatorUtil.locate(
102             MessageBus.class.getName());
103         MessageSender messageSender =
104             (MessageSender)PortalBeanLocatorUtil.locate(
105                 MessageSender.class.getName());
106         SynchronousMessageSender synchronousMessageSender =
107             (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
108                 SynchronousMessageSender.class.getName());
109 
110         MessageBusUtil.init(
111             messageBus, messageSender, synchronousMessageSender);
112 
113         // Scheduler
114 
115         SchedulerEngineUtil.init(new SchedulerEngineProxy());
116 
117         SchedulerEngineUtil.start();
118 
119         // Verify
120 
121         DBUpgrader.verify();
122     }
123 
124     private static Log _log = LogFactoryUtil.getLog(StartupAction.class);
125 
126 }