1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.events;
24  
25  import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
26  import com.liferay.portal.kernel.events.ActionException;
27  import com.liferay.portal.kernel.events.SimpleAction;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.messaging.MessageBus;
31  import com.liferay.portal.kernel.messaging.MessageBusUtil;
32  import com.liferay.portal.kernel.messaging.sender.MessageSender;
33  import com.liferay.portal.kernel.messaging.sender.SynchronousMessageSender;
34  import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
35  import com.liferay.portal.kernel.util.ReleaseInfo;
36  import com.liferay.portal.kernel.velocity.VelocityEngineUtil;
37  import com.liferay.portal.model.CompanyConstants;
38  import com.liferay.portal.scheduler.SchedulerEngineProxy;
39  import com.liferay.portal.search.lucene.LuceneUtil;
40  import com.liferay.portal.security.lang.PortalSecurityManager;
41  import com.liferay.portal.service.LockLocalServiceUtil;
42  import com.liferay.portal.tools.DBUpgrader;
43  import com.liferay.portal.util.PropsValues;
44  
45  /**
46   * <a href="StartupAction.java.html"><b><i>View Source</i></b></a>
47   *
48   * @author Brian Wing Shun Chan
49   * @author Alexander Chow
50   * @author Raymond Augé
51   */
52  public class StartupAction extends SimpleAction {
53  
54      public void run(String[] ids) throws ActionException {
55          try {
56              doRun(ids);
57          }
58          catch (RuntimeException re) {
59              throw re;
60          }
61          catch (Exception e) {
62              throw new ActionException(e);
63          }
64          finally {
65              LuceneUtil.checkLuceneDir(CompanyConstants.SYSTEM);
66          }
67      }
68  
69      protected void doRun(String[] ids) throws Exception {
70  
71          // Print release information
72  
73          System.out.println("Starting " + ReleaseInfo.getReleaseInfo());
74  
75          // Clear locks
76  
77          try {
78              LockLocalServiceUtil.clear();
79          }
80          catch (Exception e) {
81              if (_log.isWarnEnabled()) {
82                  _log.warn(
83                      "Unable to clear locks because Lock table does not exist");
84              }
85          }
86  
87          // Shutdown hook
88  
89          Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook()));
90  
91          // Security manager
92  
93          if ((System.getSecurityManager() == null) &&
94              (PropsValues.PORTAL_SECURITY_MANAGER_ENABLE)) {
95  
96              System.setSecurityManager(new PortalSecurityManager());
97          }
98  
99          // Velocity
100 
101         VelocityEngineUtil.init();
102 
103         // Upgrade
104 
105         DBUpgrader.upgrade();
106 
107         // Messaging
108 
109         MessageBus messageBus = (MessageBus)PortalBeanLocatorUtil.locate(
110             MessageBus.class.getName());
111         MessageSender messageSender =
112             (MessageSender)PortalBeanLocatorUtil.locate(
113                 MessageSender.class.getName());
114         SynchronousMessageSender synchronousMessageSender =
115             (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
116                 SynchronousMessageSender.class.getName());
117 
118         MessageBusUtil.init(
119             messageBus, messageSender, synchronousMessageSender);
120 
121         // Scheduler
122 
123         SchedulerEngineUtil.init(new SchedulerEngineProxy());
124 
125         SchedulerEngineUtil.start();
126 
127         // Verify
128 
129         DBUpgrader.verify();
130     }
131 
132     private static Log _log = LogFactoryUtil.getLog(StartupAction.class);
133 
134 }