KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > servlets > responders > ResponderSTAT


1 /******************************************************************************
2  * ResponderSTAT.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.servlets.responders;
11
12 import java.io.*;
13 import java.util.Date JavaDoc;
14 import java.util.Properties JavaDoc;
15 import javax.servlet.ServletConfig JavaDoc;
16 import javax.servlet.ServletException JavaDoc;
17 import javax.servlet.http.HttpServletRequest JavaDoc;
18 import javax.servlet.http.HttpServletResponse JavaDoc;
19 import javax.servlet.ServletOutputStream JavaDoc;
20 import org.openlaszlo.cache.RequestCache;
21 import org.openlaszlo.server.LPS;
22 import org.openlaszlo.servlets.LZServlet;
23 import org.openlaszlo.utils.FileUtils;
24 import org.apache.log4j.Logger;
25
26 public final class ResponderSTAT extends ResponderAdmin
27 {
28     private static Logger mLogger = Logger.getLogger(ResponderSTAT.class);
29
30     private static Date JavaDoc mLastCleared = new Date JavaDoc();
31
32     protected void respondAdmin(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
33         throws IOException
34     {
35         if ( ! mCollectStat ) {
36             respondWithMessage(res, "Statistics collection is off.");
37             return;
38         }
39
40         res.setContentType ("text/xml");
41         ServletOutputStream JavaDoc out = res.getOutputStream();
42         try {
43             String JavaDoc msg = statInfo(req);
44             out.println(msg);
45         } finally {
46             FileUtils.close(out);
47         }
48     }
49
50     /**
51      * send cache info out the response in HTML
52      */

53     public static String JavaDoc statInfo(HttpServletRequest JavaDoc req)
54         throws IOException
55     {
56         ResponderCache dataResponder = (ResponderCache)getResponder("data");
57         ResponderCache mediaResponder = (ResponderCache)getResponder("media");
58
59         if (dataResponder != null) {
60             String JavaDoc durl = req.getParameter("durl");
61             if (durl != null)
62                 dataResponder.mURLStat.doURLCollection(durl.equals("1"));
63         }
64
65         if (mediaResponder != null) {
66             String JavaDoc murl = req.getParameter("murl");
67             if (murl != null)
68                 mediaResponder.mURLStat.doURLCollection(murl.equals("1"));
69         }
70
71         String JavaDoc clear = req.getParameter("clear");
72         if (clear != null && clear.equals("1")) {
73             if (dataResponder != null)
74                 dataResponder.mURLStat.clear();
75             if (mediaResponder != null)
76                 mediaResponder.mURLStat.clear();
77             Responder.mSTAT_allLoadCount.reset();
78             Responder.mSTAT_compileLoadCount.reset();
79             Responder.mSTAT_mediaLoadCount.reset();
80             Responder.mSTAT_dataLoadCount.reset();
81             Responder.clearErrorSWFCount();
82             mLastCleared = new Date JavaDoc();
83         }
84
85         RequestCache mediaCache = ResponderMEDIA.getCache();
86         RequestCache dataCache = ResponderDATA.getCache();
87
88         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("");
89         buf.append("<stat");
90         buf.append(" up-since=\"").append(Responder.mSTAT_startDate.toString()).append("\"");
91         buf.append(" last-cleared=\"").append(mLastCleared).append("\"");
92         buf.append(" total-error-count=\"").append(Responder.getErrorSWFCount()).append("\"");
93         buf.append(">\n");
94         {
95             buf.append(LPS.getInfo(req, mContext, "info"));
96
97             buf.append("<load>\n");
98             {
99                 buf.append(Responder.mSTAT_compileLoadCount.toXML("application"));
100                 buf.append(Responder.mSTAT_mediaLoadCount.toXML("media"));
101                 buf.append(Responder.mSTAT_dataLoadCount.toXML("data"));
102                 buf.append("<persistent-connection active=\"")
103                     .append(ResponderCONNECT.getActiveCount())
104                     .append("\" />");
105                 buf.append(Responder.mSTAT_allLoadCount.toXML("all"));
106             }
107             buf.append("</load>\n");
108
109             buf.append("<urls>");
110             if (dataResponder != null)
111                 buf.append(dataResponder.mURLStat.toXML());
112             if (mediaResponder != null)
113                 buf.append(mediaResponder.mURLStat.toXML());
114             buf.append("</urls>");
115         }
116         buf.append("</stat>\n");
117         return buf.toString();
118     }
119
120     public static Responder getResponder(String JavaDoc lzt)
121     {
122         return (Responder) LZServlet.mResponderMap.get(lzt);
123         
124     }
125
126     public int getMimeType()
127     {
128         return MIME_TYPE_XML;
129     }
130 }
131
Popular Tags