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.im.AIMConnector;
024: import com.liferay.portal.im.ICQConnector;
025: import com.liferay.portal.im.MSNConnector;
026: import com.liferay.portal.im.YMConnector;
027: import com.liferay.portal.jcr.JCRFactoryUtil;
028: import com.liferay.portal.job.JobScheduler;
029: import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
030: import com.liferay.portal.kernel.events.ActionException;
031: import com.liferay.portal.kernel.events.SimpleAction;
032: import com.liferay.portal.kernel.log.Jdk14LogFactoryImpl;
033: import com.liferay.portal.kernel.log.LogFactoryUtil;
034: import com.liferay.portal.kernel.util.GetterUtil;
035: import com.liferay.portal.pop.POPServerUtil;
036: import com.liferay.portal.util.PropsUtil;
037: import com.liferay.portal.util.PropsValues;
038:
039: import org.apache.commons.logging.Log;
040: import org.apache.commons.logging.LogFactory;
041:
042: /**
043: * <a href="GlobalShutdownAction.java.html"><b><i>View Source</i></b></a>
044: *
045: * @author Brian Wing Shun Chan
046: *
047: */
048: public class GlobalShutdownAction extends SimpleAction {
049:
050: public void run(String[] ids) throws ActionException {
051:
052: // Hot deploy
053:
054: HotDeployUtil.unregisterListeners();
055:
056: // Instant messenger AIM
057:
058: try {
059: _log.debug("Shutting down AIM");
060:
061: AIMConnector.disconnect();
062: } catch (Exception e) {
063: }
064:
065: // Instant messenger ICQ
066:
067: try {
068: _log.debug("Shutting down ICQ");
069:
070: ICQConnector.disconnect();
071: } catch (Exception e) {
072: }
073:
074: // Instant messenger MSN
075:
076: try {
077: _log.debug("Shutting down MSN");
078:
079: MSNConnector.disconnect();
080: } catch (Exception e) {
081: }
082:
083: // Instant messenger YM
084:
085: try {
086: _log.debug("Shutting down YM");
087:
088: YMConnector.disconnect();
089: } catch (Exception e) {
090: }
091:
092: // JCR
093:
094: try {
095: _log.debug("Shutting down JCR");
096:
097: JCRFactoryUtil.shutdown();
098: } catch (Exception e) {
099: }
100:
101: // POP server
102:
103: if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
104: POPServerUtil.stop();
105: }
106:
107: // Scheduler
108:
109: try {
110: JobScheduler.shutdown();
111: } catch (Exception e) {
112: }
113:
114: // Reset log to default JDK 1.4 logger. This will allow WARs dependent
115: // on the portal to still log events after the portal WAR has been
116: // destroyed.
117:
118: try {
119: LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
120: } catch (Exception e) {
121: }
122:
123: // Programmatically exit
124:
125: if (GetterUtil.getBoolean(PropsUtil
126: .get(PropsUtil.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
127:
128: Thread thread = Thread.currentThread();
129:
130: ThreadGroup threadGroup = thread.getThreadGroup();
131:
132: for (int i = 0; i < 10; i++) {
133: if (threadGroup.getParent() == null) {
134: break;
135: } else {
136: threadGroup = threadGroup.getParent();
137: }
138: }
139:
140: //threadGroup.list();
141:
142: Thread[] threads = new Thread[threadGroup.activeCount() * 2];
143:
144: threadGroup.enumerate(threads);
145:
146: for (int i = 0; i < threads.length; i++) {
147: Thread curThread = threads[i];
148:
149: if ((curThread != null) && (curThread != thread)) {
150: try {
151: curThread.interrupt();
152: } catch (Exception e) {
153: }
154: }
155: }
156:
157: threadGroup.destroy();
158: }
159: }
160:
161: private static Log _log = LogFactory
162: .getLog(GlobalShutdownAction.class);
163:
164: }
|