1 41 42 43 package org.jahia.admin.status; 44 45 import java.io.IOException ; 46 import java.util.Iterator ; 47 48 import javax.servlet.ServletException ; 49 import javax.servlet.http.HttpServletRequest ; 50 import javax.servlet.http.HttpServletResponse ; 51 import javax.servlet.http.HttpSession ; 52 53 import org.jahia.bin.JahiaAdministration; 54 import org.jahia.registries.ServicesRegistry; 55 import org.jahia.services.cache.CacheFactory; 56 import org.jahia.services.cache.Cache; 57 58 59 69 70 public class ManageStatus { 71 72 73 private static org.apache.log4j.Logger logger = 74 org.apache.log4j.Logger.getLogger (ManageStatus.class); 75 76 private static final String CLASS_NAME = JahiaAdministration.CLASS_NAME; 77 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 78 79 80 87 public ManageStatus (HttpServletRequest request, 88 HttpServletResponse response, 89 HttpSession session) 90 throws Throwable { 91 userRequestDispatcher (request, response, session); 92 } 93 94 95 102 private void userRequestDispatcher (HttpServletRequest request, 103 HttpServletResponse response, 104 HttpSession session) 105 throws Throwable { 106 String operation = request.getParameter ("sub"); 107 108 if (operation.equals ("display")) { 109 displaySettings (request, response, session); 110 } else if (operation.equals ("process")) { 111 processSettings (request, response, session); 112 } 113 } 114 115 116 123 private void displaySettings (HttpServletRequest request, 124 HttpServletResponse response, 125 HttpSession session) 126 throws IOException , ServletException { 127 Long freeMemoryInBytes = (Long )session.getAttribute (CLASS_NAME + "freeMemoryInBytes"); 129 Long totalMemoryInBytes = (Long )session.getAttribute (CLASS_NAME + "totalMemoryInBytes"); 130 Integer outputCacheSize = (Integer )session.getAttribute (CLASS_NAME + "outputCacheSize"); 131 Integer outputCacheMaxSize = (Integer )session.getAttribute (CLASS_NAME + "outputCacheMaxSize"); 132 133 if (freeMemoryInBytes == null) { 135 freeMemoryInBytes = new Long (Runtime.getRuntime ().freeMemory ()); 136 } 137 if (totalMemoryInBytes == null) { 138 totalMemoryInBytes = new Long (Runtime.getRuntime ().totalMemory ()); 139 } 140 try { 141 if (outputCacheSize == null) { 142 outputCacheSize = new Integer (CacheFactory.getHtmlCache().size()); 143 } 144 if (outputCacheMaxSize == null) { 145 outputCacheMaxSize = new Integer (CacheFactory.getHtmlCache(). 146 getCacheLimit()); 147 } 148 } catch (Throwable t) { 149 logger.error("Error while trying to retrieve HTML status", t); 150 } 151 152 request.setAttribute ("freeMemoryInBytes", freeMemoryInBytes); 154 request.setAttribute ("totalMemoryInBytes", totalMemoryInBytes); 155 request.setAttribute ("outputCacheSize", outputCacheSize); 156 request.setAttribute ("outputCacheMaxSize", outputCacheMaxSize); 157 158 JahiaAdministration.doRedirect (request, response, session, JSP_PATH + "status.jsp"); 159 } 160 161 162 170 private void processSettings (HttpServletRequest request, 171 HttpServletResponse response, 172 HttpSession session) 173 throws IOException , ServletException { 174 if (request.getParameter ("flushHTML") != null) { 175 logger.debug ("Flushing Output Cache"); 176 try { 177 CacheFactory.getHtmlCache().flush(); 178 } catch (Throwable t) { 179 logger.error("Error while trying to flush HTML cache", t); 180 } 181 } 182 183 if (request.getParameter ("flushLocks") != null) { 184 logger.debug ("Flushing Locks"); 185 ServicesRegistry.getInstance ().getLockService().purgeLocks(); 186 } 187 188 if (request.getParameter ("flushAllCaches") != null) { 189 logger.debug ("Flushing all caches"); 190 CacheFactory.getInstance().flushAllCaches(); 191 } 192 193 CacheFactory cacheFactory = CacheFactory.getInstance (); 195 196 Iterator cacheNameIte = cacheFactory.getNames ().iterator(); 198 199 while (cacheNameIte.hasNext()) { 201 202 String curCacheName = (String )cacheNameIte.next (); 204 205 if (request.getParameter ("flush_" + curCacheName) != null) { 206 Cache cache = CacheFactory.getInstance().getCache (curCacheName); 207 if (cache != null) { 208 logger.debug ("Flushing cache : " + curCacheName); 209 cache.flush(); 210 } 211 } 212 } 213 214 displaySettings (request, response, session); 215 } 216 217 } 218 | Popular Tags |