001
014
015 package com.liferay.portal.events;
016
017 import com.liferay.portal.deploy.DeployUtil;
018 import com.liferay.portal.deploy.messaging.RequiredPluginsMessageListener;
019 import com.liferay.portal.jcr.JCRFactoryUtil;
020 import com.liferay.portal.kernel.deploy.auto.AutoDeployDir;
021 import com.liferay.portal.kernel.deploy.auto.AutoDeployListener;
022 import com.liferay.portal.kernel.deploy.auto.AutoDeployUtil;
023 import com.liferay.portal.kernel.deploy.hot.HotDeployListener;
024 import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
025 import com.liferay.portal.kernel.deploy.sandbox.SandboxDeployDir;
026 import com.liferay.portal.kernel.deploy.sandbox.SandboxDeployListener;
027 import com.liferay.portal.kernel.deploy.sandbox.SandboxDeployUtil;
028 import com.liferay.portal.kernel.events.SimpleAction;
029 import com.liferay.portal.kernel.javadoc.JavadocManagerUtil;
030 import com.liferay.portal.kernel.jsonwebservice.JSONWebServiceActionsManagerUtil;
031 import com.liferay.portal.kernel.log.Log;
032 import com.liferay.portal.kernel.log.LogFactoryUtil;
033 import com.liferay.portal.kernel.scheduler.SchedulerEngineHelperUtil;
034 import com.liferay.portal.kernel.scheduler.SchedulerEntry;
035 import com.liferay.portal.kernel.scheduler.SchedulerEntryImpl;
036 import com.liferay.portal.kernel.scheduler.StorageType;
037 import com.liferay.portal.kernel.scheduler.TimeUnit;
038 import com.liferay.portal.kernel.scheduler.TriggerType;
039 import com.liferay.portal.kernel.util.GetterUtil;
040 import com.liferay.portal.kernel.util.InfrastructureUtil;
041 import com.liferay.portal.kernel.util.InstanceFactory;
042 import com.liferay.portal.kernel.util.PropsKeys;
043 import com.liferay.portal.kernel.util.ServerDetector;
044 import com.liferay.portal.kernel.util.StringPool;
045 import com.liferay.portal.kernel.util.SystemProperties;
046 import com.liferay.portal.kernel.util.Validator;
047 import com.liferay.portal.pop.POPServerUtil;
048 import com.liferay.portal.spring.context.PortalContextLoaderListener;
049 import com.liferay.portal.struts.AuthPublicPathRegistry;
050 import com.liferay.portal.util.BrowserLauncher;
051 import com.liferay.portal.util.ClassLoaderUtil;
052 import com.liferay.portal.util.PrefsPropsUtil;
053 import com.liferay.portal.util.PropsUtil;
054 import com.liferay.portal.util.PropsValues;
055
056 import java.io.File;
057
058 import java.util.ArrayList;
059 import java.util.List;
060
061 import org.jamwiki.Environment;
062
063
066 public class GlobalStartupAction extends SimpleAction {
067
068 public static List<AutoDeployListener> getAutoDeployListeners(
069 boolean reset) {
070
071 if ((_autoDeployListeners != null) && !reset) {
072 return _autoDeployListeners;
073 }
074
075 List<AutoDeployListener> autoDeployListeners =
076 new ArrayList<AutoDeployListener>();
077
078 String[] autoDeployListenerClassNames = PropsUtil.getArray(
079 PropsKeys.AUTO_DEPLOY_LISTENERS);
080
081 for (String autoDeployListenerClassName :
082 autoDeployListenerClassNames) {
083
084 try {
085 if (_log.isDebugEnabled()) {
086 _log.debug("Instantiating " + autoDeployListenerClassName);
087 }
088
089 AutoDeployListener autoDeployListener =
090 (AutoDeployListener)InstanceFactory.newInstance(
091 autoDeployListenerClassName);
092
093 autoDeployListeners.add(autoDeployListener);
094 }
095 catch (Exception e) {
096 _log.error(e);
097 }
098 }
099
100 _autoDeployListeners = autoDeployListeners;
101
102 return _autoDeployListeners;
103 }
104
105 public static List<HotDeployListener> getHotDeployListeners() {
106 if (_hotDeployListeners != null) {
107 return _hotDeployListeners;
108 }
109
110 List<HotDeployListener> hotDeployListeners =
111 new ArrayList<HotDeployListener>();
112
113 String[] hotDeployListenerClassNames = PropsUtil.getArray(
114 PropsKeys.HOT_DEPLOY_LISTENERS);
115
116 for (String hotDeployListenerClassName : hotDeployListenerClassNames) {
117 try {
118 if (_log.isDebugEnabled()) {
119 _log.debug("Instantiating " + hotDeployListenerClassName);
120 }
121
122 HotDeployListener hotDeployListener =
123 (HotDeployListener)InstanceFactory.newInstance(
124 hotDeployListenerClassName);
125
126 hotDeployListeners.add(hotDeployListener);
127 }
128 catch (Exception e) {
129 _log.error(e);
130 }
131 }
132
133 _hotDeployListeners = hotDeployListeners;
134
135 return _hotDeployListeners;
136 }
137
138 public static List<SandboxDeployListener> getSandboxDeployListeners() {
139 List<SandboxDeployListener> sandboxDeployListeners =
140 new ArrayList<SandboxDeployListener>();
141
142 String[] sandboxDeployListenerClassNames = PropsUtil.getArray(
143 PropsKeys.SANDBOX_DEPLOY_LISTENERS);
144
145 for (String sandboxDeployListenerClassName :
146 sandboxDeployListenerClassNames) {
147
148 try {
149 if (_log.isDebugEnabled()) {
150 _log.debug(
151 "Instantiating " + sandboxDeployListenerClassName);
152 }
153
154 SandboxDeployListener sandboxDeployListener =
155 (SandboxDeployListener)InstanceFactory.newInstance(
156 sandboxDeployListenerClassName);
157
158 sandboxDeployListeners.add(sandboxDeployListener);
159 }
160 catch (Exception e) {
161 _log.error(e);
162 }
163 }
164
165 return sandboxDeployListeners;
166 }
167
168 @Override
169 public void run(String[] ids) {
170
171
172
173 try {
174 File deployDir = new File(
175 PrefsPropsUtil.getString(
176 PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
177 PropsValues.AUTO_DEPLOY_DEPLOY_DIR));
178 File destDir = new File(DeployUtil.getAutoDeployDestDir());
179 long interval = PrefsPropsUtil.getLong(
180 PropsKeys.AUTO_DEPLOY_INTERVAL,
181 PropsValues.AUTO_DEPLOY_INTERVAL);
182
183 List<AutoDeployListener> autoDeployListeners =
184 getAutoDeployListeners(false);
185
186 AutoDeployDir autoDeployDir = new AutoDeployDir(
187 AutoDeployDir.DEFAULT_NAME, deployDir, destDir, interval,
188 autoDeployListeners);
189
190 if (PrefsPropsUtil.getBoolean(
191 PropsKeys.AUTO_DEPLOY_ENABLED,
192 PropsValues.AUTO_DEPLOY_ENABLED)) {
193
194 if (_log.isInfoEnabled()) {
195 _log.info("Registering auto deploy directories");
196 }
197
198 AutoDeployUtil.registerDir(autoDeployDir);
199 }
200 else {
201 if (_log.isInfoEnabled()) {
202 _log.info("Not registering auto deploy directories");
203 }
204 }
205 }
206 catch (Exception e) {
207 _log.error(e);
208 }
209
210
211
212 if (_log.isDebugEnabled()) {
213 _log.debug("Registering hot deploy listeners");
214 }
215
216 for (HotDeployListener hotDeployListener : getHotDeployListeners()) {
217 HotDeployUtil.registerListener(hotDeployListener);
218 }
219
220
221
222 try {
223 if (PrefsPropsUtil.getBoolean(
224 PropsKeys.SANDBOX_DEPLOY_ENABLED,
225 PropsValues.SANDBOX_DEPLOY_ENABLED)) {
226
227 if (_log.isInfoEnabled()) {
228 _log.info("Registering sandbox deploy directories");
229 }
230
231 File deployDir = new File(
232 PrefsPropsUtil.getString(
233 PropsKeys.SANDBOX_DEPLOY_DIR,
234 PropsValues.SANDBOX_DEPLOY_DIR));
235 long interval = PrefsPropsUtil.getLong(
236 PropsKeys.SANDBOX_DEPLOY_INTERVAL,
237 PropsValues.SANDBOX_DEPLOY_INTERVAL);
238
239 List<SandboxDeployListener> sandboxDeployListeners =
240 getSandboxDeployListeners();
241
242 SandboxDeployDir sandboxDeployDir = new SandboxDeployDir(
243 SandboxDeployDir.DEFAULT_NAME, deployDir, interval,
244 sandboxDeployListeners);
245
246 SandboxDeployUtil.registerDir(sandboxDeployDir);
247 }
248 else {
249 if (_log.isInfoEnabled()) {
250 _log.info("Not registering sandbox deploy directories");
251 }
252 }
253 }
254 catch (Exception e) {
255 _log.error(e);
256 }
257
258
259
260 AuthPublicPathRegistry.register(PropsValues.AUTH_PUBLIC_PATHS);
261
262
263
264 try {
265 String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);
266
267 Environment.setValue(Environment.PROP_BASE_FILE_DIR, tmpDir);
268 }
269 catch (Throwable t) {
270 _log.error(t);
271 }
272
273
274
275 ClassLoader contextClassLoader =
276 ClassLoaderUtil.getContextClassLoader();
277
278 JavadocManagerUtil.load(StringPool.BLANK, contextClassLoader);
279
280
281
282 try {
283 JCRFactoryUtil.prepare();
284
285 if (GetterUtil.getBoolean(
286 PropsUtil.get(PropsKeys.JCR_INITIALIZE_ON_STARTUP))) {
287
288 JCRFactoryUtil.initialize();
289 }
290 }
291 catch (Exception e) {
292 _log.error(e);
293 }
294
295
296
297 try {
298 InfrastructureUtil.getDataSource();
299 }
300 catch (Exception e) {
301 _log.error(e, e);
302 }
303
304 try {
305 if (!ServerDetector.isJOnAS()) {
306 InfrastructureUtil.getMailSession();
307 }
308 }
309 catch (Exception e) {
310 if (_log.isWarnEnabled()) {
311 _log.warn(e.getMessage());
312 }
313 }
314
315
316
317 JSONWebServiceActionsManagerUtil.registerServletContext(
318 PortalContextLoaderListener.getPortalServletContextPath());
319
320
321
322 try {
323 SchedulerEntry schedulerEntry = new SchedulerEntryImpl();
324
325 schedulerEntry.setEventListenerClass(
326 RequiredPluginsMessageListener.class.getName());
327 schedulerEntry.setTimeUnit(TimeUnit.MINUTE);
328 schedulerEntry.setTriggerType(TriggerType.SIMPLE);
329 schedulerEntry.setTriggerValue(1);
330
331 SchedulerEngineHelperUtil.schedule(
332 schedulerEntry, StorageType.MEMORY, null, 0);
333 }
334 catch (Exception e) {
335 _log.error(e, e);
336 }
337
338
339
340 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
341 POPServerUtil.start();
342 }
343
344
345
346 if (Validator.isNotNull(PropsValues.BROWSER_LAUNCHER_URL)) {
347 Thread browserLauncherThread = new Thread(new BrowserLauncher());
348
349 browserLauncherThread.start();
350 }
351 }
352
353 private static Log _log = LogFactoryUtil.getLog(GlobalStartupAction.class);
354
355 private static List<AutoDeployListener> _autoDeployListeners;
356 private static List<HotDeployListener> _hotDeployListeners;
357
358 }