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