jsedek@2019
|
1 |
/*
|
jtulach@2556
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jsedek@2019
|
3 |
*
|
jtulach@2556
|
4 |
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
|
jsedek@2019
|
5 |
*
|
jtulach@2556
|
6 |
* The contents of this file are subject to the terms of either the GNU
|
jtulach@2556
|
7 |
* General Public License Version 2 only ("GPL") or the Common
|
jtulach@2556
|
8 |
* Development and Distribution License("CDDL") (collectively, the
|
jtulach@2556
|
9 |
* "License"). You may not use this file except in compliance with the
|
jtulach@2556
|
10 |
* License. You can obtain a copy of the License at
|
jtulach@2556
|
11 |
* http://www.netbeans.org/cddl-gplv2.html
|
jtulach@2556
|
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jtulach@2556
|
13 |
* specific language governing permissions and limitations under the
|
jtulach@2556
|
14 |
* License. When distributing the software, include this License Header
|
jtulach@2556
|
15 |
* Notice in each file and include the License file at
|
jtulach@2556
|
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
jtulach@2556
|
17 |
* particular file as subject to the "Classpath" exception as provided
|
jtulach@2556
|
18 |
* by Sun in the GPL Version 2 section of the License file that
|
jtulach@2556
|
19 |
* accompanied this code. If applicable, add the following below the
|
jtulach@2556
|
20 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jtulach@2556
|
21 |
* your own identifying information:
|
jsedek@2019
|
22 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jsedek@2019
|
23 |
*
|
jtulach@2556
|
24 |
* Contributor(s):
|
jtulach@2556
|
25 |
*
|
jsedek@2019
|
26 |
* The Original Software is NetBeans. The Initial Developer of the Original
|
jsedek@2019
|
27 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
|
jsedek@2019
|
28 |
* Microsystems, Inc. All Rights Reserved.
|
jtulach@2556
|
29 |
*
|
jtulach@2556
|
30 |
* If you wish your version of this file to be governed by only the CDDL
|
jtulach@2556
|
31 |
* or only the GPL Version 2, indicate your decision by adding
|
jtulach@2556
|
32 |
* "[Contributor] elects to include this software in this distribution
|
jtulach@2556
|
33 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
jtulach@2556
|
34 |
* single choice of license, a recipient has the option to distribute
|
jtulach@2556
|
35 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
jtulach@2556
|
36 |
* to extend the choice of license to its licensees as provided above.
|
jtulach@2556
|
37 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
jtulach@2556
|
38 |
* Version 2 license, then the option applies only if the new code is
|
jtulach@2556
|
39 |
* made subject to such option by the copyright holder.
|
jsedek@2019
|
40 |
*/
|
jsedek@2019
|
41 |
|
jsedek@2019
|
42 |
package org.netbeans.server.uihandler.statistics;
|
jsedek@2019
|
43 |
|
jsedek@2551
|
44 |
import java.util.ArrayList;
|
jsedek@2044
|
45 |
import java.util.Collections;
|
jsedek@2551
|
46 |
import java.util.Comparator;
|
jsedek@2044
|
47 |
import java.util.Iterator;
|
jsedek@2044
|
48 |
import java.util.List;
|
jsedek@2019
|
49 |
import java.util.Map;
|
jsedek@2019
|
50 |
import java.util.TreeMap;
|
jtulach@2286
|
51 |
import java.util.logging.Level;
|
jsedek@2019
|
52 |
import java.util.logging.LogRecord;
|
jtulach@2286
|
53 |
import java.util.logging.Logger;
|
jtulach@2548
|
54 |
import java.util.prefs.BackingStoreException;
|
jtulach@2548
|
55 |
import java.util.prefs.Preferences;
|
jsedek@2044
|
56 |
import javax.servlet.jsp.PageContext;
|
jsedek@2044
|
57 |
import org.netbeans.modules.exceptions.entity.Exceptions;
|
jsedek@2044
|
58 |
import org.netbeans.modules.exceptions.utils.PersistenceUtils;
|
jsedek@2019
|
59 |
import org.netbeans.server.uihandler.Statistics;
|
jsedek@2076
|
60 |
import org.netbeans.server.uihandler.Utils;
|
jsedek@2019
|
61 |
import org.netbeans.server.uihandler.statistics.ExceptionReports.Data;
|
jsedek@2019
|
62 |
/**
|
jsedek@2019
|
63 |
*
|
jsedek@2019
|
64 |
* @author Jindrich Sedek
|
jsedek@2019
|
65 |
*/
|
jsedek@2019
|
66 |
|
jsedek@2019
|
67 |
public class ExceptionReports extends Statistics<ExceptionReports.Data>{
|
jtulach@2286
|
68 |
private static Logger LOG = Logger.getLogger(ExceptionReports.class.getName());
|
jsedek@2019
|
69 |
public ExceptionReports() {
|
jsedek@2019
|
70 |
super("ExceptionReports");
|
jsedek@2019
|
71 |
}
|
jsedek@2019
|
72 |
|
jsedek@2019
|
73 |
protected Data newData() {
|
jsedek@2044
|
74 |
return null;
|
jsedek@2019
|
75 |
}
|
jsedek@2019
|
76 |
|
jsedek@2019
|
77 |
protected Data process(LogRecord rec) {
|
jsedek@2044
|
78 |
return null;
|
jsedek@2019
|
79 |
}
|
jsedek@2019
|
80 |
|
jsedek@2019
|
81 |
protected Data join(Data one, Data two) {
|
jsedek@2044
|
82 |
return null;
|
jsedek@2019
|
83 |
}
|
jsedek@2019
|
84 |
|
jsedek@2019
|
85 |
protected Data finishSessionUpload(String userId, int sessionNumber, boolean initialParse, Data data) {
|
jsedek@2044
|
86 |
return null;
|
jsedek@2044
|
87 |
}
|
jsedek@2044
|
88 |
|
jsedek@2044
|
89 |
@Override
|
jsedek@2044
|
90 |
protected void registerPageContext(PageContext page, String name, Data data) {
|
jsedek@2044
|
91 |
Data dat = new Data();
|
jsedek@2044
|
92 |
Map<String, Integer> result = new TreeMap<String, Integer>();
|
jtulach@2286
|
93 |
try {
|
jtulach@2286
|
94 |
PersistenceUtils pUtils = Utils.getPersistenceUtils();
|
jtulach@2286
|
95 |
dat.globalReportsNumber = pUtils.count(Exceptions.class);
|
jtulach@2286
|
96 |
List<String> list = pUtils.getDistinct(Exceptions.class, "component");
|
jtulach@2286
|
97 |
Iterator<String> iter = list.iterator();
|
jsedek@2717
|
98 |
int minimumToShow = dat.globalReportsNumber / 50; // 2%
|
jtulach@2286
|
99 |
while (iter.hasNext()){
|
jtulach@2286
|
100 |
//List<String> list = iter.next();
|
jtulach@2286
|
101 |
String str = iter.next();
|
jtulach@2286
|
102 |
int count = pUtils.count(Exceptions.class, "entity.component = '" + str+"'");
|
jsedek@2551
|
103 |
if ((str != null)&&(count > minimumToShow)) result.put(str, count);
|
jtulach@2286
|
104 |
}
|
jtulach@2286
|
105 |
} catch (Exception ex) {
|
jtulach@2286
|
106 |
// requires database and that is not present
|
jtulach@2286
|
107 |
LOG.log(Level.WARNING, ex.getMessage(), ex);
|
jsedek@2019
|
108 |
}
|
jsedek@2044
|
109 |
dat.components = result;
|
jsedek@2044
|
110 |
super.registerPageContext(page, name, dat);
|
jsedek@2019
|
111 |
}
|
jsedek@2019
|
112 |
|
jsedek@2019
|
113 |
public static final class Data{
|
jsedek@2019
|
114 |
int globalReportsNumber;
|
jsedek@2019
|
115 |
Map<String, Integer> components;
|
jsedek@2019
|
116 |
|
jsedek@2019
|
117 |
public Data(){
|
jsedek@2019
|
118 |
globalReportsNumber = 0;
|
jsedek@2019
|
119 |
}
|
jsedek@2019
|
120 |
|
jsedek@2044
|
121 |
public Data(int global){
|
jsedek@2044
|
122 |
globalReportsNumber = global;
|
jsedek@2019
|
123 |
}
|
jsedek@2019
|
124 |
|
jsedek@2019
|
125 |
public int getGlobalReportsNumber(){
|
jsedek@2019
|
126 |
return globalReportsNumber;
|
jsedek@2019
|
127 |
}
|
jsedek@2019
|
128 |
|
jsedek@2019
|
129 |
public Map<String, Integer> getComponents(){
|
jsedek@2044
|
130 |
if (components!= null) return components;
|
jtulach@2548
|
131 |
else return Collections.emptyMap();
|
jsedek@2019
|
132 |
}
|
jsedek@2019
|
133 |
|
jsedek@2551
|
134 |
public List<String> getSortedKeys(){
|
jsedek@2551
|
135 |
List<String> list = new ArrayList(components.keySet());
|
jsedek@2551
|
136 |
Collections.sort(list, new ReportsComparator());
|
jsedek@2551
|
137 |
return list;
|
jsedek@2551
|
138 |
}
|
jsedek@2551
|
139 |
|
jsedek@2551
|
140 |
private final class ReportsComparator implements Comparator<String>{
|
jsedek@2551
|
141 |
|
jsedek@2551
|
142 |
public int compare(String o1, String o2) {
|
jsedek@2717
|
143 |
return components.get(o2).compareTo(components.get(o1));
|
jsedek@2551
|
144 |
}
|
jsedek@2551
|
145 |
|
jsedek@2551
|
146 |
}
|
jsedek@2019
|
147 |
}
|
jtulach@2548
|
148 |
|
jtulach@2548
|
149 |
protected void write(Preferences pref, Data d) throws BackingStoreException {
|
jsedek@2551
|
150 |
// data are saved in DB for this statistics
|
jtulach@2548
|
151 |
}
|
jtulach@2548
|
152 |
|
jtulach@2548
|
153 |
protected Data read(Preferences pref) throws BackingStoreException {
|
jsedek@2551
|
154 |
return null; // nothing is needed to be done
|
jtulach@2548
|
155 |
}
|
jsedek@2019
|
156 |
}
|