1 package org.nemesis.forum.webapp.admin.action; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 import org.apache.struts.action.ActionError; 12 import org.apache.struts.action.ActionErrors; 13 import org.apache.struts.action.ActionForm; 14 import org.apache.struts.action.ActionForward; 15 import org.apache.struts.action.ActionMapping; 16 import org.nemesis.forum.ForumFactory; 17 import org.nemesis.forum.impl.DbCacheManager; 18 import org.nemesis.forum.impl.DbForumFactory; 19 import org.nemesis.forum.proxy.ForumFactoryProxy; 20 import org.nemesis.forum.util.cache.Cache; 21 import org.nemesis.forum.webapp.admin.bean.CacheBean; 22 23 24 25 public class CacheAction extends BaseAction { 26 27 static protected Log log =LogFactory.getLog(CacheAction.class); 28 static private int[] ctes = {DbCacheManager.MESSAGE_CACHE,DbCacheManager.THREAD_CACHE,DbCacheManager.FORUM_CACHE,DbCacheManager.USER_CACHE,DbCacheManager.GROUP_CACHE}; 29 30 31 public ActionForward execute(ActionMapping mapping, 32 ActionForm form, 33 HttpServletRequest request, 34 HttpServletResponse response) 35 throws Exception { 36 37 checkUser(request); 39 checkPermission(request,OperationConstants.MANAGE_CACHE); 41 42 ActionErrors errors = new ActionErrors(); 43 44 try { 45 ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request)); 46 DbForumFactory dbForumFactory = null; 47 dbForumFactory = (DbForumFactory)((ForumFactoryProxy)forumFactory).getUnderlyingForumFactory(); 48 DbCacheManager cacheManager = dbForumFactory.getCacheManager(); 49 50 if(request.getParameter("switchcache")!=null){ 52 cacheManager.setCacheEnabled(!cacheManager.isCacheEnabled()); 53 } 54 if(request.getParameter("clean")!=null){ 55 try { 56 cacheManager.clear(Integer.parseInt(request.getParameter("clean"))); 57 } catch (Exception e) { 58 } 59 } 60 if(request.getParameter("newSize")!=null){ 61 try { 62 Cache cache = cacheManager.getCache(Integer.parseInt(request.getParameter("oid"))); 63 cache.setMaxSize(Integer.parseInt(request.getParameter("newSize"))*1024); 64 } catch (Exception e) { 65 } 66 } 67 68 70 List mcos =new ArrayList (5); 71 for(int i =0;i<ctes.length;i++){ 72 mcos.add(new CacheBean(ctes[i], "cache.memory.ctes."+(i+1),cacheManager.getCache(ctes[i]))); 73 } 74 request.setAttribute("mcos",mcos); 75 request.setAttribute("isCacheEnabled",new Boolean (cacheManager.isCacheEnabled())); 76 77 } catch (Exception e) { 78 String eid=this.getClass().getName()+"_"+System.currentTimeMillis(); 79 log.error("eid:"+eid +"\nsessionID" +request.getSession().getId(),e) ; 80 errors.add("general", new ActionError("error.general","error id:"+eid)); 81 } 82 83 saveErrors(request, errors); 84 85 return mapping.findForward("view"); 86 } 87 88 } | Popular Tags |