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.job.JobScheduler;
31 import com.liferay.portal.kernel.log.Jdk14LogFactoryImpl;
32 import com.liferay.portal.kernel.log.LogFactoryUtil;
33 import com.liferay.portal.kernel.util.GetterUtil;
34 import com.liferay.portal.smtp.SMTPServerUtil;
35 import com.liferay.portal.struts.ActionException;
36 import com.liferay.portal.struts.SimpleAction;
37 import com.liferay.portal.util.PropsUtil;
38
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41
42
48 public class GlobalShutdownAction extends SimpleAction {
49
50 public void run(String[] ids) throws ActionException {
51
52
54 try {
55 _log.debug("Shutting down AIM");
56
57 AIMConnector.disconnect();
58 }
59 catch (Exception e) {
60 }
61
62
64 try {
65 _log.debug("Shutting down ICQ");
66
67 ICQConnector.disconnect();
68 }
69 catch (Exception e) {
70 }
71
72
74 try {
75 _log.debug("Shutting down MSN");
76
77 MSNConnector.disconnect();
78 }
79 catch (Exception e) {
80 }
81
82
84 try {
85 _log.debug("Shutting down YM");
86
87 YMConnector.disconnect();
88 }
89 catch (Exception e) {
90 }
91
92
94 try {
95 _log.debug("Shutting down JCR");
96
97 JCRFactoryUtil.shutdown();
98 }
99 catch (Exception e) {
100 }
101
102
104 try {
105 JobScheduler.shutdown();
106 }
107 catch (Exception e) {
108 }
109
110
112 if (GetterUtil.getBoolean(PropsUtil.get(
113 PropsUtil.SMTP_SERVER_ENABLED))) {
114
115 SMTPServerUtil.stop();
116 }
117
118
122 try {
123 LogFactoryUtil.setLogFactory(new Jdk14LogFactoryImpl());
124 }
125 catch (Exception e) {
126 }
127
128
130 if (GetterUtil.getBoolean(PropsUtil.get(
131 PropsUtil.SHUTDOWN_PROGRAMMATICALLY_EXIT))) {
132
133 Thread thread = Thread.currentThread();
134
135 ThreadGroup threadGroup = thread.getThreadGroup();
136
137 for (int i = 0; i < 10; i++) {
138 if (threadGroup.getParent() == null) {
139 break;
140 }
141 else {
142 threadGroup = threadGroup.getParent();
143 }
144 }
145
146
148 Thread[] threads = new Thread[threadGroup.activeCount() * 2];
149
150 threadGroup.enumerate(threads);
151
152 for (int i = 0; i < threads.length; i++) {
153 Thread curThread = threads[i];
154
155 if ((curThread != null) && (curThread != thread)) {
156 try {
157 curThread.interrupt();
158 }
159 catch (Exception e) {
160 }
161 }
162 }
163
164 threadGroup.destroy();
165 }
166 }
167
168 private static Log _log = LogFactory.getLog(GlobalShutdownAction.class);
169
170 }