1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.events;
16  
17  import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
18  import com.liferay.portal.kernel.cluster.ClusterExecutorUtil;
19  import com.liferay.portal.kernel.events.ActionException;
20  import com.liferay.portal.kernel.events.SimpleAction;
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          if (_log.isDebugEnabled()) {
66              _log.debug("Clear locks");
67          }
68  
69          try {
70              LockLocalServiceUtil.clear();
71          }
72          catch (Exception e) {
73              if (_log.isWarnEnabled()) {
74                  _log.warn(
75                      "Unable to clear locks because Lock table does not exist");
76              }
77          }
78  
79          // Shutdown hook
80  
81          if (_log.isDebugEnabled()) {
82              _log.debug("Add shutdown hook");
83          }
84  
85          Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook()));
86  
87          // Security manager
88  
89          if ((System.getSecurityManager() == null) &&
90              (PropsValues.PORTAL_SECURITY_MANAGER_ENABLE)) {
91  
92              System.setSecurityManager(new PortalSecurityManager());
93          }
94  
95          // Velocity
96  
97          if (_log.isDebugEnabled()) {
98              _log.debug("Initialize Velocity engine");
99          }
100 
101         VelocityEngineUtil.init();
102 
103         // Upgrade
104 
105         if (_log.isDebugEnabled()) {
106             _log.debug("Upgrade database");
107         }
108 
109         DBUpgrader.upgrade();
110 
111         // Messaging
112 
113         if (_log.isDebugEnabled()) {
114             _log.debug("Initialize message bus");
115         }
116 
117         MessageBus messageBus = (MessageBus)PortalBeanLocatorUtil.locate(
118             MessageBus.class.getName());
119         MessageSender messageSender =
120             (MessageSender)PortalBeanLocatorUtil.locate(
121                 MessageSender.class.getName());
122         SynchronousMessageSender synchronousMessageSender =
123             (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
124                 SynchronousMessageSender.class.getName());
125 
126         MessageBusUtil.init(
127             messageBus, messageSender, synchronousMessageSender);
128 
129         // Scheduler
130 
131         if (_log.isDebugEnabled()) {
132             _log.debug("Initialize scheduler engine");
133         }
134 
135         SchedulerEngineUtil.init(new SchedulerEngineProxy());
136 
137         SchedulerEngineUtil.start();
138 
139         // Verify
140 
141         if (_log.isDebugEnabled()) {
142             _log.debug("Verify database");
143         }
144 
145         DBUpgrader.verify();
146 
147         // Cluster executor
148 
149         ClusterExecutorUtil.initialize();
150     }
151 
152     private static Log _log = LogFactoryUtil.getLog(StartupAction.class);
153 
154 }