01: /******************************************************************************
02: * ResponderSETCACHESIZE.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import java.util.Properties;
07: import javax.servlet.ServletConfig;
08: import javax.servlet.ServletException;
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11: import javax.servlet.ServletOutputStream;
12: import org.openlaszlo.utils.FileUtils;
13: import org.openlaszlo.cache.Cache;
14: import org.apache.log4j.Logger;
15:
16: public final class ResponderSETCACHESIZE extends ResponderAdmin {
17: private static Logger mLogger = Logger
18: .getLogger(ResponderSETCACHESIZE.class);
19:
20: protected void respondAdmin(HttpServletRequest req,
21: HttpServletResponse res) throws IOException {
22: ServletOutputStream out = res.getOutputStream();
23: try {
24: String l = req.getParameter("size");
25: String msg = null;
26: String t = req.getParameter("t");
27: String k = req.getParameter("k");
28: boolean inMem = true;
29: Cache cache;
30: if (t != null && t.equalsIgnoreCase("data")) {
31: cache = ResponderDATA.getCache();
32: } else if (t != null && t.equalsIgnoreCase("compiler")) {
33: cache = ResponderCompile.getCompilationManager();
34: } else {
35: cache = ResponderMEDIA.getCache();
36: }
37: if (k != null && k.equalsIgnoreCase("disk")) {
38: inMem = false;
39: }
40:
41: if (l != null) {
42: long s = -1;
43: try {
44: s = Long.parseLong(l);
45: } catch (NumberFormatException e) {
46: }
47: if (s >= 0) {
48: if (inMem) {
49: cache.setMaxMemSize(s);
50: } else {
51: cache.setMaxDiskSize(s);
52: }
53: } else {
54: mLogger.error(
55: /* (non-Javadoc)
56: * @i18n.test
57: * @org-mes="ignored bad size parameter"
58: */
59: org.openlaszlo.i18n.LaszloMessages.getMessage(
60: ResponderSETCACHESIZE.class.getName(),
61: "051018-67"));
62: }
63: res.setContentType("text/xml");
64: msg = ResponderCACHEINFO.cacheInfo(false, false);
65: out.println(msg);
66: } else {
67: res.setContentType("text/html");
68: msg =
69: /* (non-Javadoc)
70: * @i18n.test
71: * @org-mes="Can't set cache size: size parameter missing from setcachesize request"
72: */
73: org.openlaszlo.i18n.LaszloMessages.getMessage(
74: ResponderSETCACHESIZE.class.getName(),
75: "051018-81");
76: mLogger.error(msg);
77: msg = msg + "<br/>"
78: + ResponderCACHEINFO.cacheInfo(false, false);
79:
80: out
81: .println("<html><head><title>LPS Cache Information</title></head>");
82: out.println("<body>");
83: out.println(msg);
84: out.println("</body></html>");
85: }
86:
87: mLogger.info(msg);
88: } finally {
89: FileUtils.close(out);
90: }
91: }
92:
93: public int getMimeType() {
94: return MIME_TYPE_XML;
95: }
96: }
|