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.deploy.hot.HotDeployUtil;
31 import com.liferay.portal.kernel.events.ActionException;
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.util.GetterUtil;
37 import com.liferay.portal.pop.POPServerUtil;
38 import com.liferay.portal.util.PropsUtil;
39 import com.liferay.portal.util.PropsValues;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44
50 public class GlobalShutdownAction extends SimpleAction {
51
52 public void run(String[] ids) throws ActionException {
53
54
56 HotDeployUtil.unregisterListeners();
57
58
60 try {
61 _log.debug("Shutting down AIM");
62
63 AIMConnector.disconnect();
64 }
65 catch (Exception e) {
66 }
67
68
70 try {
71 _log.debug("Shutting down ICQ");
72
73 ICQConnector.disconnect();
74 }
75 catch (Exception e) {
76 }
77
78
80 try {
81 _log.debug("Shutting down MSN");
82
83 MSNConnector.disconnect();
84 }
85 catch (Exception e) {
86 }
87
88
90 try {
91 _log.debug("Shutting down YM");
92
93 YMConnector.disconnect();
94 }
95 catch (Exception e) {
96 }
97
98
100 try {
101 _log.debug("Shutting down JCR");
102
103 JCRFactoryUtil.shutdown();
104 }
105 catch (Exception e) {
106 }
107
108
110 if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
111 POPServerUtil.stop();
112 }
113
114
116 try {
117 JobSchedulerUtil.shutdown();
118 }
119 catch (Exception e) {
120 }
121
122
126 try {
127 LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
128 }
129 catch (Exception e) {
130 }
131
132
134 if (GetterUtil.getBoolean(PropsUtil.get(
135 PropsUtil.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
136
137 Thread thread = Thread.currentThread();
138
139 ThreadGroup threadGroup = thread.getThreadGroup();
140
141 for (int i = 0; i < 10; i++) {
142 if (threadGroup.getParent() == null) {
143 break;
144 }
145 else {
146 threadGroup = threadGroup.getParent();
147 }
148 }
149
150
152 Thread[] threads = new Thread[threadGroup.activeCount() * 2];
153
154 threadGroup.enumerate(threads);
155
156 for (int i = 0; i < threads.length; i++) {
157 Thread curThread = threads[i];
158
159 if ((curThread != null) && (curThread != thread)) {
160 try {
161 curThread.interrupt();
162 }
163 catch (Exception e) {
164 }
165 }
166 }
167
168 threadGroup.destroy();
169 }
170 }
171
172 private static Log _log = LogFactory.getLog(GlobalShutdownAction.class);
173
174 }