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