Coverage Report - net.admin4j.ui.servlets.PerformanceDisplayServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
PerformanceDisplayServlet
50%
15/30
22%
4/18
5.5
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.ui.servlets;
 15  
 
 16  
 import java.io.IOException;
 17  
 import java.util.ArrayList;
 18  
 import java.util.Collections;
 19  
 import java.util.Comparator;
 20  
 import java.util.HashMap;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 import java.util.Set;
 24  
 import java.util.TreeSet;
 25  
 
 26  
 import javax.servlet.ServletException;
 27  
 import javax.servlet.http.HttpServletRequest;
 28  
 import javax.servlet.http.HttpServletResponse;
 29  
 
 30  
 import net.admin4j.deps.commons.beanutils.BeanComparator;
 31  
 import net.admin4j.deps.commons.collections.comparators.ReverseComparator;
 32  
 import net.admin4j.deps.commons.lang3.StringUtils;
 33  
 import net.admin4j.timer.TaskTimerFactory;
 34  
 import net.admin4j.util.FreemarkerUtils;
 35  
 import net.admin4j.vo.DataMeasurementSummaryVO;
 36  
 import net.admin4j.vo.PerformanceSummaryVO;
 37  
 
 38  
 /**
 39  
  * Will display collected performance statistics.
 40  
  * @author D. Ashmore
 41  
  * @since 1.0
 42  
  */
 43  6
 public class PerformanceDisplayServlet extends AdminDisplayServlet {
 44  
 
 45  
     private static final long serialVersionUID = 7019549673215008662L;
 46  
     public static final String PUBLIC_HANDLE="perf";
 47  
 
 48  
     /* (non-Javadoc)
 49  
      * @see javax.servlet.http.HttpServlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
 50  
      */
 51  
     @Override
 52  
     public void service(HttpServletRequest request, HttpServletResponse response)
 53  
             throws ServletException, IOException {
 54  
 
 55  3
         String actionStr = request.getParameter("action");
 56  0
         if ( !StringUtils.isEmpty(actionStr)) {
 57  0
             if ("delete".equalsIgnoreCase(actionStr)) {
 58  0
                 TaskTimerFactory.delete(request.getParameter("perfLabel"));
 59  
             }
 60  
         }
 61  
         
 62  3
         Map<String,Set<DataMeasurementSummaryVO>> summaryMap = TaskTimerFactory.getDataSummaryMap();
 63  3
         TreeSet<String> labelSet = new TreeSet<String>(summaryMap.keySet());
 64  
         
 65  3
         List<PerformanceSummaryVO> summaryList = new ArrayList<PerformanceSummaryVO>();
 66  
         PerformanceSummaryVO summary;
 67  
         Set<DataMeasurementSummaryVO> measureSet;
 68  3
         for (String label: labelSet) {
 69  0
             summary = new PerformanceSummaryVO();
 70  0
             summaryList.add(summary);
 71  0
             summary.setLabel(label);
 72  
             
 73  0
             measureSet = summaryMap.get(label);
 74  0
             for (DataMeasurementSummaryVO measure: measureSet) {
 75  0
                 if (DataMeasurementSummaryVO.SummaryType.SUMMARY.equals(measure.getSummaryType())) {
 76  0
                     summary.setSummaryMeasurement(measure);
 77  
                 }
 78  0
                 else if (DataMeasurementSummaryVO.SummaryType.ROLLING_TIME.equals(measure.getSummaryType())) {
 79  0
                     summary.setRollingTimeMeasurement(measure);
 80  
                 }
 81  0
                 else if (DataMeasurementSummaryVO.SummaryType.ROLLING_NBR_OBS.equals(measure.getSummaryType())) {
 82  0
                     summary.setRollingNbrObservationsMeasurement(measure);
 83  
                 }
 84  
             }
 85  
         }
 86  
         
 87  3
         String sortField = request.getParameter("sortField"); 
 88  
         
 89  0
         if ( StringUtils.isEmpty(sortField)) {
 90  3
             sortField = "label";
 91  
         }
 92  
         
 93  3
         if ("label".equals(sortField)) {
 94  
             Collections.sort(summaryList, new BeanComparator(sortField));
 95  
         }
 96  
         else {
 97  
             Collections.sort(summaryList, new ReverseComparator(new BeanComparator(sortField)));
 98  
         }
 99  
         
 100  3
         Map<String,Object> variableMap = new HashMap<String,Object>();
 101  3
         variableMap.put("performanceSummaryList", summaryList);
 102  3
         FreemarkerUtils.addConfiguration(variableMap);
 103  
         
 104  3
         this.displayFreeMarkerPage(request, response, "performanceDisplayServletDisplay.ftl", variableMap);
 105  3
     }
 106  
     
 107  
     /* (non-Javadoc)
 108  
      * @see net.admin4j.ui.servlets.Admin4JServlet#getServletLabel()
 109  
      */
 110  
     @Override
 111  
     public String getServletLabel() {
 112  3
         return "Performance Statistics";
 113  
     }
 114  
     
 115  
 }