1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
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 | |
|
40 | |
|
41 | |
|
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 | |
|
49 | |
|
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 | |
|
108 | |
|
109 | |
|
110 | |
@Override |
111 | |
public String getServletLabel() { |
112 | 3 | return "Performance Statistics"; |
113 | |
} |
114 | |
|
115 | |
} |