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 try {
116 if (GetterUtil.getBoolean(PropsUtil.get(
117 PropsUtil.JCR_INITIALIZE_ON_STARTUP))) {
118
119 JCRFactoryUtil.initialize();
120 }
121 }
122 catch (Exception e) {
123 _log.error(e);
124 }
125
126
128 _log.debug("Registering hot deploy listeners");
129
130 Iterator itr = getHotDeployListeners().iterator();
131
132 while (itr.hasNext()) {
133 HotDeployListener hotDeployListener = (HotDeployListener)itr.next();
134
135 HotDeployUtil.registerListener(hotDeployListener);
136 }
137
138
140 try {
141 if (PrefsPropsUtil.getBoolean(
142 PropsUtil.AUTO_DEPLOY_ENABLED,
143 PropsValues.AUTO_DEPLOY_ENABLED)) {
144
145 if (_log.isInfoEnabled()) {
146 _log.info("Registering auto deploy directories");
147 }
148
149 File deployDir = new File(
150 PrefsPropsUtil.getString(
151 PropsUtil.AUTO_DEPLOY_DEPLOY_DIR,
152 PropsValues.AUTO_DEPLOY_DEPLOY_DIR));
153 File destDir = new File(DeployUtil.getAutoDeployDestDir());
154 long interval = PrefsPropsUtil.getLong(
155 PropsUtil.AUTO_DEPLOY_INTERVAL,
156 PropsValues.AUTO_DEPLOY_INTERVAL);
157 int blacklistThreshold = PrefsPropsUtil.getInteger(
158 PropsUtil.AUTO_DEPLOY_BLACKLIST_THRESHOLD,
159 PropsValues.AUTO_DEPLOY_BLACKLIST_THRESHOLD);
160
161 List autoDeployListeners = getAutoDeployListeners();
162
163 AutoDeployDir autoDeployDir = new AutoDeployDir(
164 "defaultAutoDeployDir", deployDir, destDir, interval,
165 blacklistThreshold, autoDeployListeners);
166
167 AutoDeployUtil.registerDir(autoDeployDir);
168 }
169 else {
170 if (_log.isInfoEnabled()) {
171 _log.info("Not registering auto deploy directories");
172 }
173 }
174 }
175 catch (Exception e) {
176 _log.error(e);
177 }
178
179
181 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
182 POPServerUtil.start();
183 }
184
185
187 CommLink.getInstance();
188
189
191 runEvent(FixOracleAction.class.getName(), ids);
192 runEvent(FixCounterAction.class.getName(), ids);
193 }
195
196 protected void runEvent(String className, String[] ids)
197 throws ActionException {
198
199 SimpleAction action = (SimpleAction)InstancePool.get(className);
200
201 action.run(ids);
202 }
203
204 private static Log _log = LogFactory.getLog(GlobalStartupAction.class);
205
206 }