001
014
015 package com.liferay.portal.events;
016
017 import com.liferay.portal.im.AIMConnector;
018 import com.liferay.portal.im.ICQConnector;
019 import com.liferay.portal.im.MSNConnector;
020 import com.liferay.portal.im.YMConnector;
021 import com.liferay.portal.jcr.JCRFactoryUtil;
022 import com.liferay.portal.kernel.dao.db.DB;
023 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
024 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
025 import com.liferay.portal.kernel.deploy.auto.AutoDeployDir;
026 import com.liferay.portal.kernel.deploy.auto.AutoDeployUtil;
027 import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
028 import com.liferay.portal.kernel.deploy.sandbox.SandboxDeployDir;
029 import com.liferay.portal.kernel.deploy.sandbox.SandboxDeployUtil;
030 import com.liferay.portal.kernel.events.SimpleAction;
031 import com.liferay.portal.kernel.executor.PortalExecutorManagerUtil;
032 import com.liferay.portal.kernel.log.Jdk14LogFactoryImpl;
033 import com.liferay.portal.kernel.log.Log;
034 import com.liferay.portal.kernel.log.LogFactoryUtil;
035 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
036 import com.liferay.portal.kernel.util.CentralizedThreadLocal;
037 import com.liferay.portal.kernel.util.GetterUtil;
038 import com.liferay.portal.kernel.util.PropsKeys;
039 import com.liferay.portal.search.lucene.LuceneHelperUtil;
040 import com.liferay.portal.util.PropsUtil;
041 import com.liferay.portlet.documentlibrary.util.DocumentConversionUtil;
042 import com.liferay.util.ThirdPartyThreadLocalRegistry;
043
044 import java.sql.Connection;
045 import java.sql.Statement;
046
047
050 public class GlobalShutdownAction extends SimpleAction {
051
052 @Override
053 public void run(String[] ids) {
054
055
056
057 AutoDeployUtil.unregisterDir(AutoDeployDir.DEFAULT_NAME);
058
059
060
061 HotDeployUtil.unregisterListeners();
062
063
064
065 SandboxDeployUtil.unregisterDir(SandboxDeployDir.DEFAULT_NAME);
066
067
068
069 try {
070 if (_log.isDebugEnabled()) {
071 _log.debug("Shutting down AIM");
072 }
073
074 AIMConnector.disconnect();
075 }
076 catch (Exception e) {
077 }
078
079
080
081 try {
082 if (_log.isDebugEnabled()) {
083 _log.debug("Shutting down ICQ");
084 }
085
086 ICQConnector.disconnect();
087 }
088 catch (Exception e) {
089 }
090
091
092
093 try {
094 if (_log.isDebugEnabled()) {
095 _log.debug("Shutting down MSN");
096 }
097
098 MSNConnector.disconnect();
099 }
100 catch (Exception e) {
101 }
102
103
104
105 try {
106 if (_log.isDebugEnabled()) {
107 _log.debug("Shutting down YM");
108 }
109
110 YMConnector.disconnect();
111 }
112 catch (Exception e) {
113 }
114
115
116
117 try {
118 if (_log.isDebugEnabled()) {
119 _log.debug("Shutting down JCR");
120 }
121
122 JCRFactoryUtil.shutdown();
123 }
124 catch (Exception e) {
125 }
126
127
128
129 LuceneHelperUtil.shutdown();
130
131
132
133 DocumentConversionUtil.disconnect();
134
135
136
137 try {
138 SchedulerEngineUtil.shutdown();
139 }
140 catch (Exception e) {
141 }
142
143
144
145 ThirdPartyThreadLocalRegistry.resetThreadLocals();
146 CentralizedThreadLocal.clearShortLivedThreadLocals();
147
148
149
150 DB db = DBFactoryUtil.getDB();
151
152 String dbType = db.getType();
153
154 if (dbType.equals(DB.TYPE_HYPERSONIC)) {
155 Connection connection = null;
156 Statement statement = null;
157
158 try {
159 connection = DataAccess.getConnection();
160
161 statement = connection.createStatement();
162
163 statement.executeUpdate("SHUTDOWN");
164 }
165 catch (Exception e) {
166 _log.error(e, e);
167 }
168 finally {
169 DataAccess.cleanUp(connection, statement);
170 }
171 }
172
173
174
175
176
177 try {
178 LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
179 }
180 catch (Exception e) {
181 }
182
183
184
185 try {
186 Thread.sleep(1000);
187 }
188 catch (Exception e) {
189 e.printStackTrace();
190 }
191
192
193
194 PortalExecutorManagerUtil.shutdown(true);
195
196
197
198 if (GetterUtil.getBoolean(
199 PropsUtil.get(PropsKeys.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
200
201 Thread currentThread = Thread.currentThread();
202
203 ThreadGroup threadGroup = getThreadGroup();
204
205 Thread[] threads = getThreads(threadGroup);
206
207 for (Thread thread : threads) {
208 if ((thread == null) || (thread == currentThread)) {
209 continue;
210 }
211
212 try {
213 thread.interrupt();
214 }
215 catch (Exception e) {
216 }
217 }
218
219 threadGroup.destroy();
220 }
221 }
222
223 protected ThreadGroup getThreadGroup() {
224 Thread currentThread = Thread.currentThread();
225
226 ThreadGroup threadGroup = currentThread.getThreadGroup();
227
228 for (int i = 0; i < 10; i++) {
229 if (threadGroup.getParent() == null) {
230 break;
231 }
232 else {
233 threadGroup = threadGroup.getParent();
234 }
235 }
236
237 return threadGroup;
238 }
239
240 protected Thread[] getThreads(ThreadGroup threadGroup) {
241 Thread[] threads = new Thread[threadGroup.activeCount() * 2];
242
243 threadGroup.enumerate(threads);
244
245 return threads;
246 }
247
248 private static Log _log = LogFactoryUtil.getLog(GlobalShutdownAction.class);
249
250 }