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