| GlobalShutdownAction.java |
1 /**
2 * Copyright (c) 2000-2008 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.kernel.deploy.hot.HotDeployUtil;
31 import com.liferay.portal.kernel.events.SimpleAction;
32 import com.liferay.portal.kernel.job.JobSchedulerUtil;
33 import com.liferay.portal.kernel.log.Jdk14LogFactoryImpl;
34 import com.liferay.portal.kernel.log.LogFactoryUtil;
35 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
36 import com.liferay.portal.kernel.util.GetterUtil;
37 import com.liferay.portal.pop.POPServerUtil;
38 import com.liferay.portal.util.PropsKeys;
39 import com.liferay.portal.util.PropsUtil;
40 import com.liferay.portal.util.PropsValues;
41
42 import org.apache.commons.logging.Log;
43 import org.apache.commons.logging.LogFactory;
44
45 /**
46 * <a href="GlobalShutdownAction.java.html"><b><i>View Source</i></b></a>
47 *
48 * @author Brian Wing Shun Chan
49 *
50 */
51 public class GlobalShutdownAction extends SimpleAction {
52
53 public void run(String[] ids) {
54
55 // Hot deploy
56
57 HotDeployUtil.unregisterListeners();
58
59 // Instant messenger AIM
60
61 try {
62 _log.debug("Shutting down AIM");
63
64 AIMConnector.disconnect();
65 }
66 catch (Exception e) {
67 }
68
69 // Instant messenger ICQ
70
71 try {
72 _log.debug("Shutting down ICQ");
73
74 ICQConnector.disconnect();
75 }
76 catch (Exception e) {
77 }
78
79 // Instant messenger MSN
80
81 try {
82 _log.debug("Shutting down MSN");
83
84 MSNConnector.disconnect();
85 }
86 catch (Exception e) {
87 }
88
89 // Instant messenger YM
90
91 try {
92 _log.debug("Shutting down YM");
93
94 YMConnector.disconnect();
95 }
96 catch (Exception e) {
97 }
98
99 // JCR
100
101 try {
102 _log.debug("Shutting down JCR");
103
104 JCRFactoryUtil.shutdown();
105 }
106 catch (Exception e) {
107 }
108
109 // POP server
110
111 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
112 POPServerUtil.stop();
113 }
114
115 // Scheduler
116
117 try {
118 JobSchedulerUtil.shutdown();
119 }
120 catch (Exception e) {
121 }
122
123 try {
124 SchedulerEngineUtil.shutdown();
125 }
126 catch (Exception e) {
127 }
128
129 // Reset log to default JDK 1.4 logger. This will allow WARs dependent
130 // on the portal to still log events after the portal WAR has been
131 // destroyed.
132
133 try {
134 LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
135 }
136 catch (Exception e) {
137 }
138
139 // Programmatically exit
140
141 if (GetterUtil.getBoolean(PropsUtil.get(
142 PropsKeys.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
143
144 Thread thread = Thread.currentThread();
145
146 ThreadGroup threadGroup = thread.getThreadGroup();
147
148 for (int i = 0; i < 10; i++) {
149 if (threadGroup.getParent() == null) {
150 break;
151 }
152 else {
153 threadGroup = threadGroup.getParent();
154 }
155 }
156
157 //threadGroup.list();
158
159 Thread[] threads = new Thread[threadGroup.activeCount() * 2];
160
161 threadGroup.enumerate(threads);
162
163 for (int i = 0; i < threads.length; i++) {
164 Thread curThread = threads[i];
165
166 if ((curThread != null) && (curThread != thread)) {
167 try {
168 curThread.interrupt();
169 }
170 catch (Exception e) {
171 }
172 }
173 }
174
175 threadGroup.destroy();
176 }
177 }
178
179 private static Log _log = LogFactory.getLog(GlobalShutdownAction.class);
180
181 }