1 4 5 9 10 package org.openlaszlo.servlets.responders; 11 12 import java.io.*; 13 import java.util.Date ; 14 import java.util.Properties ; 15 import javax.servlet.ServletConfig ; 16 import javax.servlet.ServletException ; 17 import javax.servlet.http.HttpServletRequest ; 18 import javax.servlet.http.HttpServletResponse ; 19 import javax.servlet.ServletOutputStream ; 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 mLastCleared = new Date (); 31 32 protected void respondAdmin(HttpServletRequest req, HttpServletResponse 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 out = res.getOutputStream(); 42 try { 43 String msg = statInfo(req); 44 out.println(msg); 45 } finally { 46 FileUtils.close(out); 47 } 48 } 49 50 53 public static String statInfo(HttpServletRequest req) 54 throws IOException 55 { 56 ResponderCache dataResponder = (ResponderCache)getResponder("data"); 57 ResponderCache mediaResponder = (ResponderCache)getResponder("media"); 58 59 if (dataResponder != null) { 60 String durl = req.getParameter("durl"); 61 if (durl != null) 62 dataResponder.mURLStat.doURLCollection(durl.equals("1")); 63 } 64 65 if (mediaResponder != null) { 66 String murl = req.getParameter("murl"); 67 if (murl != null) 68 mediaResponder.mURLStat.doURLCollection(murl.equals("1")); 69 } 70 71 String 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 (); 83 } 84 85 RequestCache mediaCache = ResponderMEDIA.getCache(); 86 RequestCache dataCache = ResponderDATA.getCache(); 87 88 StringBuffer buf = new StringBuffer (""); 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 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 |