001
014
015 package com.liferay.portal.events;
016
017 import com.liferay.portal.cache.ehcache.EhcacheStreamBootstrapCacheLoader;
018 import com.liferay.portal.jericho.CachedLoggerProvider;
019 import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
020 import com.liferay.portal.kernel.cluster.ClusterExecutorUtil;
021 import com.liferay.portal.kernel.cluster.ClusterLinkUtil;
022 import com.liferay.portal.kernel.cluster.ClusterMasterExecutorUtil;
023 import com.liferay.portal.kernel.events.ActionException;
024 import com.liferay.portal.kernel.events.SimpleAction;
025 import com.liferay.portal.kernel.log.Log;
026 import com.liferay.portal.kernel.log.LogFactoryUtil;
027 import com.liferay.portal.kernel.messaging.MessageBus;
028 import com.liferay.portal.kernel.messaging.MessageBusUtil;
029 import com.liferay.portal.kernel.messaging.sender.MessageSender;
030 import com.liferay.portal.kernel.messaging.sender.SynchronousMessageSender;
031 import com.liferay.portal.kernel.nio.intraband.Intraband;
032 import com.liferay.portal.kernel.nio.intraband.SystemDataType;
033 import com.liferay.portal.kernel.nio.intraband.cache.PortalCacheDatagramReceiveHandler;
034 import com.liferay.portal.kernel.nio.intraband.mailbox.MailboxDatagramReceiveHandler;
035 import com.liferay.portal.kernel.nio.intraband.messaging.MessageDatagramReceiveHandler;
036 import com.liferay.portal.kernel.nio.intraband.rpc.RPCDatagramReceiveHandler;
037 import com.liferay.portal.kernel.patcher.PatcherUtil;
038 import com.liferay.portal.kernel.resiliency.mpi.MPIHelperUtil;
039 import com.liferay.portal.kernel.resiliency.spi.SPIUtil;
040 import com.liferay.portal.kernel.resiliency.spi.agent.annotation.Direction;
041 import com.liferay.portal.kernel.resiliency.spi.agent.annotation.DistributedRegistry;
042 import com.liferay.portal.kernel.resiliency.spi.agent.annotation.MatchType;
043 import com.liferay.portal.kernel.scheduler.SchedulerEngineHelperUtil;
044 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
045 import com.liferay.portal.kernel.servlet.JspFactorySwapper;
046 import com.liferay.portal.kernel.template.TemplateManagerUtil;
047 import com.liferay.portal.kernel.util.ReleaseInfo;
048 import com.liferay.portal.kernel.util.StringPool;
049 import com.liferay.portal.kernel.util.StringUtil;
050 import com.liferay.portal.kernel.util.Validator;
051 import com.liferay.portal.plugin.PluginPackageIndexer;
052 import com.liferay.portal.security.lang.DoPrivilegedUtil;
053 import com.liferay.portal.service.BackgroundTaskLocalServiceUtil;
054 import com.liferay.portal.service.LockLocalServiceUtil;
055 import com.liferay.portal.tools.DBUpgrader;
056 import com.liferay.portal.util.WebKeys;
057 import com.liferay.portlet.messageboards.util.MBMessageIndexer;
058
059 import javax.portlet.MimeResponse;
060 import javax.portlet.PortletRequest;
061
062 import org.apache.struts.taglib.tiles.ComponentConstants;
063
064
069 public class StartupAction extends SimpleAction {
070
071 @Override
072 public void run(String[] ids) throws ActionException {
073 try {
074 doRun(ids);
075 }
076 catch (RuntimeException re) {
077 throw re;
078 }
079 catch (Exception e) {
080 throw new ActionException(e);
081 }
082 }
083
084 protected void doRun(String[] ids) throws Exception {
085
086
087
088 System.out.println("Starting " + ReleaseInfo.getReleaseInfo());
089
090
091
092 if (_log.isInfoEnabled() && !PatcherUtil.hasInconsistentPatchLevels()) {
093 String installedPatches = StringUtil.merge(
094 PatcherUtil.getInstalledPatches(), StringPool.COMMA_AND_SPACE);
095
096 if (Validator.isNull(installedPatches)) {
097 _log.info("There are no patches installed");
098 }
099 else {
100 _log.info(
101 "The following patches are installed: " + installedPatches);
102 }
103 }
104
105
106
107 DistributedRegistry.registerDistributed(
108 ComponentConstants.COMPONENT_CONTEXT, Direction.DUPLEX,
109 MatchType.POSTFIX);
110 DistributedRegistry.registerDistributed(
111 MimeResponse.MARKUP_HEAD_ELEMENT, Direction.DUPLEX,
112 MatchType.EXACT);
113 DistributedRegistry.registerDistributed(
114 PortletRequest.LIFECYCLE_PHASE, Direction.DUPLEX, MatchType.EXACT);
115 DistributedRegistry.registerDistributed(WebKeys.class);
116
117 Intraband intraband = MPIHelperUtil.getIntraband();
118
119 intraband.registerDatagramReceiveHandler(
120 SystemDataType.MAILBOX.getValue(),
121 new MailboxDatagramReceiveHandler());
122
123 MessageBus messageBus = (MessageBus)PortalBeanLocatorUtil.locate(
124 MessageBus.class.getName());
125
126 intraband.registerDatagramReceiveHandler(
127 SystemDataType.MESSAGE.getValue(),
128 new MessageDatagramReceiveHandler(messageBus));
129
130 intraband.registerDatagramReceiveHandler(
131 SystemDataType.PORTAL_CACHE.getValue(),
132 new PortalCacheDatagramReceiveHandler());
133 intraband.registerDatagramReceiveHandler(
134 SystemDataType.RPC.getValue(), new RPCDatagramReceiveHandler());
135
136
137
138 if (_log.isDebugEnabled()) {
139 _log.debug("Clear locks");
140 }
141
142 try {
143 LockLocalServiceUtil.clear();
144 }
145 catch (Exception e) {
146 if (_log.isWarnEnabled()) {
147 _log.warn(
148 "Unable to clear locks because Lock table does not exist");
149 }
150 }
151
152
153
154 if (_log.isDebugEnabled()) {
155 _log.debug("Add shutdown hook");
156 }
157
158 Runtime runtime = Runtime.getRuntime();
159
160 runtime.addShutdownHook(new Thread(new ShutdownHook()));
161
162
163
164 if (_log.isDebugEnabled()) {
165 _log.debug("Initialize template manager");
166 }
167
168 TemplateManagerUtil.init();
169
170
171
172 IndexerRegistryUtil.register(new MBMessageIndexer());
173 IndexerRegistryUtil.register(new PluginPackageIndexer());
174
175
176
177 if (_log.isDebugEnabled()) {
178 _log.debug("Upgrade database");
179 }
180
181 DBUpgrader.upgrade();
182
183
184
185 if (_log.isDebugEnabled()) {
186 _log.debug("Initialize message bus");
187 }
188
189 MessageSender messageSender =
190 (MessageSender)PortalBeanLocatorUtil.locate(
191 MessageSender.class.getName());
192 SynchronousMessageSender synchronousMessageSender =
193 (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
194 SynchronousMessageSender.class.getName());
195
196 MessageBusUtil.init(
197 DoPrivilegedUtil.wrap(messageBus),
198 DoPrivilegedUtil.wrap(messageSender),
199 DoPrivilegedUtil.wrap(synchronousMessageSender));
200
201
202
203 ClusterLinkUtil.initialize();
204
205
206
207 ClusterExecutorUtil.initialize();
208
209 if (!SPIUtil.isSPI()) {
210 ClusterMasterExecutorUtil.initialize();
211 }
212
213
214
215 EhcacheStreamBootstrapCacheLoader.start();
216
217
218
219 if (_log.isDebugEnabled()) {
220 _log.debug("Initialize scheduler engine lifecycle");
221 }
222
223 SchedulerEngineHelperUtil.initialize();
224
225
226
227 if (_log.isDebugEnabled()) {
228 _log.debug("Verify database");
229 }
230
231 DBUpgrader.verify();
232
233
234
235 if (!ClusterMasterExecutorUtil.isEnabled()) {
236 BackgroundTaskLocalServiceUtil.cleanUpBackgroundTasks();
237 }
238
239
240
241 JspFactorySwapper.swap();
242
243
244
245 CachedLoggerProvider.install();
246 }
247
248 private static Log _log = LogFactoryUtil.getLog(StartupAction.class);
249
250 }