1
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.dao.db.DB;
31 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
32 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
33 import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
34 import com.liferay.portal.kernel.events.SimpleAction;
35 import com.liferay.portal.kernel.job.JobSchedulerUtil;
36 import com.liferay.portal.kernel.log.Jdk14LogFactoryImpl;
37 import com.liferay.portal.kernel.log.Log;
38 import com.liferay.portal.kernel.log.LogFactoryUtil;
39 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
40 import com.liferay.portal.kernel.util.GetterUtil;
41 import com.liferay.portal.kernel.util.PropsKeys;
42 import com.liferay.portal.pop.POPServerUtil;
43 import com.liferay.portal.search.lucene.LuceneHelperUtil;
44 import com.liferay.portal.util.PropsUtil;
45 import com.liferay.portal.util.PropsValues;
46 import com.liferay.portlet.documentlibrary.util.DocumentConversionUtil;
47
48 import java.sql.Connection;
49 import java.sql.Statement;
50
51
56 public class GlobalShutdownAction extends SimpleAction {
57
58 public void run(String[] ids) {
59
60
62 HotDeployUtil.unregisterListeners();
63
64
66 try {
67 if (_log.isDebugEnabled()) {
68 _log.debug("Shutting down AIM");
69 }
70
71 AIMConnector.disconnect();
72 }
73 catch (Exception e) {
74 }
75
76
78 try {
79 if (_log.isDebugEnabled()) {
80 _log.debug("Shutting down ICQ");
81 }
82
83 ICQConnector.disconnect();
84 }
85 catch (Exception e) {
86 }
87
88
90 try {
91 if (_log.isDebugEnabled()) {
92 _log.debug("Shutting down MSN");
93 }
94
95 MSNConnector.disconnect();
96 }
97 catch (Exception e) {
98 }
99
100
102 try {
103 if (_log.isDebugEnabled()) {
104 _log.debug("Shutting down YM");
105 }
106
107 YMConnector.disconnect();
108 }
109 catch (Exception e) {
110 }
111
112
114 try {
115 if (_log.isDebugEnabled()) {
116 _log.debug("Shutting down JCR");
117 }
118
119 JCRFactoryUtil.shutdown();
120 }
121 catch (Exception e) {
122 }
123
124
126 LuceneHelperUtil.shutdown();
127
128
130 DocumentConversionUtil.disconnect();
131
132
134 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
135 POPServerUtil.stop();
136 }
137
138
140 try {
141 JobSchedulerUtil.shutdown();
142 }
143 catch (Exception e) {
144 }
145
146 try {
147 SchedulerEngineUtil.shutdown();
148 }
149 catch (Exception e) {
150 }
151
152
154 DB db = DBFactoryUtil.getDB();
155
156 if (db.getType().equals(DB.TYPE_HYPERSONIC)) {
157 try {
158 Connection connection = DataAccess.getConnection();
159
160 Statement statement = connection.createStatement();
161
162 statement.executeUpdate("SHUTDOWN");
163
164 statement.close();
165 }
166 catch (Exception e) {
167 _log.error(e, e);
168 }
169 }
170
171
175 try {
176 LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
177 }
178 catch (Exception e) {
179 }
180
181
183 if (GetterUtil.getBoolean(PropsUtil.get(
184 PropsKeys.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
185
186 Thread thread = Thread.currentThread();
187
188 ThreadGroup threadGroup = thread.getThreadGroup();
189
190 for (int i = 0; i < 10; i++) {
191 if (threadGroup.getParent() == null) {
192 break;
193 }
194 else {
195 threadGroup = threadGroup.getParent();
196 }
197 }
198
199
201 Thread[] threads = new Thread[threadGroup.activeCount() * 2];
202
203 threadGroup.enumerate(threads);
204
205 for (int i = 0; i < threads.length; i++) {
206 Thread curThread = threads[i];
207
208 if ((curThread != null) && (curThread != thread)) {
209 try {
210 curThread.interrupt();
211 }
212 catch (Exception e) {
213 }
214 }
215 }
216
217 threadGroup.destroy();
218 }
219 }
220
221 private static Log _log = LogFactoryUtil.getLog(GlobalShutdownAction.class);
222
223 }