001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.events;
022:
023: import com.liferay.portal.comm.CommLink;
024: import com.liferay.portal.deploy.DeployUtil;
025: import com.liferay.portal.jcr.JCRFactoryUtil;
026: import com.liferay.portal.kernel.deploy.auto.AutoDeployDir;
027: import com.liferay.portal.kernel.deploy.auto.AutoDeployListener;
028: import com.liferay.portal.kernel.deploy.auto.AutoDeployUtil;
029: import com.liferay.portal.kernel.deploy.hot.HotDeployListener;
030: import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
031: import com.liferay.portal.kernel.events.ActionException;
032: import com.liferay.portal.kernel.events.SimpleAction;
033: import com.liferay.portal.kernel.util.GetterUtil;
034: import com.liferay.portal.kernel.util.InstancePool;
035: import com.liferay.portal.pop.POPServerUtil;
036: import com.liferay.portal.util.PrefsPropsUtil;
037: import com.liferay.portal.util.PropsUtil;
038: import com.liferay.portal.util.PropsValues;
039:
040: import java.io.File;
041:
042: import java.util.ArrayList;
043: import java.util.Iterator;
044: import java.util.List;
045:
046: import org.apache.commons.logging.Log;
047: import org.apache.commons.logging.LogFactory;
048:
049: /**
050: * <a href="GlobalStartupAction.java.html"><b><i>View Source</i></b></a>
051: *
052: * @author Brian Wing Shun Chan
053: *
054: */
055: public class GlobalStartupAction extends SimpleAction {
056:
057: public static List getAutoDeployListeners() {
058: List list = new ArrayList();
059:
060: String[] autoDeployListeners = PropsUtil
061: .getArray(PropsUtil.AUTO_DEPLOY_LISTENERS);
062:
063: for (int i = 0; i < autoDeployListeners.length; i++) {
064: try {
065: if (_log.isDebugEnabled()) {
066: _log.debug("Instantiating "
067: + autoDeployListeners[i]);
068: }
069:
070: AutoDeployListener autoDeployListener = (AutoDeployListener) Class
071: .forName(autoDeployListeners[i]).newInstance();
072:
073: list.add(autoDeployListener);
074: } catch (Exception e) {
075: _log.error(e);
076: }
077: }
078:
079: return list;
080: }
081:
082: public static List getHotDeployListeners() {
083: List list = new ArrayList();
084:
085: String[] hotDeployListeners = PropsUtil
086: .getArray(PropsUtil.HOT_DEPLOY_LISTENERS);
087:
088: for (int i = 0; i < hotDeployListeners.length; i++) {
089: try {
090: if (_log.isDebugEnabled()) {
091: _log
092: .debug("Instantiating "
093: + hotDeployListeners[i]);
094: }
095:
096: HotDeployListener hotDeployListener = (HotDeployListener) Class
097: .forName(hotDeployListeners[i]).newInstance();
098:
099: list.add(hotDeployListener);
100: } catch (Exception e) {
101: _log.error(e);
102: }
103: }
104:
105: return list;
106: }
107:
108: public void run(String[] ids) throws ActionException {
109:
110: // Hot deploy
111:
112: if (_log.isDebugEnabled()) {
113: _log.debug("Registering hot deploy listeners");
114: }
115:
116: Iterator itr = getHotDeployListeners().iterator();
117:
118: while (itr.hasNext()) {
119: HotDeployListener hotDeployListener = (HotDeployListener) itr
120: .next();
121:
122: HotDeployUtil.registerListener(hotDeployListener);
123: }
124:
125: // Auto deploy
126:
127: try {
128: if (PrefsPropsUtil.getBoolean(
129: PropsUtil.AUTO_DEPLOY_ENABLED,
130: PropsValues.AUTO_DEPLOY_ENABLED)) {
131:
132: if (_log.isInfoEnabled()) {
133: _log.info("Registering auto deploy directories");
134: }
135:
136: File deployDir = new File(PrefsPropsUtil.getString(
137: PropsUtil.AUTO_DEPLOY_DEPLOY_DIR,
138: PropsValues.AUTO_DEPLOY_DEPLOY_DIR));
139: File destDir = new File(DeployUtil
140: .getAutoDeployDestDir());
141: long interval = PrefsPropsUtil.getLong(
142: PropsUtil.AUTO_DEPLOY_INTERVAL,
143: PropsValues.AUTO_DEPLOY_INTERVAL);
144: int blacklistThreshold = PrefsPropsUtil.getInteger(
145: PropsUtil.AUTO_DEPLOY_BLACKLIST_THRESHOLD,
146: PropsValues.AUTO_DEPLOY_BLACKLIST_THRESHOLD);
147:
148: List autoDeployListeners = getAutoDeployListeners();
149:
150: AutoDeployDir autoDeployDir = new AutoDeployDir(
151: "defaultAutoDeployDir", deployDir, destDir,
152: interval, blacklistThreshold,
153: autoDeployListeners);
154:
155: AutoDeployUtil.registerDir(autoDeployDir);
156: } else {
157: if (_log.isInfoEnabled()) {
158: _log
159: .info("Not registering auto deploy directories");
160: }
161: }
162: } catch (Exception e) {
163: _log.error(e);
164: }
165:
166: // JCR
167:
168: try {
169: if (GetterUtil.getBoolean(PropsUtil
170: .get(PropsUtil.JCR_INITIALIZE_ON_STARTUP))) {
171:
172: JCRFactoryUtil.initialize();
173: }
174: } catch (Exception e) {
175: _log.error(e);
176: }
177:
178: // JGroups
179:
180: CommLink.getInstance();
181:
182: // POP server
183:
184: if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
185: POPServerUtil.start();
186: }
187:
188: // Other required events
189:
190: runEvent(FixOracleAction.class.getName(), ids);
191: runEvent(FixCounterAction.class.getName(), ids);
192: //runEvent(FixJournalAction.class.getName(), ids);
193: }
194:
195: protected void runEvent(String className, String[] ids)
196: throws ActionException {
197:
198: SimpleAction action = (SimpleAction) InstancePool
199: .get(className);
200:
201: action.run(ids);
202: }
203:
204: private static Log _log = LogFactory
205: .getLog(GlobalStartupAction.class);
206:
207: }
|