1
19
20 package com.liferay.portal.events;
21
22 import com.liferay.portal.im.AIMConnector;
23 import com.liferay.portal.im.ICQConnector;
24 import com.liferay.portal.im.MSNConnector;
25 import com.liferay.portal.im.YMConnector;
26 import com.liferay.portal.jcr.JCRFactoryUtil;
27 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
28 import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
29 import com.liferay.portal.kernel.events.SimpleAction;
30 import com.liferay.portal.kernel.job.JobSchedulerUtil;
31 import com.liferay.portal.kernel.log.Jdk14LogFactoryImpl;
32 import com.liferay.portal.kernel.log.Log;
33 import com.liferay.portal.kernel.log.LogFactoryUtil;
34 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
35 import com.liferay.portal.kernel.util.GetterUtil;
36 import com.liferay.portal.pop.POPServerUtil;
37 import com.liferay.portal.tools.sql.DBUtil;
38 import com.liferay.portal.util.PropsKeys;
39 import com.liferay.portal.util.PropsUtil;
40 import com.liferay.portal.util.PropsValues;
41 import com.liferay.portlet.documentlibrary.util.DocumentConversionUtil;
42
43 import java.sql.Connection;
44 import java.sql.Statement;
45
46
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 DocumentConversionUtil.disconnect();
123
124
126 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
127 POPServerUtil.stop();
128 }
129
130
132 try {
133 JobSchedulerUtil.shutdown();
134 }
135 catch (Exception e) {
136 }
137
138 try {
139 SchedulerEngineUtil.shutdown();
140 }
141 catch (Exception e) {
142 }
143
144
146 DBUtil dbUtil = DBUtil.getInstance();
147
148 if (dbUtil.getType().equals(DBUtil.TYPE_HYPERSONIC)) {
149 try {
150 Connection connection = DataAccess.getConnection();
151
152 Statement statement = connection.createStatement();
153
154 statement.executeUpdate("SHUTDOWN");
155
156 statement.close();
157 }
158 catch (Exception e) {
159 _log.error(e, e);
160 }
161 }
162
163
167 try {
168 LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
169 }
170 catch (Exception e) {
171 }
172
173
175 if (GetterUtil.getBoolean(PropsUtil.get(
176 PropsKeys.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
177
178 Thread thread = Thread.currentThread();
179
180 ThreadGroup threadGroup = thread.getThreadGroup();
181
182 for (int i = 0; i < 10; i++) {
183 if (threadGroup.getParent() == null) {
184 break;
185 }
186 else {
187 threadGroup = threadGroup.getParent();
188 }
189 }
190
191
193 Thread[] threads = new Thread[threadGroup.activeCount() * 2];
194
195 threadGroup.enumerate(threads);
196
197 for (int i = 0; i < threads.length; i++) {
198 Thread curThread = threads[i];
199
200 if ((curThread != null) && (curThread != thread)) {
201 try {
202 curThread.interrupt();
203 }
204 catch (Exception e) {
205 }
206 }
207 }
208
209 threadGroup.destroy();
210 }
211 }
212
213 private static Log _log = LogFactoryUtil.getLog(GlobalShutdownAction.class);
214
215 }