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 org.apache.struts.Globals;
10: import org.apache.struts.action.ActionError;
11: import org.apache.struts.action.ActionErrors;
12: import org.apache.struts.action.ActionForm;
13: import org.apache.struts.action.ActionForward;
14: import org.apache.struts.action.ActionMapping;
15: import org.vfny.geoserver.global.UserContainer;
16: import javax.servlet.http.HttpServletRequest;
17: import javax.servlet.http.HttpServletResponse;
18:
19: /**
20: * Free Memory by running the garbage collector.
21: * <p>
22: * This represents an action that interacts with the running GeoServer
23: * application (it is not really a config action, it is just that I want the
24: * user to be logged in).
25: * </p>
26: * @author Jody Garnett, Refractions Research, Inc.
27: * @author $Author: jive $ (last modification)
28: * @version $Id: FreeMemoryAction.java 6177 2007-02-19 10:11:27Z aaime $
29: */
30: public class FreeMemoryAction extends ConfigAction {
31: /* (non-Javadoc)
32: * @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)
33: */
34: public ActionForward execute(ActionMapping mapping,
35: ActionForm form, UserContainer user,
36: HttpServletRequest request, HttpServletResponse response)
37: throws Exception {
38: Runtime rt = Runtime.getRuntime();
39:
40: long before = rt.freeMemory();
41:
42: System.gc();
43: System.runFinalization();
44:
45: long after = rt.freeMemory();
46: long difference = (before - after) / 1024;
47:
48: // Provide status message
49: //
50: ActionErrors errors = new ActionErrors();
51: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
52: "message.memory", new Long(difference)));
53: request.setAttribute(Globals.ERROR_KEY, errors);
54:
55: // return back to the admin screen
56: //
57: return mapping.findForward("admin");
58: }
59: }
|