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