1
22
23 package com.liferay.portal.events;
24
25 import com.liferay.mail.messaging.MailMessageListener;
26 import com.liferay.portal.comm.CommLink;
27 import com.liferay.portal.deploy.DeployUtil;
28 import com.liferay.portal.jcr.JCRFactoryUtil;
29 import com.liferay.portal.kernel.deploy.auto.AutoDeployDir;
30 import com.liferay.portal.kernel.deploy.auto.AutoDeployListener;
31 import com.liferay.portal.kernel.deploy.auto.AutoDeployUtil;
32 import com.liferay.portal.kernel.deploy.hot.HotDeployListener;
33 import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
34 import com.liferay.portal.kernel.events.SimpleAction;
35 import com.liferay.portal.kernel.jndi.PortalJNDIUtil;
36 import com.liferay.portal.kernel.messaging.Destination;
37 import com.liferay.portal.kernel.messaging.DestinationNames;
38 import com.liferay.portal.kernel.messaging.MessageBusUtil;
39 import com.liferay.portal.kernel.messaging.ParallelDestination;
40 import com.liferay.portal.kernel.messaging.SerialDestination;
41 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
42 import com.liferay.portal.kernel.util.GetterUtil;
43 import com.liferay.portal.kernel.util.ServerDetector;
44 import com.liferay.portal.liveusers.messaging.LiveUsersMessageListener;
45 import com.liferay.portal.pop.POPServerUtil;
46 import com.liferay.portal.scheduler.SchedulerEngineImpl;
47 import com.liferay.portal.scheduler.quartz.QuartzSchedulerEngineUtil;
48 import com.liferay.portal.util.PrefsPropsUtil;
49 import com.liferay.portal.util.PropsKeys;
50 import com.liferay.portal.util.PropsUtil;
51 import com.liferay.portal.util.PropsValues;
52 import com.liferay.portlet.messageboards.messaging.MBMessageListener;
53 import com.liferay.portlet.wiki.messaging.WikiMessageListener;
54
55 import java.io.File;
56
57 import java.util.ArrayList;
58 import java.util.List;
59
60 import org.apache.commons.logging.Log;
61 import org.apache.commons.logging.LogFactory;
62
63
69 public class GlobalStartupAction extends SimpleAction {
70
71 public static List<AutoDeployListener> getAutoDeployListeners() {
72 List<AutoDeployListener> list = new ArrayList<AutoDeployListener>();
73
74 String[] autoDeployListeners =
75 PropsUtil.getArray(PropsKeys.AUTO_DEPLOY_LISTENERS);
76
77 for (int i = 0; i < autoDeployListeners.length; i++) {
78 try {
79 if (_log.isDebugEnabled()) {
80 _log.debug("Instantiating " + autoDeployListeners[i]);
81 }
82
83 AutoDeployListener autoDeployListener =
84 (AutoDeployListener)Class.forName(
85 autoDeployListeners[i]).newInstance();
86
87 list.add(autoDeployListener);
88 }
89 catch (Exception e) {
90 _log.error(e);
91 }
92 }
93
94 return list;
95 }
96
97 public static List<HotDeployListener> getHotDeployListeners() {
98 List<HotDeployListener> list = new ArrayList<HotDeployListener>();
99
100 String[] hotDeployListeners =
101 PropsUtil.getArray(PropsKeys.HOT_DEPLOY_LISTENERS);
102
103 for (int i = 0; i < hotDeployListeners.length; i++) {
104 try {
105 if (_log.isDebugEnabled()) {
106 _log.debug("Instantiating " + hotDeployListeners[i]);
107 }
108
109 HotDeployListener hotDeployListener =
110 (HotDeployListener)Class.forName(
111 hotDeployListeners[i]).newInstance();
112
113 list.add(hotDeployListener);
114 }
115 catch (Exception e) {
116 _log.error(e);
117 }
118 }
119
120 return list;
121 }
122
123 public void run(String[] ids) {
124
125
127 if (_log.isDebugEnabled()) {
128 _log.debug("Registering hot deploy listeners");
129 }
130
131 for (HotDeployListener hotDeployListener : getHotDeployListeners()) {
132 HotDeployUtil.registerListener(hotDeployListener);
133 }
134
135
137 try {
138 if (PrefsPropsUtil.getBoolean(
139 PropsKeys.AUTO_DEPLOY_ENABLED,
140 PropsValues.AUTO_DEPLOY_ENABLED)) {
141
142 if (_log.isInfoEnabled()) {
143 _log.info("Registering auto deploy directories");
144 }
145
146 File deployDir = new File(
147 PrefsPropsUtil.getString(
148 PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
149 PropsValues.AUTO_DEPLOY_DEPLOY_DIR));
150 File destDir = new File(DeployUtil.getAutoDeployDestDir());
151 long interval = PrefsPropsUtil.getLong(
152 PropsKeys.AUTO_DEPLOY_INTERVAL,
153 PropsValues.AUTO_DEPLOY_INTERVAL);
154 int blacklistThreshold = PrefsPropsUtil.getInteger(
155 PropsKeys.AUTO_DEPLOY_BLACKLIST_THRESHOLD,
156 PropsValues.AUTO_DEPLOY_BLACKLIST_THRESHOLD);
157
158 List<AutoDeployListener> autoDeployListeners =
159 getAutoDeployListeners();
160
161 AutoDeployDir autoDeployDir = new AutoDeployDir(
162 "defaultAutoDeployDir", deployDir, destDir, interval,
163 blacklistThreshold, autoDeployListeners);
164
165 AutoDeployUtil.registerDir(autoDeployDir);
166 }
167 else {
168 if (_log.isInfoEnabled()) {
169 _log.info("Not registering auto deploy directories");
170 }
171 }
172 }
173 catch (Exception e) {
174 _log.error(e);
175 }
176
177
179 try {
180 JCRFactoryUtil.prepare();
181
182 if (GetterUtil.getBoolean(PropsUtil.get(
183 PropsKeys.JCR_INITIALIZE_ON_STARTUP))) {
184
185 JCRFactoryUtil.initialize();
186 }
187 }
188 catch (Exception e) {
189 _log.error(e);
190 }
191
192
194 CommLink.getInstance();
195
196
198 try {
199 PortalJNDIUtil.getDataSource();
200 }
201 catch (Exception e) {
202 _log.error(e, e);
203 }
204
205 try {
206 if (!ServerDetector.isJOnAS()) {
207 PortalJNDIUtil.getMailSession();
208 }
209 }
210 catch (Exception e) {
211 if (_log.isWarnEnabled()) {
212 _log.warn(e.getMessage());
213 }
214 }
215
216
218 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
219 POPServerUtil.start();
220 }
221
222
224 try {
225 QuartzSchedulerEngineUtil.init();
226 }
227 catch (Exception e) {
228 _log.error(e, e);
229 }
230
231 SchedulerEngineUtil.init(new SchedulerEngineImpl());
232
233
235 populateMessageBus();
236 }
237
238 protected void populateMessageBus() {
239
240
242 Destination liveUsersDestination = new SerialDestination(
243 DestinationNames.LIVE_USERS);
244
245 MessageBusUtil.addDestination(liveUsersDestination);
246
247 MessageBusUtil.registerMessageListener(
248 liveUsersDestination.getName(), new LiveUsersMessageListener());
249
250
252 Destination mailDestination = new ParallelDestination(
253 DestinationNames.MAIL);
254
255 MessageBusUtil.addDestination(mailDestination);
256
257 MessageBusUtil.registerMessageListener(
258 mailDestination.getName(), new MailMessageListener());
259
260
262 Destination messageBoardsDestination = new ParallelDestination(
263 DestinationNames.MESSAGE_BOARDS);
264
265 MessageBusUtil.addDestination(messageBoardsDestination);
266
267 MessageBusUtil.registerMessageListener(
268 messageBoardsDestination.getName(), new MBMessageListener());
269
270
272 Destination wikiDestination = new ParallelDestination(
273 DestinationNames.WIKI);
274
275 MessageBusUtil.addDestination(wikiDestination);
276
277 MessageBusUtil.registerMessageListener(
278 wikiDestination.getName(), new WikiMessageListener());
279 }
280
281 private static Log _log = LogFactory.getLog(GlobalStartupAction.class);
282
283 }