1
22
23 package com.liferay.portal.events;
24
25 import com.liferay.portal.comm.CommLink;
26 import com.liferay.portal.deploy.DeployUtil;
27 import com.liferay.portal.jcr.JCRFactoryUtil;
28 import com.liferay.portal.kernel.deploy.auto.AutoDeployDir;
29 import com.liferay.portal.kernel.deploy.auto.AutoDeployListener;
30 import com.liferay.portal.kernel.deploy.auto.AutoDeployUtil;
31 import com.liferay.portal.kernel.deploy.hot.HotDeployListener;
32 import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
33 import com.liferay.portal.kernel.util.GetterUtil;
34 import com.liferay.portal.kernel.util.InstancePool;
35 import com.liferay.portal.smtp.SMTPServerUtil;
36 import com.liferay.portal.struts.ActionException;
37 import com.liferay.portal.struts.SimpleAction;
38 import com.liferay.portal.util.PrefsPropsUtil;
39 import com.liferay.portal.util.PropsUtil;
40
41 import java.io.File;
42
43 import java.util.ArrayList;
44 import java.util.Iterator;
45 import java.util.List;
46
47 import org.apache.commons.logging.Log;
48 import org.apache.commons.logging.LogFactory;
49
50
56 public class GlobalStartupAction extends SimpleAction {
57
58 public static List getAutoDeployListeners() {
59 List list = new ArrayList();
60
61 String[] autoDeployListeners =
62 PropsUtil.getArray(PropsUtil.AUTO_DEPLOY_LISTENERS);
63
64 for (int i = 0; i < autoDeployListeners.length; i++) {
65 try {
66 if (_log.isDebugEnabled()) {
67 _log.debug("Instantiating " + autoDeployListeners[i]);
68 }
69
70 AutoDeployListener autoDeployListener =
71 (AutoDeployListener)Class.forName(
72 autoDeployListeners[i]).newInstance();
73
74 list.add(autoDeployListener);
75 }
76 catch (Exception e) {
77 _log.error(e);
78 }
79 }
80
81 return list;
82 }
83
84 public static List getHotDeployListeners() {
85 List list = new ArrayList();
86
87 String[] hotDeployListeners =
88 PropsUtil.getArray(PropsUtil.HOT_DEPLOY_LISTENERS);
89
90 for (int i = 0; i < hotDeployListeners.length; i++) {
91 try {
92 if (_log.isDebugEnabled()) {
93 _log.debug("Instantiating " + hotDeployListeners[i]);
94 }
95
96 HotDeployListener hotDeployListener =
97 (HotDeployListener)Class.forName(
98 hotDeployListeners[i]).newInstance();
99
100 list.add(hotDeployListener);
101 }
102 catch (Exception e) {
103 _log.error(e);
104 }
105 }
106
107 return list;
108 }
109
110 public void run(String[] ids) throws ActionException {
111
112
114 try {
115 if (GetterUtil.getBoolean(PropsUtil.get(
116 PropsUtil.JCR_INITIALIZE_ON_STARTUP))) {
117
118 JCRFactoryUtil.initialize();
119 }
120 }
121 catch (Exception e) {
122 _log.error(e);
123 }
124
125
127 _log.debug("Registering hot deploy listeners");
128
129 Iterator itr = getHotDeployListeners().iterator();
130
131 while (itr.hasNext()) {
132 HotDeployListener hotDeployListener = (HotDeployListener)itr.next();
133
134 HotDeployUtil.registerListener(hotDeployListener);
135 }
136
137
139 try {
140 if (PrefsPropsUtil.getBoolean(PropsUtil.AUTO_DEPLOY_ENABLED)) {
141 if (_log.isInfoEnabled()) {
142 _log.info("Registering auto deploy directories");
143 }
144
145 File deployDir = new File(
146 PrefsPropsUtil.getString(PropsUtil.AUTO_DEPLOY_DEPLOY_DIR));
147 File destDir = new File(DeployUtil.getAutoDeployDestDir());
148 long interval = PrefsPropsUtil.getLong(
149 PropsUtil.AUTO_DEPLOY_INTERVAL);
150 int blacklistThreshold = PrefsPropsUtil.getInteger(
151 PropsUtil.AUTO_DEPLOY_BLACKLIST_THRESHOLD);
152
153 List autoDeployListeners = getAutoDeployListeners();
154
155 AutoDeployDir autoDeployDir = new AutoDeployDir(
156 "defaultAutoDeployDir", deployDir, destDir, interval,
157 blacklistThreshold, autoDeployListeners);
158
159 AutoDeployUtil.registerDir(autoDeployDir);
160 }
161 else {
162 if (_log.isInfoEnabled()) {
163 _log.info("Not registering auto deploy directories");
164 }
165 }
166 }
167 catch (Exception e) {
168 _log.error(e);
169 }
170
171
173 if (GetterUtil.getBoolean(PropsUtil.get(
174 PropsUtil.SMTP_SERVER_ENABLED))) {
175
176 int port = GetterUtil.getInteger(PropsUtil.get(
177 PropsUtil.SMTP_SERVER_PORT));
178
179 SMTPServerUtil.setPort(port);
180
181 SMTPServerUtil.start();
182 }
183
184
186 CommLink.getInstance();
187
188
190 runEvent(FixOracleAction.class.getName(), ids);
191 runEvent(FixCounterAction.class.getName(), ids);
192 }
194
195 protected void runEvent(String className, String[] ids)
196 throws ActionException {
197
198 SimpleAction action = (SimpleAction)InstancePool.get(className);
199
200 action.run(ids);
201 }
202
203 private static Log _log = LogFactory.getLog(GlobalStartupAction.class);
204
205 }