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