1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.kuali.rice.ksb.messaging.web; |
15 | |
|
16 | |
import java.io.IOException; |
17 | |
import java.util.List; |
18 | |
|
19 | |
import javax.servlet.ServletException; |
20 | |
import javax.servlet.http.HttpServletRequest; |
21 | |
import javax.servlet.http.HttpServletResponse; |
22 | |
import javax.xml.namespace.QName; |
23 | |
|
24 | |
import org.apache.commons.lang.StringUtils; |
25 | |
import org.apache.struts.action.ActionForm; |
26 | |
import org.apache.struts.action.ActionForward; |
27 | |
import org.apache.struts.action.ActionMapping; |
28 | |
import org.apache.struts.action.ActionMessages; |
29 | |
import org.kuali.rice.core.config.ConfigContext; |
30 | |
import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocator; |
31 | |
import org.kuali.rice.ksb.messaging.RemotedServiceHolder; |
32 | |
import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory; |
33 | |
import org.kuali.rice.ksb.messaging.service.BusAdminService; |
34 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
35 | |
import org.kuali.rice.ksb.util.KSBConstants; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class ThreadPoolAction extends KSBAction { |
44 | |
|
45 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ThreadPoolAction.class); |
46 | |
|
47 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, |
48 | |
HttpServletResponse response) throws IOException, ServletException { |
49 | 0 | return mapping.findForward("basic"); |
50 | |
} |
51 | |
|
52 | |
public ActionForward update(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, |
53 | |
HttpServletResponse response) throws Exception { |
54 | 0 | ThreadPoolForm form = (ThreadPoolForm)actionForm; |
55 | 0 | if (form.getTimeIncrement() != null && form.getTimeIncrement().longValue() <= 0) { |
56 | 0 | form.setTimeIncrement(null); |
57 | |
} |
58 | 0 | if (form.getMaxRetryAttempts() != null && form.getMaxRetryAttempts().longValue() < 0) { |
59 | 0 | form.setMaxRetryAttempts(null); |
60 | |
} |
61 | 0 | if (form.isAllServers()) { |
62 | |
|
63 | 0 | QName qName = new QName(form.getServiceNamespace(), "busAdminService"); |
64 | 0 | RemoteResourceServiceLocator remoteResourceLocator = KSBResourceLoaderFactory.getRemoteResourceLocator(); |
65 | 0 | List<RemotedServiceHolder> adminServices = remoteResourceLocator.getAllServices(qName); |
66 | 0 | for (RemotedServiceHolder adminServiceHolder : adminServices) { |
67 | |
try { |
68 | 0 | BusAdminService adminService = (BusAdminService)adminServiceHolder.getService(); |
69 | 0 | adminService.setCorePoolSize(form.getCorePoolSize()); |
70 | 0 | adminService.setMaximumPoolSize(form.getMaximumPoolSize()); |
71 | 0 | adminService.setConfigProperty(KSBConstants.ROUTE_QUEUE_TIME_INCREMENT_KEY, (form.getTimeIncrement() == null ? null : form.getTimeIncrement().toString())); |
72 | 0 | adminService.setConfigProperty(KSBConstants.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY, (form.getMaxRetryAttempts() == null ? null : form.getMaxRetryAttempts().toString())); |
73 | 0 | } catch (Exception e) { |
74 | 0 | LOG.error("Failed to set thread pool sizes for busAdminService at " + adminServiceHolder.getServiceInfo().getEndpointUrl()); |
75 | 0 | } |
76 | |
} |
77 | 0 | } else { |
78 | 0 | form.getThreadPool().setCorePoolSize(form.getCorePoolSize()); |
79 | 0 | if (form.getMaximumPoolSize() < form.getCorePoolSize()) { |
80 | 0 | form.setMaximumPoolSize(form.getCorePoolSize()); |
81 | |
} |
82 | 0 | form.getThreadPool().setMaximumPoolSize(form.getMaximumPoolSize()); |
83 | |
|
84 | 0 | if (form.getTimeIncrement() == null) { |
85 | 0 | ConfigContext.getCurrentContextConfig().removeProperty(KSBConstants.ROUTE_QUEUE_TIME_INCREMENT_KEY); |
86 | |
} else { |
87 | 0 | ConfigContext.getCurrentContextConfig().putProperty(KSBConstants.ROUTE_QUEUE_TIME_INCREMENT_KEY, form.getTimeIncrement().toString()); |
88 | |
} |
89 | |
|
90 | 0 | if (form.getMaxRetryAttempts() == null) { |
91 | 0 | ConfigContext.getCurrentContextConfig().removeProperty(KSBConstants.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY); |
92 | |
} else { |
93 | 0 | ConfigContext.getCurrentContextConfig().putProperty(KSBConstants.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY, form.getMaxRetryAttempts().toString()); |
94 | |
} |
95 | |
} |
96 | 0 | return mapping.findForward("basic"); |
97 | |
} |
98 | |
|
99 | |
public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm actionForm) throws Exception { |
100 | 0 | ThreadPoolForm form = (ThreadPoolForm)actionForm; |
101 | 0 | form.setThreadPool(KSBServiceLocator.getThreadPool()); |
102 | 0 | if (form.getCorePoolSize() == null) { |
103 | 0 | form.setCorePoolSize(form.getThreadPool().getCorePoolSize()); |
104 | |
} |
105 | 0 | if (form.getMaximumPoolSize() == null) { |
106 | 0 | form.setMaximumPoolSize(form.getThreadPool().getMaximumPoolSize()); |
107 | |
} |
108 | 0 | if (form.getTimeIncrement() == null) { |
109 | 0 | String timeIncrementValue = ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.ROUTE_QUEUE_TIME_INCREMENT_KEY); |
110 | 0 | if (!StringUtils.isEmpty(timeIncrementValue)) { |
111 | 0 | form.setTimeIncrement(Long.parseLong(timeIncrementValue)); |
112 | |
} |
113 | |
} |
114 | 0 | if (form.getMaxRetryAttempts() == null) { |
115 | 0 | String maxRetryAttemptsValue = ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY); |
116 | 0 | if (!StringUtils.isEmpty(maxRetryAttemptsValue)) { |
117 | 0 | form.setMaxRetryAttempts(Long.parseLong(maxRetryAttemptsValue)); |
118 | |
} |
119 | |
} |
120 | 0 | return null; |
121 | |
} |
122 | |
|
123 | |
} |