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