| GlobalShutdownAction.java |
1 /**
2 * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portal.events;
24
25 import com.liferay.portal.im.AIMConnector;
26 import com.liferay.portal.im.ICQConnector;
27 import com.liferay.portal.im.MSNConnector;
28 import com.liferay.portal.im.YMConnector;
29 import com.liferay.portal.jcr.JCRFactoryUtil;
30 import com.liferay.portal.job.JobScheduler;
31 import com.liferay.portal.kernel.log.Jdk14LogFactoryImpl;
32 import com.liferay.portal.kernel.log.LogFactoryUtil;
33 import com.liferay.portal.kernel.util.GetterUtil;
34 import com.liferay.portal.smtp.SMTPServerUtil;
35 import com.liferay.portal.struts.ActionException;
36 import com.liferay.portal.struts.SimpleAction;
37 import com.liferay.portal.util.PropsUtil;
38
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41
42 /**
43 * <a href="GlobalShutdownAction.java.html"><b><i>View Source</i></b></a>
44 *
45 * @author Brian Wing Shun Chan
46 *
47 */
48 public class GlobalShutdownAction extends SimpleAction {
49
50 public void run(String[] ids) throws ActionException {
51
52 // Disconnect AIM
53
54 try {
55 _log.debug("Shutting down AIM");
56
57 AIMConnector.disconnect();
58 }
59 catch (Exception e) {
60 }
61
62 // Disconnect ICQ
63
64 try {
65 _log.debug("Shutting down ICQ");
66
67 ICQConnector.disconnect();
68 }
69 catch (Exception e) {
70 }
71
72 // Disconnect MSN
73
74 try {
75 _log.debug("Shutting down MSN");
76
77 MSNConnector.disconnect();
78 }
79 catch (Exception e) {
80 }
81
82 // Disconnect YM
83
84 try {
85 _log.debug("Shutting down YM");
86
87 YMConnector.disconnect();
88 }
89 catch (Exception e) {
90 }
91
92 // Shutdown JCR
93
94 try {
95 _log.debug("Shutting down JCR");
96
97 JCRFactoryUtil.shutdown();
98 }
99 catch (Exception e) {
100 }
101
102 // Scheduler
103
104 try {
105 JobScheduler.shutdown();
106 }
107 catch (Exception e) {
108 }
109
110 // SMTP server
111
112 if (GetterUtil.getBoolean(PropsUtil.get(
113 PropsUtil.SMTP_SERVER_ENABLED))) {
114
115 SMTPServerUtil.stop();
116 }
117
118 // Reset log to default JDK 1.4 logger. This will allow WARs dependent
119 // on the portal to still log events after the portal WAR has been
120 // destroyed.
121
122 try {
123 LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
124 }
125 catch (Exception e) {
126 }
127
128 // Programmatically exit
129
130 if (GetterUtil.getBoolean(PropsUtil.get(
131 PropsUtil.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
132
133 Thread thread = Thread.currentThread();
134
135 ThreadGroup threadGroup = thread.getThreadGroup();
136
137 for (int i = 0; i < 10; i++) {
138 if (threadGroup.getParent() == null) {
139 break;
140 }
141 else {
142 threadGroup = threadGroup.getParent();
143 }
144 }
145
146 //threadGroup.list();
147
148 Thread[] threads = new Thread[threadGroup.activeCount() * 2];
149
150 threadGroup.enumerate(threads);
151
152 for (int i = 0; i < threads.length; i++) {
153 Thread curThread = threads[i];
154
155 if ((curThread != null) && (curThread != thread)) {
156 try {
157 curThread.interrupt();
158 }
159 catch (Exception e) {
160 }
161 }
162 }
163
164 threadGroup.destroy();
165 }
166 }
167
168 private static Log _log = LogFactory.getLog(GlobalShutdownAction.class);
169
170 }