1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.scheduler.SchedulerEngineProxy;
38  import com.liferay.portal.security.lang.PortalSecurityManager;
39  import com.liferay.portal.service.LockLocalServiceUtil;
40  import com.liferay.portal.tools.DBUpgrader;
41  import com.liferay.portal.util.PropsValues;
42  
43  /**
44   * <a href="StartupAction.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Brian Wing Shun Chan
47   * @author Alexander Chow
48   * @author Raymond Augé
49   */
50  public class StartupAction extends SimpleAction {
51  
52      public void run(String[] ids) throws ActionException {
53          try {
54              doRun(ids);
55          }
56          catch (RuntimeException re) {
57              throw re;
58          }
59          catch (Exception e) {
60              throw new ActionException(e);
61          }
62      }
63  
64      protected void doRun(String[] ids) throws Exception {
65  
66          // Print release information
67  
68          System.out.println("Starting " + ReleaseInfo.getReleaseInfo());
69  
70          // Clear locks
71  
72          try {
73              LockLocalServiceUtil.clear();
74          }
75          catch (Exception e) {
76              if (_log.isWarnEnabled()) {
77                  _log.warn(
78                      "Unable to clear locks because Lock table does not exist");
79              }
80          }
81  
82          // Shutdown hook
83  
84          Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook()));
85  
86          // Security manager
87  
88          if ((System.getSecurityManager() == null) &&
89              (PropsValues.PORTAL_SECURITY_MANAGER_ENABLE)) {
90  
91              System.setSecurityManager(new PortalSecurityManager());
92          }
93  
94          // Velocity
95  
96          VelocityEngineUtil.init();
97  
98          // Upgrade
99  
100         DBUpgrader.upgrade();
101 
102         // Messaging
103 
104         MessageBus messageBus = (MessageBus)PortalBeanLocatorUtil.locate(
105             MessageBus.class.getName());
106         MessageSender messageSender =
107             (MessageSender)PortalBeanLocatorUtil.locate(
108                 MessageSender.class.getName());
109         SynchronousMessageSender synchronousMessageSender =
110             (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
111                 SynchronousMessageSender.class.getName());
112 
113         MessageBusUtil.init(
114             messageBus, messageSender, synchronousMessageSender);
115 
116         // Scheduler
117 
118         SchedulerEngineUtil.init(new SchedulerEngineProxy());
119 
120         SchedulerEngineUtil.start();
121 
122         // Verify
123 
124         DBUpgrader.verify();
125     }
126 
127     private static Log _log = LogFactoryUtil.getLog(StartupAction.class);
128 
129 }