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