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