KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > server > uihandler > Statistics


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
16  */

17
18 package org.netbeans.server.uihandler;
19
20 import java.util.logging.LogRecord JavaDoc;
21 import javax.servlet.jsp.PageContext JavaDoc;
22
23 /** A provider of one kind of statistics for the UI handler server.
24  * The provider should be a subclass of this call, with a statically
25  * defined <code>Data</code> parameter to hold the actual statistics.
26  * For example:
27  * <pre>
28  * public class CountRecords extends Statistics&lt;Integer&gt; {
29  * public CountRecords() {
30  * super("CountRecords");
31  * }
32  * // etc.
33  * }
34  * </pre>
35  * This class should be registered in
36  * <code>META-INF/services/org.netbeans.server.uihandler.Statistics</code>
37  * file. Then it is picked by the processing server up and its methods
38  * are called, and feeded with <code>LogRecord</code>s. When a request
39  * for a page is made via {@link LogRecords#preparePage} three parameters
40  * are inserted into <code>PageContext</code>, for the CountRecords example
41  * that would be:
42  * <ul>
43  * <li>globalCountRecords
44  * <li>userCountRecords
45  * <li>lastCountRecords
46  * </ul>
47  * Each of them contains a pointer to the "Data" - e.g. <code>Integer</code>
48  * in case of <code>CountRecords</code>. These beans can then be used
49  * from any JSP page.
50  * <p>
51  * The <code>Data</code> object is supposed to be immutable and shall not
52  * be modified. Instead new copy should be created in each method of the
53  * Statistics class if necessary.
54  *
55  * @param Data type of data this statistic produces and consumes
56  * @author Jaroslav Tulach
57  */

58 public abstract class Statistics<Data> {
59     final String JavaDoc name;
60
61     /** Creates new statistics with given name. Constructor for subclasses.
62      * @param name name of the statistics
63      */

64     protected Statistics(String JavaDoc name) {
65         this.name = name;
66     }
67     
68     /** Creates new, empty data for statistics.
69      * @return the data, not null
70      */

71     protected abstract Data newData();
72
73     /** Reads data from a record and converts them into
74      * reasonable data representation
75      *
76      * @param rec the record to analyse
77      * @return data representing the values in the record, not null
78      */

79     protected abstract Data process(LogRecord JavaDoc rec);
80     
81     /** Called when all records in one session have been processed.
82      *
83      * @param userId identification of the user
84      * @param sessionNumber the id of the session for the user
85      * @param initialParse is this initial upload or just a reparse from
86      * data existing on a disk
87      * @param d the data collected from the log records found in the session
88      * @return new data that should represent the session
89      */

90     protected abstract Data finishSessionUpload(
91         String JavaDoc userId, int sessionNumber, boolean initialParse, Data d
92     );
93     
94     /** Merges values of two data and produces a concatation
95      * or an average, etc. representing the merged data.
96      *
97      * @param one input data
98      * @param two input data
99      * @return merged values, not null
100      */

101     protected abstract Data join(Data one, Data two);
102     
103     
104     /** Registers given data into page context for consumption by associated
105      * JSP page. The default implementation just assigns the data to the
106      * name.
107      *
108      * @param page page context to fill
109      * @param name name of the variable to assign there
110      * @param data the data to assign to the variable
111      */

112     protected void registerPageContext(PageContext JavaDoc page, String JavaDoc name, Data data) {
113         page.setAttribute(name, data);
114     }
115 }
116
Popular Tags