1 4 5 9 10 package org.openlaszlo.servlets.responders; 11 12 import java.io.*; 13 import java.util.Properties ; 14 import javax.servlet.ServletConfig ; 15 import javax.servlet.ServletException ; 16 import javax.servlet.http.HttpServletRequest ; 17 import javax.servlet.http.HttpServletResponse ; 18 import javax.servlet.ServletOutputStream ; 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 req, HttpServletResponse res) 28 throws IOException 29 { 30 ServletOutputStream out = res.getOutputStream(); 31 try { 32 String l = req.getParameter("size"); 33 String msg = null; 34 String t = req.getParameter("t"); 35 String 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 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 |