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.util.GetterUtil;
36 import com.liferay.portal.kernel.util.InstancePool;
37 import com.liferay.portal.pop.POPServerUtil;
38 import com.liferay.portal.util.PrefsPropsUtil;
39 import com.liferay.portal.util.PropsUtil;
40 import com.liferay.portal.util.PropsValues;
41
42 import java.io.File;
43
44 import java.util.ArrayList;
45 import java.util.Iterator;
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 getAutoDeployListeners() {
60 List list = new ArrayList();
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 getHotDeployListeners() {
86 List list = new ArrayList();
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 Iterator itr = getHotDeployListeners().iterator();
120
121 while (itr.hasNext()) {
122 HotDeployListener hotDeployListener = (HotDeployListener)itr.next();
123
124 HotDeployUtil.registerListener(hotDeployListener);
125 }
126
127
129 try {
130 if (PrefsPropsUtil.getBoolean(
131 PropsUtil.AUTO_DEPLOY_ENABLED,
132 PropsValues.AUTO_DEPLOY_ENABLED)) {
133
134 if (_log.isInfoEnabled()) {
135 _log.info("Registering auto deploy directories");
136 }
137
138 File deployDir = new File(
139 PrefsPropsUtil.getString(
140 PropsUtil.AUTO_DEPLOY_DEPLOY_DIR,
141 PropsValues.AUTO_DEPLOY_DEPLOY_DIR));
142 File destDir = new File(DeployUtil.getAutoDeployDestDir());
143 long interval = PrefsPropsUtil.getLong(
144 PropsUtil.AUTO_DEPLOY_INTERVAL,
145 PropsValues.AUTO_DEPLOY_INTERVAL);
146 int blacklistThreshold = PrefsPropsUtil.getInteger(
147 PropsUtil.AUTO_DEPLOY_BLACKLIST_THRESHOLD,
148 PropsValues.AUTO_DEPLOY_BLACKLIST_THRESHOLD);
149
150 List autoDeployListeners = getAutoDeployListeners();
151
152 AutoDeployDir autoDeployDir = new AutoDeployDir(
153 "defaultAutoDeployDir", deployDir, destDir, interval,
154 blacklistThreshold, autoDeployListeners);
155
156 AutoDeployUtil.registerDir(autoDeployDir);
157 }
158 else {
159 if (_log.isInfoEnabled()) {
160 _log.info("Not registering auto deploy directories");
161 }
162 }
163 }
164 catch (Exception e) {
165 _log.error(e);
166 }
167
168
170 try {
171 if (GetterUtil.getBoolean(PropsUtil.get(
172 PropsUtil.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 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
188 POPServerUtil.start();
189 }
190
191
193 runEvent(FixOracleAction.class.getName(), ids);
194 runEvent(FixCounterAction.class.getName(), ids);
195 }
197
198 protected void runEvent(String className, String[] ids)
199 throws ActionException {
200
201 SimpleAction action = (SimpleAction)InstancePool.get(className);
202
203 action.run(ids);
204 }
205
206 private static Log _log = LogFactory.getLog(GlobalStartupAction.class);
207
208 }