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.events.SimpleAction;
34 import com.liferay.portal.kernel.util.GetterUtil;
35 import com.liferay.portal.kernel.util.InfrastructureUtil;
36 import com.liferay.portal.kernel.util.ServerDetector;
37 import com.liferay.portal.pop.POPServerUtil;
38 import com.liferay.portal.util.BrowserLauncher;
39 import com.liferay.portal.util.PrefsPropsUtil;
40 import com.liferay.portal.util.PropsKeys;
41 import com.liferay.portal.util.PropsUtil;
42 import com.liferay.portal.util.PropsValues;
43
44 import java.io.File;
45
46 import java.util.ArrayList;
47 import java.util.List;
48
49 import org.apache.commons.logging.Log;
50 import org.apache.commons.logging.LogFactory;
51
52
58 public class GlobalStartupAction extends SimpleAction {
59
60 public static List<AutoDeployListener> getAutoDeployListeners() {
61 List<AutoDeployListener> list = new ArrayList<AutoDeployListener>();
62
63 String[] autoDeployListeners =
64 PropsUtil.getArray(PropsKeys.AUTO_DEPLOY_LISTENERS);
65
66 for (int i = 0; i < autoDeployListeners.length; i++) {
67 try {
68 if (_log.isDebugEnabled()) {
69 _log.debug("Instantiating " + autoDeployListeners[i]);
70 }
71
72 AutoDeployListener autoDeployListener =
73 (AutoDeployListener)Class.forName(
74 autoDeployListeners[i]).newInstance();
75
76 list.add(autoDeployListener);
77 }
78 catch (Exception e) {
79 _log.error(e);
80 }
81 }
82
83 return list;
84 }
85
86 public static List<HotDeployListener> getHotDeployListeners() {
87 List<HotDeployListener> list = new ArrayList<HotDeployListener>();
88
89 String[] hotDeployListeners =
90 PropsUtil.getArray(PropsKeys.HOT_DEPLOY_LISTENERS);
91
92 for (int i = 0; i < hotDeployListeners.length; i++) {
93 try {
94 if (_log.isDebugEnabled()) {
95 _log.debug("Instantiating " + hotDeployListeners[i]);
96 }
97
98 HotDeployListener hotDeployListener =
99 (HotDeployListener)Class.forName(
100 hotDeployListeners[i]).newInstance();
101
102 list.add(hotDeployListener);
103 }
104 catch (Exception e) {
105 _log.error(e);
106 }
107 }
108
109 return list;
110 }
111
112 public void run(String[] ids) {
113
114
116 if (_log.isDebugEnabled()) {
117 _log.debug("Registering hot deploy listeners");
118 }
119
120 for (HotDeployListener hotDeployListener : getHotDeployListeners()) {
121 HotDeployUtil.registerListener(hotDeployListener);
122 }
123
124
126 try {
127 if (PrefsPropsUtil.getBoolean(
128 PropsKeys.AUTO_DEPLOY_ENABLED,
129 PropsValues.AUTO_DEPLOY_ENABLED)) {
130
131 if (_log.isInfoEnabled()) {
132 _log.info("Registering auto deploy directories");
133 }
134
135 File deployDir = new File(
136 PrefsPropsUtil.getString(
137 PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
138 PropsValues.AUTO_DEPLOY_DEPLOY_DIR));
139 File destDir = new File(DeployUtil.getAutoDeployDestDir());
140 long interval = PrefsPropsUtil.getLong(
141 PropsKeys.AUTO_DEPLOY_INTERVAL,
142 PropsValues.AUTO_DEPLOY_INTERVAL);
143 int blacklistThreshold = PrefsPropsUtil.getInteger(
144 PropsKeys.AUTO_DEPLOY_BLACKLIST_THRESHOLD,
145 PropsValues.AUTO_DEPLOY_BLACKLIST_THRESHOLD);
146
147 List<AutoDeployListener> autoDeployListeners =
148 getAutoDeployListeners();
149
150 AutoDeployDir autoDeployDir = new AutoDeployDir(
151 "defaultAutoDeployDir", deployDir, destDir, interval,
152 blacklistThreshold, autoDeployListeners);
153
154 AutoDeployUtil.registerDir(autoDeployDir);
155 }
156 else {
157 if (_log.isInfoEnabled()) {
158 _log.info("Not registering auto deploy directories");
159 }
160 }
161 }
162 catch (Exception e) {
163 _log.error(e);
164 }
165
166
168 try {
169 JCRFactoryUtil.prepare();
170
171 if (GetterUtil.getBoolean(PropsUtil.get(
172 PropsKeys.JCR_INITIALIZE_ON_STARTUP))) {
173
174 JCRFactoryUtil.initialize();
175 }
176 }
177 catch (Exception e) {
178 _log.error(e);
179 }
180
181
183 CommLink.getInstance();
184
185
187 try {
188 InfrastructureUtil.getDataSource();
189 }
190 catch (Exception e) {
191 _log.error(e, e);
192 }
193
194 try {
195 if (!ServerDetector.isJOnAS()) {
196 InfrastructureUtil.getMailSession();
197 }
198 }
199 catch (Exception e) {
200 if (_log.isWarnEnabled()) {
201 _log.warn(e.getMessage());
202 }
203 }
204
205
207 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
208 POPServerUtil.start();
209 }
210
211
213 Thread browserLauncherThread = new Thread(new BrowserLauncher());
214
215 browserLauncherThread.start();
216 }
217
218 private static Log _log = LogFactory.getLog(GlobalStartupAction.class);
219
220 }