01: /*
02: * Created on Jan 28, 2004
03: *
04: * To change the template for this generated file go to
05: * Window - Preferences - Java - Code Generation - Code and Comments
06: */
07: package org.vfny.geoserver.action;
08:
09: import com.sun.media.jai.util.SunTileCache;
10: import org.apache.struts.Globals;
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.vfny.geoserver.global.GeoServer;
17: import org.vfny.geoserver.global.UserContainer;
18: import javax.media.jai.JAI;
19: import javax.servlet.ServletContext;
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: /**
24: * Free JAI Memory by running the Tile Cahce flushing.
25: * <p>
26: * This represents an action that interacts with the running GeoServer
27: * application (it is not really a config action, it is just that I want the
28: * user to be logged in).
29: * </p>
30: * @author $Author: Alessio Fabiani $ (last modification)
31: */
32: public class FreeJAIMemoryAction extends ConfigAction {
33: /* (non-Javadoc)
34: * @see org.vfny.geoserver.action.ConfigAction#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, org.vfny.geoserver.global.UserContainer, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
35: */
36: public ActionForward execute(ActionMapping mapping,
37: ActionForm form, UserContainer user,
38: HttpServletRequest request, HttpServletResponse response)
39: throws Exception {
40: ServletContext sc = request.getSession().getServletContext();
41:
42: final JAI jaiDef = ((GeoServer) sc
43: .getAttribute(GeoServer.WEB_CONTAINER_KEY))
44: .getJAIDefault();
45: final SunTileCache jaiCache = ((GeoServer) sc
46: .getAttribute(GeoServer.WEB_CONTAINER_KEY))
47: .getJaiCache();
48: final long capacityBefore = jaiCache.getMemoryCapacity();
49: final long usageBefore = jaiCache.getCacheMemoryUsed();
50:
51: jaiCache.flush();
52: jaiCache.setMemoryCapacity(0); //to be sure we realease all tiles
53: System.gc();
54: System.gc();
55: System.gc();
56: System.gc();
57: System.gc();
58: System.gc();
59: jaiCache.setMemoryCapacity(capacityBefore);
60:
61: final long usageAfter = jaiCache.getCacheMemoryUsed();
62:
63: // Provide status message
64: //
65: final ActionErrors errors = new ActionErrors();
66: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
67: "message.JAI.memory", new Long(
68: (usageBefore - usageAfter) / 1024)));
69: request.setAttribute(Globals.ERROR_KEY, errors);
70:
71: // return back to the admin screen
72: //
73: return mapping.findForward("admin");
74: }
75: }
|