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.hot.HotDeployUtil;
026 import com.liferay.portal.kernel.events.SimpleAction;
027 import com.liferay.portal.kernel.log.Jdk14LogFactoryImpl;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.PropsKeys;
033 import com.liferay.portal.kernel.util.ThreadLocalRegistry;
034 import com.liferay.portal.pop.POPServerUtil;
035 import com.liferay.portal.search.lucene.LuceneHelperUtil;
036 import com.liferay.portal.util.PropsUtil;
037 import com.liferay.portal.util.PropsValues;
038 import com.liferay.portlet.documentlibrary.util.DocumentConversionUtil;
039 import com.liferay.util.ThirdPartyThreadLocalRegistry;
040
041 import java.sql.Connection;
042 import java.sql.Statement;
043
044
047 public class GlobalShutdownAction extends SimpleAction {
048
049 public void run(String[] ids) {
050
051
052
053 HotDeployUtil.unregisterListeners();
054
055
056
057 try {
058 if (_log.isDebugEnabled()) {
059 _log.debug("Shutting down AIM");
060 }
061
062 AIMConnector.disconnect();
063 }
064 catch (Exception e) {
065 }
066
067
068
069 try {
070 if (_log.isDebugEnabled()) {
071 _log.debug("Shutting down ICQ");
072 }
073
074 ICQConnector.disconnect();
075 }
076 catch (Exception e) {
077 }
078
079
080
081 try {
082 if (_log.isDebugEnabled()) {
083 _log.debug("Shutting down MSN");
084 }
085
086 MSNConnector.disconnect();
087 }
088 catch (Exception e) {
089 }
090
091
092
093 try {
094 if (_log.isDebugEnabled()) {
095 _log.debug("Shutting down YM");
096 }
097
098 YMConnector.disconnect();
099 }
100 catch (Exception e) {
101 }
102
103
104
105 try {
106 if (_log.isDebugEnabled()) {
107 _log.debug("Shutting down JCR");
108 }
109
110 JCRFactoryUtil.shutdown();
111 }
112 catch (Exception e) {
113 }
114
115
116
117 LuceneHelperUtil.shutdown();
118
119
120
121 DocumentConversionUtil.disconnect();
122
123
124
125 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
126 POPServerUtil.stop();
127 }
128
129
130
131 try {
132 SchedulerEngineUtil.shutdown();
133 }
134 catch (Exception e) {
135 }
136
137
138
139 ThirdPartyThreadLocalRegistry.resetThreadLocals();
140 ThreadLocalRegistry.resetThreadLocals();
141
142
143
144 DB db = DBFactoryUtil.getDB();
145
146 if (db.getType().equals(DB.TYPE_HYPERSONIC)) {
147 try {
148 Connection connection = DataAccess.getConnection();
149
150 Statement statement = connection.createStatement();
151
152 statement.executeUpdate("SHUTDOWN");
153
154 statement.close();
155 }
156 catch (Exception e) {
157 _log.error(e, e);
158 }
159 }
160
161
162
163
164
165 try {
166 LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
167 }
168 catch (Exception e) {
169 }
170
171
172
173 try {
174 Thread.sleep(1000);
175 }
176 catch (Exception e) {
177 e.printStackTrace();
178 }
179
180
181
182 if (GetterUtil.getBoolean(PropsUtil.get(
183 PropsKeys.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
184
185 Thread currentThread = Thread.currentThread();
186
187 ThreadGroup threadGroup = currentThread.getThreadGroup();
188
189 for (int i = 0; i < 10; i++) {
190 if (threadGroup.getParent() == null) {
191 break;
192 }
193 else {
194 threadGroup = threadGroup.getParent();
195 }
196 }
197
198 Thread[] threads = new Thread[threadGroup.activeCount() * 2];
199
200 threadGroup.enumerate(threads);
201
202 for (Thread thread : threads) {
203 if ((thread == null) || (thread == currentThread)) {
204 continue;
205 }
206
207 try {
208 thread.interrupt();
209 }
210 catch (Exception e) {
211 }
212 }
213
214 threadGroup.destroy();
215 }
216 }
217
218 private static Log _log = LogFactoryUtil.getLog(GlobalShutdownAction.class);
219
220 }