Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 79106 invoked from network); 25 Apr 2007 19:56:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Apr 2007 19:56:53 -0000 Received: (qmail 46352 invoked by uid 500); 25 Apr 2007 19:56:54 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 46295 invoked by uid 500); 25 Apr 2007 19:56:54 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 46283 invoked by uid 500); 25 Apr 2007 19:56:54 -0000 Delivered-To: apmail-jakarta-tomcat-dev@jakarta.apache.org Received: (qmail 46270 invoked by uid 99); 25 Apr 2007 19:56:54 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Apr 2007 12:56:54 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Apr 2007 12:56:46 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id AFCD51A9838; Wed, 25 Apr 2007 12:56:26 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r532461 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager: HTMLManagerServlet.java LocalStrings.properties LocalStrings_de.properties ManagerServlet.java Date: Wed, 25 Apr 2007 19:56:26 -0000 To: tomcat-dev@jakarta.apache.org From: remm@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070425195626.AFCD51A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: remm Date: Wed Apr 25 12:56:25 2007 New Revision: 532461 URL: http://svn.apache.org/viewvc?view=rev&rev=532461 Log: - Session expiration and statistics tools. - Submitted by Rainer Jung. Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings_de.properties tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java?view=diff&rev=532461&r1=532460&r2=532461 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java Wed Apr 25 12:56:25 2007 @@ -113,8 +113,9 @@ message = reload(path); } else if (command.equals("/undeploy")) { message = undeploy(path); + } else if (command.equals("/expire")) { + message = expireSessions(path, request); } else if (command.equals("/sessions")) { - //message = sessions(path); try { doSessions(path, request, response); return; @@ -353,6 +354,7 @@ String appsStop = sm.getString("htmlManagerServlet.appsStop"); String appsReload = sm.getString("htmlManagerServlet.appsReload"); String appsUndeploy = sm.getString("htmlManagerServlet.appsUndeploy"); + String appsExpire = sm.getString("htmlManagerServlet.appsExpire"); Iterator iterator = sortedContextPathsMap.entrySet().iterator(); boolean isHighlighted = true; @@ -406,7 +408,7 @@ writer.print (MessageFormat.format(APPS_ROW_DETAILS_SECTION, args)); - args = new Object[9]; + args = new Object[14]; args[0] = response.encodeURL (request.getContextPath() + "/html/start?path=" + displayPath); @@ -424,7 +426,15 @@ "/html/undeploy?path=" + displayPath); args[7] = appsUndeploy; - args[8] = highlightColor; + args[8] = response.encodeURL + (request.getContextPath() + + "/html/expire?path=" + displayPath); + args[9] = appsExpire; + args[10] = sm.getString("htmlManagerServlet.expire.explain"); + args[11] = new Integer(context.getManager().getMaxInactiveInterval()/60); + args[12] = sm.getString("htmlManagerServlet.expire.unit"); + + args[13] = highlightColor; if (context.getPath().equals(this.context.getPath())) { writer.print(MessageFormat.format( @@ -533,22 +543,36 @@ /** * Display session information and invoke list. * - * @see ManagerServlet#sessions(PrintWriter, String) + * @see ManagerServlet#sessions(PrintWriter, String, int) * * @param path Context path of the application to list session information + * @param idle Expire all sessions with idle time ≥ idle for this context * @return message String */ - public String sessions(String path) { + public String sessions(String path, int idle) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.sessions(printWriter, path); + super.sessions(printWriter, path, idle); return stringWriter.toString(); } /** + * Display session information and invoke list. + * + * @see ManagerServlet#sessions(PrintWriter, String) + * + * @param path Context path of the application to list session information + * @return message String + */ + public String sessions(String path) { + + return sessions(path, -1); + } + + /** * Start the web application at the specified context path. * * @see ManagerServlet#start(PrintWriter, String) @@ -601,6 +625,26 @@ // ------------------------------------------------ Sessions administration /** + * + * Extract the expiration request parameter + * + * @param path + * @param req + */ + protected String expireSessions(String path, HttpServletRequest req) { + int idle = -1; + String idleParam = req.getParameter("idle"); + if (idleParam != null) { + try { + idle = Integer.parseInt(idleParam); + } catch (NumberFormatException e) { + log("Could not parse idle parameter to an int: " + idleParam); + } + } + return sessions(path, idle); + } + + /** * * @param req * @param resp @@ -903,18 +947,20 @@ " {2}\n" + " {3}\n" + " {4}\n" + - " {5}\n" + + " {5}\n" + "\n"; private static final String APPS_ROW_DETAILS_SECTION = "\n" + - " {0}\n" + - " {1}\n" + - " {2}\n" + - " {4}\n"; + " {0}" + + "\n" + + " {1}\n" + + " {2}\n" + + " " + + "{4}\n"; private static final String MANAGER_APP_ROW_BUTTON_SECTION = - " \n" + + " \n" + " \n" + "  {1} \n" + "  {3} \n" + @@ -922,10 +968,18 @@ "  {7} \n" + " \n" + " \n" + + "\n" + + " \n" + + "
\n" + + " \n" + + "   {10}  {12} \n" + + " \n" + + "
\n" + + " \n" + "\n"; private static final String STARTED_DEPLOYED_APPS_ROW_BUTTON_SECTION = - " \n" + + " \n" + " \n" + "  {1} \n" + "  {3} \n" + @@ -933,10 +987,18 @@ "  {7} \n" + " \n" + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + "   {10}  {12} \n" + + " \n" + + "
\n" + + " \n" + "\n"; private static final String STOPPED_DEPLOYED_APPS_ROW_BUTTON_SECTION = - " \n" + + " \n" + " \n" + "  {1} \n" + "  {3} \n" + @@ -947,7 +1009,7 @@ "\n"; private static final String STARTED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION = - " \n" + + " \n" + " \n" + "  {1} \n" + "  {3} \n" + @@ -958,7 +1020,7 @@ "\n"; private static final String STOPPED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION = - " \n" + + " \n" + " \n" + "  {1} \n" + "  {3} \n" + Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties?view=diff&rev=532461&r1=532460&r2=532461 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties Wed Apr 25 12:56:25 2007 @@ -3,11 +3,14 @@ htmlManagerServlet.appsPath=Path htmlManagerServlet.appsReload=Reload htmlManagerServlet.appsUndeploy=Undeploy +htmlManagerServlet.appsExpire=Expire sessions htmlManagerServlet.appsSessions=Sessions htmlManagerServlet.appsStart=Start htmlManagerServlet.appsStop=Stop htmlManagerServlet.appsTasks=Commands htmlManagerServlet.appsTitle=Applications +htmlManagerServlet.expire.explain=with idle ≥ +htmlManagerServlet.expire.unit=minutes htmlManagerServlet.helpHtmlManager=HTML Manager Help htmlManagerServlet.helpHtmlManagerFile=../docs/html-manager-howto.html htmlManagerServlet.helpManager=Manager Help Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings_de.properties URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings_de.properties?view=diff&rev=532461&r1=532460&r2=532461 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings_de.properties (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/LocalStrings_de.properties Wed Apr 25 12:56:25 2007 @@ -3,11 +3,14 @@ htmlManagerServlet.appsPath=Kontext Pfad htmlManagerServlet.appsReload=Neu laden htmlManagerServlet.appsUndeploy=Entfernen +htmlManagerServlet.appsExpire=Lösche Sitzungen htmlManagerServlet.appsSessions=Sitzungen htmlManagerServlet.appsStart=Start htmlManagerServlet.appsStop=Stop htmlManagerServlet.appsTasks=Kommandos htmlManagerServlet.appsTitle=Anwendungen +htmlManagerServlet.expire.explain=mit Inaktivität ≥ +htmlManagerServlet.expire.unit=Minuten htmlManagerServlet.helpHtmlManager=Hilfeseite HTML Manager (englisch) htmlManagerServlet.helpHtmlManagerFile=html-manager-howto.html htmlManagerServlet.helpManager=Hilfeseite Manager (englisch) Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java?view=diff&rev=532461&r1=532460&r2=532461 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java Wed Apr 25 12:56:25 2007 @@ -100,9 +100,12 @@ * descriptions from the user database connected to the users * resource reference. *
  • /serverinfo - Display system OS and JVM properties. - *
  • /sessions?path=/xxx - List session information about the web - * application attached to context path /xxx for this + *
  • /expire?path=/xxx - List session idle timeinformation about the + * web application attached to context path /xxx for this * virtual host.
  • + *
  • /expire?path=/xxx&idle=mm - Expire sessions + * for the context path /xxx which were idle for at + * least mm minutes.
  • *
  • /start?path=/xxx - Start the web application attached to * context path /xxx for this virtual host.
  • *
  • /stop?path=/xxx - Stop the web application attached to @@ -364,8 +367,8 @@ save(writer, path); } else if (command.equals("/serverinfo")) { serverinfo(writer); - } else if (command.equals("/sessions")) { - sessions(writer, path); + } else if (command.equals("/expire")) { + expireSessions(writer, path, request); } else if (command.equals("/start")) { start(writer, path); } else if (command.equals("/stop")) { @@ -1082,16 +1085,20 @@ /** * Session information for the web application at the specified context path. - * Displays a profile of session MaxInactiveInterval timeouts listing number - * of sessions for each 10 minute timeout interval up to 10 hours. + * Displays a profile of session lastAccessedTime listing number + * of sessions for each 10 minute interval up to 10 hours. * * @param writer Writer to render to * @param path Context path of the application to list session information for + * @param idle Expire all sessions with idle time ≥ idle for this context */ - protected void sessions(PrintWriter writer, String path) { + protected void sessions(PrintWriter writer, String path, int idle) { - if (debug >= 1) + if (debug >= 1) { log("sessions: Session information for web application at '" + path + "'"); + if (idle >= 0) + log("sessions: Session expiration for " + idle + " minutes '" + path + "'"); + } if ((path == null) || (!path.startsWith("/") && path.equals(""))) { writer.println(sm.getString("managerServlet.invalidPath", @@ -1108,37 +1115,56 @@ RequestUtil.filter(displayPath))); return; } + int maxCount = 60; + int maxInactiveInterval = context.getManager().getMaxInactiveInterval()/60; + int histoInterval = maxInactiveInterval / maxCount; + if ( histoInterval * maxCount < maxInactiveInterval ) + histoInterval++; + maxCount = maxInactiveInterval / histoInterval; + if ( histoInterval * maxCount < maxInactiveInterval ) + maxCount++; + writer.println(sm.getString("managerServlet.sessions", displayPath)); writer.println(sm.getString("managerServlet.sessiondefaultmax", - "" + context.getManager().getMaxInactiveInterval()/60)); + "" + maxInactiveInterval)); Session [] sessions = context.getManager().findSessions(); - int [] timeout = new int[60]; + int [] timeout = new int[maxCount]; int notimeout = 0; + int expired = 0; + long now = System.currentTimeMillis(); for (int i = 0; i < sessions.length; i++) { - int time = sessions[i].getMaxInactiveInterval()/(10*60); + int time = (int)((now-sessions[i].getLastAccessedTime())/1000); + if (idle >= 0 && time >= idle*60) { + sessions[i].expire(); + idle++; + } + time=time/60/histoInterval; if (time < 0) notimeout++; - else if (time >= timeout.length) - timeout[timeout.length-1]++; + else if (time >= maxCount) + timeout[maxCount-1]++; else timeout[time]++; } if (timeout[0] > 0) writer.println(sm.getString("managerServlet.sessiontimeout", - "<10", "" + timeout[0])); - for (int i = 1; i < timeout.length-1; i++) { + "<" + histoInterval, "" + timeout[0])); + for (int i = 1; i < maxCount-1; i++) { if (timeout[i] > 0) writer.println(sm.getString("managerServlet.sessiontimeout", - "" + (i)*10 + " - <" + (i+1)*10, + "" + (i)*histoInterval + " - <" + (i+1)*histoInterval, "" + timeout[i])); } - if (timeout[timeout.length-1] > 0) + if (timeout[maxCount-1] > 0) writer.println(sm.getString("managerServlet.sessiontimeout", - ">=" + timeout.length*10, - "" + timeout[timeout.length-1])); + ">=" + maxCount*histoInterval, + "" + timeout[maxCount-1])); if (notimeout > 0) writer.println(sm.getString("managerServlet.sessiontimeout", "unlimited","" + notimeout)); + if (idle >= 0) + writer.println(sm.getString("managerServlet.sessiontimeout", + "" + idle,"expired " + expired)); } catch (Throwable t) { log("ManagerServlet.sessions[" + displayPath + "]", t); writer.println(sm.getString("managerServlet.exception", @@ -1147,6 +1173,39 @@ } + + /** + * Session information for the web application at the specified context path. + * Displays a profile of session lastAccessedTime listing number + * of sessions for each 10 minute interval up to 10 hours. + * + * @param writer Writer to render to + * @param path Context path of the application to list session information for + */ + protected void sessions(PrintWriter writer, String path) { + sessions(writer, path, -1); + } + + + /** + * + * Extract the expiration request parameter + * + * @param path + * @param req + */ + protected void expireSessions(PrintWriter writer, String path, HttpServletRequest req) { + int idle = -1; + String idleParam = req.getParameter("idle"); + if (idleParam != null) { + try { + idle = Integer.parseInt(idleParam); + } catch (NumberFormatException e) { + log("Could not parse idle parameter to an int: " + idleParam); + } + } + sessions(writer, path, idle); + } /** * Start the web application at the specified context path. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org