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