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.events.ActionException;
19  import com.liferay.portal.kernel.events.SimpleAction;
20  import com.liferay.portal.kernel.log.Log;
21  import com.liferay.portal.kernel.log.LogFactoryUtil;
22  import com.liferay.portal.kernel.messaging.MessageBus;
23  import com.liferay.portal.kernel.messaging.MessageBusUtil;
24  import com.liferay.portal.kernel.messaging.sender.MessageSender;
25  import com.liferay.portal.kernel.messaging.sender.SynchronousMessageSender;
26  import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
27  import com.liferay.portal.kernel.util.ReleaseInfo;
28  import com.liferay.portal.kernel.velocity.VelocityEngineUtil;
29  import com.liferay.portal.scheduler.SchedulerEngineProxy;
30  import com.liferay.portal.security.lang.PortalSecurityManager;
31  import com.liferay.portal.service.LockLocalServiceUtil;
32  import com.liferay.portal.tools.DBUpgrader;
33  import com.liferay.portal.util.PropsValues;
34  
35  /**
36   * <a href="StartupAction.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   * @author Alexander Chow
40   * @author Raymond Augé
41   */
42  public class StartupAction extends SimpleAction {
43  
44      public void run(String[] ids) throws ActionException {
45          try {
46              doRun(ids);
47          }
48          catch (RuntimeException re) {
49              throw re;
50          }
51          catch (Exception e) {
52              throw new ActionException(e);
53          }
54      }
55  
56      protected void doRun(String[] ids) throws Exception {
57  
58          // Print release information
59  
60          System.out.println("Starting " + ReleaseInfo.getReleaseInfo());
61  
62          // Clear locks
63  
64          try {
65              LockLocalServiceUtil.clear();
66          }
67          catch (Exception e) {
68              if (_log.isWarnEnabled()) {
69                  _log.warn(
70                      "Unable to clear locks because Lock table does not exist");
71              }
72          }
73  
74          // Shutdown hook
75  
76          Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook()));
77  
78          // Security manager
79  
80          if ((System.getSecurityManager() == null) &&
81              (PropsValues.PORTAL_SECURITY_MANAGER_ENABLE)) {
82  
83              System.setSecurityManager(new PortalSecurityManager());
84          }
85  
86          // Velocity
87  
88          VelocityEngineUtil.init();
89  
90          // Upgrade
91  
92          DBUpgrader.upgrade();
93  
94          // Messaging
95  
96          MessageBus messageBus = (MessageBus)PortalBeanLocatorUtil.locate(
97              MessageBus.class.getName());
98          MessageSender messageSender =
99              (MessageSender)PortalBeanLocatorUtil.locate(
100                 MessageSender.class.getName());
101         SynchronousMessageSender synchronousMessageSender =
102             (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
103                 SynchronousMessageSender.class.getName());
104 
105         MessageBusUtil.init(
106             messageBus, messageSender, synchronousMessageSender);
107 
108         // Scheduler
109 
110         SchedulerEngineUtil.init(new SchedulerEngineProxy());
111 
112         SchedulerEngineUtil.start();
113 
114         // Verify
115 
116         DBUpgrader.verify();
117     }
118 
119     private static Log _log = LogFactoryUtil.getLog(StartupAction.class);
120 
121 }