Coverage Report - org.kuali.rice.ksb.messaging.web.ThreadPoolAction
 
Classes in this File Line Coverage Branch Coverage Complexity
ThreadPoolAction
0%
0/48
0%
0/34
7
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Struts action for interacting with the queue of messages.
 42  
  *
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
             // if it's all servers, we need to find all of the BusAdmin services
 65  0
             QName serviceName = new QName(form.getApplicationId(), "busAdminService");
 66  0
             ServiceBus serviceBus = KsbApiServiceLocator.getServiceBus();
 67  0
             List<Endpoint> adminServices = serviceBus.getEndpoints(serviceName);
 68  0
             for (Endpoint adminEndpoint : adminServices) {
 69  
                 try {
 70  0
                     BusAdminService adminService = (BusAdminService)adminEndpoint.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 " + adminEndpoint.getServiceConfiguration().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  
 }