KickJava   Java API By Example, From Geeks To Geeks.

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


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