1
14
15 package com.liferay.portal.events;
16
17 import com.liferay.portal.im.AIMConnector;
18 import com.liferay.portal.im.ICQConnector;
19 import com.liferay.portal.im.MSNConnector;
20 import com.liferay.portal.im.YMConnector;
21 import com.liferay.portal.jcr.JCRFactoryUtil;
22 import com.liferay.portal.kernel.dao.db.DB;
23 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
24 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
25 import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
26 import com.liferay.portal.kernel.events.SimpleAction;
27 import com.liferay.portal.kernel.job.JobSchedulerUtil;
28 import com.liferay.portal.kernel.log.Jdk14LogFactoryImpl;
29 import com.liferay.portal.kernel.log.Log;
30 import com.liferay.portal.kernel.log.LogFactoryUtil;
31 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.PropsKeys;
34 import com.liferay.portal.kernel.util.ReflectionUtil;
35 import com.liferay.portal.kernel.util.ThreadLocalRegistry;
36 import com.liferay.portal.pop.POPServerUtil;
37 import com.liferay.portal.search.lucene.LuceneHelperUtil;
38 import com.liferay.portal.util.PropsUtil;
39 import com.liferay.portal.util.PropsValues;
40 import com.liferay.portlet.documentlibrary.util.DocumentConversionUtil;
41 import com.liferay.util.ThirdPartyThreadLocalRegistry;
42
43 import java.sql.Connection;
44 import java.sql.Statement;
45
46 import org.apache.axis.utils.XMLUtils;
47
48
53 public class GlobalShutdownAction extends SimpleAction {
54
55 public void run(String[] ids) {
56
57
59 HotDeployUtil.unregisterListeners();
60
61
63 try {
64 if (_log.isDebugEnabled()) {
65 _log.debug("Shutting down AIM");
66 }
67
68 AIMConnector.disconnect();
69 }
70 catch (Exception e) {
71 }
72
73
75 try {
76 if (_log.isDebugEnabled()) {
77 _log.debug("Shutting down ICQ");
78 }
79
80 ICQConnector.disconnect();
81 }
82 catch (Exception e) {
83 }
84
85
87 try {
88 if (_log.isDebugEnabled()) {
89 _log.debug("Shutting down MSN");
90 }
91
92 MSNConnector.disconnect();
93 }
94 catch (Exception e) {
95 }
96
97
99 try {
100 if (_log.isDebugEnabled()) {
101 _log.debug("Shutting down YM");
102 }
103
104 YMConnector.disconnect();
105 }
106 catch (Exception e) {
107 }
108
109
111 try {
112 if (_log.isDebugEnabled()) {
113 _log.debug("Shutting down JCR");
114 }
115
116 JCRFactoryUtil.shutdown();
117 }
118 catch (Exception e) {
119 }
120
121
123 LuceneHelperUtil.shutdown();
124
125
127 DocumentConversionUtil.disconnect();
128
129
131 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
132 POPServerUtil.stop();
133 }
134
135
137 try {
138 JobSchedulerUtil.shutdown();
139 }
140 catch (Exception e) {
141 }
142
143 try {
144 SchedulerEngineUtil.shutdown();
145 }
146 catch (Exception e) {
147 }
148
149
151 ThirdPartyThreadLocalRegistry.resetThreadLocals();
152 ThreadLocalRegistry.resetThreadLocals();
153
154 ThreadLocal<?> threadLocal =
155 (ThreadLocal<?>)ReflectionUtil.getFieldValue(
156 XMLUtils.class, "documentBuilder");
157
158 threadLocal.remove();
159
160
162 DB db = DBFactoryUtil.getDB();
163
164 if (db.getType().equals(DB.TYPE_HYPERSONIC)) {
165 try {
166 Connection connection = DataAccess.getConnection();
167
168 Statement statement = connection.createStatement();
169
170 statement.executeUpdate("SHUTDOWN");
171
172 statement.close();
173 }
174 catch (Exception e) {
175 _log.error(e, e);
176 }
177 }
178
179
183 try {
184 LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
185 }
186 catch (Exception e) {
187 }
188
189
191 try {
192 Thread.sleep(1000);
193 }
194 catch (Exception e) {
195 e.printStackTrace();
196 }
197
198
200 if (GetterUtil.getBoolean(PropsUtil.get(
201 PropsKeys.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
202
203 Thread currentThread = Thread.currentThread();
204
205 ThreadGroup threadGroup = currentThread.getThreadGroup();
206
207 for (int i = 0; i < 10; i++) {
208 if (threadGroup.getParent() == null) {
209 break;
210 }
211 else {
212 threadGroup = threadGroup.getParent();
213 }
214 }
215
216 Thread[] threads = new Thread[threadGroup.activeCount() * 2];
217
218 threadGroup.enumerate(threads);
219
220 for (Thread thread : threads) {
221 if ((thread == null) || (thread == currentThread)) {
222 continue;
223 }
224
225 try {
226 thread.interrupt();
227 }
228 catch (Exception e) {
229 }
230 }
231
232 threadGroup.destroy();
233 }
234 }
235
236 private static Log _log = LogFactoryUtil.getLog(GlobalShutdownAction.class);
237
238 }