001: /******************************************************************************
002: * ResponderSTAT.java
003: * ****************************************************************************/package org.openlaszlo.servlets.responders;
004:
005: import java.io.*;
006: import java.util.Date;
007: import java.util.Properties;
008: import javax.servlet.ServletConfig;
009: import javax.servlet.ServletException;
010: import javax.servlet.http.HttpServletRequest;
011: import javax.servlet.http.HttpServletResponse;
012: import javax.servlet.ServletOutputStream;
013: import org.openlaszlo.cache.RequestCache;
014: import org.openlaszlo.server.LPS;
015: import org.openlaszlo.servlets.LZServlet;
016: import org.openlaszlo.utils.FileUtils;
017: import org.apache.log4j.Logger;
018:
019: public final class ResponderSTAT extends ResponderAdmin {
020: private static Logger mLogger = Logger
021: .getLogger(ResponderSTAT.class);
022:
023: private static Date mLastCleared = new Date();
024:
025: protected void respondAdmin(HttpServletRequest req,
026: HttpServletResponse res) throws IOException {
027: if (!mCollectStat) {
028: respondWithMessage(res,
029: /* (non-Javadoc)
030: * @i18n.test
031: * @org-mes="Statistics collection is off."
032: */
033: org.openlaszlo.i18n.LaszloMessages.getMessage(
034: ResponderSTAT.class.getName(), "051018-41"));
035: return;
036: }
037:
038: res.setContentType("text/xml");
039: ServletOutputStream out = res.getOutputStream();
040: try {
041: String msg = statInfo(req);
042: out.println(msg);
043: } finally {
044: FileUtils.close(out);
045: }
046: }
047:
048: /**
049: * send cache info out the response in HTML
050: */
051: public static String statInfo(HttpServletRequest req)
052: throws IOException {
053: ResponderCache dataResponder = (ResponderCache) getResponder("data");
054: ResponderCache mediaResponder = (ResponderCache) getResponder("media");
055:
056: if (dataResponder != null) {
057: String durl = req.getParameter("durl");
058: if (durl != null)
059: dataResponder.mURLStat
060: .doURLCollection(durl.equals("1"));
061: }
062:
063: if (mediaResponder != null) {
064: String murl = req.getParameter("murl");
065: if (murl != null)
066: mediaResponder.mURLStat.doURLCollection(murl
067: .equals("1"));
068: }
069:
070: String clear = req.getParameter("clear");
071: if (clear != null && clear.equals("1")) {
072: if (dataResponder != null)
073: dataResponder.mURLStat.clear();
074: if (mediaResponder != null)
075: mediaResponder.mURLStat.clear();
076: Responder.mSTAT_allLoadCount.reset();
077: Responder.mSTAT_compileLoadCount.reset();
078: Responder.mSTAT_mediaLoadCount.reset();
079: Responder.mSTAT_dataLoadCount.reset();
080: Responder.clearErrorSWFCount();
081: mLastCleared = new Date();
082: }
083:
084: RequestCache mediaCache = ResponderMEDIA.getCache();
085: RequestCache dataCache = ResponderDATA.getCache();
086:
087: StringBuffer buf = new StringBuffer("");
088: buf.append("<stat");
089: buf.append(" up-since=\"").append(
090: Responder.mSTAT_startDate.toString()).append("\"");
091: buf.append(" last-cleared=\"").append(mLastCleared)
092: .append("\"");
093: buf.append(" total-error-count=\"").append(
094: Responder.getErrorSWFCount()).append("\"");
095: buf.append(">\n");
096: {
097: buf.append(LPS.getInfo(req, mContext, "info"));
098:
099: buf.append("<load>\n");
100: {
101: buf.append(Responder.mSTAT_compileLoadCount
102: .toXML("application"));
103: buf.append(Responder.mSTAT_mediaLoadCount
104: .toXML("media"));
105: buf.append(Responder.mSTAT_dataLoadCount.toXML("data"));
106: buf.append("<persistent-connection active=\"").append(
107: ResponderCONNECT.getActiveCount()).append(
108: "\" />");
109: buf.append(Responder.mSTAT_allLoadCount.toXML("all"));
110: }
111: buf.append("</load>\n");
112:
113: buf.append("<urls>");
114: if (dataResponder != null)
115: buf.append(dataResponder.mURLStat.toXML());
116: if (mediaResponder != null)
117: buf.append(mediaResponder.mURLStat.toXML());
118: buf.append("</urls>");
119: }
120: buf.append("</stat>\n");
121: return buf.toString();
122: }
123:
124: public static Responder getResponder(String lzt) {
125: return (Responder) LZServlet.mResponderMap.get(lzt);
126:
127: }
128:
129: public int getMimeType() {
130: return MIME_TYPE_XML;
131: }
132: }
|