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