tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
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 GMT
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 @@
         " <td class=\"header-left\"><small>{2}</small></td>\n" +
         " <td class=\"header-center\"><small>{3}</small></td>\n"
+
         " <td class=\"header-center\"><small>{4}</small></td>\n"
+
-        " <td class=\"header-center\"><small>{5}</small></td>\n"
+
+        " <td class=\"header-left\"><small>{5}</small></td>\n" +
         "</tr>\n";
 
     private static final String APPS_ROW_DETAILS_SECTION =
         "<tr>\n" +
-        " <td class=\"row-left\" bgcolor=\"{5}\"><small><a href=\"{0}\">{0}</a></small></td>\n"
+
-        " <td class=\"row-left\" bgcolor=\"{5}\"><small>{1}</small></td>\n"
+
-        " <td class=\"row-center\" bgcolor=\"{5}\"><small>{2}</small></td>\n"
+
-        " <td class=\"row-center\" bgcolor=\"{5}\"><small><a href=\"{3}\"
target=\"_new\">{4}</a></small></td>\n";
+        " <td class=\"row-left\" bgcolor=\"{5}\" rowspan=\"2\"><small><a href=\"{0}\">{0}</a>"
+
+        "</small></td>\n" +
+        " <td class=\"row-left\" bgcolor=\"{5}\" rowspan=\"2\"><small>{1}</small></td>\n"
+
+        " <td class=\"row-center\" bgcolor=\"{5}\" rowspan=\"2\"><small>{2}</small></td>\n"
+
+        " <td class=\"row-center\" bgcolor=\"{5}\" rowspan=\"2\">" +
+        "<small><a href=\"{3}\" target=\"_new\">{4}</a></small></td>\n";
 
     private static final String MANAGER_APP_ROW_BUTTON_SECTION =
-        " <td class=\"row-left\" bgcolor=\"{8}\">\n" +
+        " <td class=\"row-left\" bgcolor=\"{13}\">\n" +
         "  <small>\n" +
         "  &nbsp;{1}&nbsp;\n" +
         "  &nbsp;{3}&nbsp;\n" +
@@ -922,10 +968,18 @@
         "  &nbsp;{7}&nbsp;\n" +
         "  </small>\n" +
         " </td>\n" +
+        "</tr><tr>\n" +
+        " <td class=\"row-left\" bgcolor=\"{13}\">\n" +
+        "  <form method=\"POST\" action=\"{8}\">\n" +
+        "  <small>\n" +
+        "  &nbsp;<input type=\"submit\" value=\"{9}\">&nbsp;{10}&nbsp;<input
type=\"text\" name=\"expire\" size=\"5\" value=\"{11}\">&nbsp;{12}&nbsp;\n" +
+        "  </small>\n" +
+        "  </form>\n" +
+        " </td>\n" +
         "</tr>\n";
 
     private static final String STARTED_DEPLOYED_APPS_ROW_BUTTON_SECTION =
-        " <td class=\"row-left\" bgcolor=\"{8}\">\n" +
+        " <td class=\"row-left\" bgcolor=\"{13}\">\n" +
         "  <small>\n" +
         "  &nbsp;{1}&nbsp;\n" +
         "  &nbsp;<a href=\"{2}\" onclick=\"return(confirm('''Are you sure?'''))\">{3}</a>&nbsp;\n"
+
@@ -933,10 +987,18 @@
         "  &nbsp;<a href=\"{6}\" onclick=\"return(confirm('''Are you sure?'''))\">{7}</a>&nbsp;\n"
+
         "  </small>\n" +
         " </td>\n" +
+        " </tr><tr>\n" +
+        " <td class=\"row-left\" bgcolor=\"{13}\">\n" +
+        "  <form method=\"POST\" action=\"{8}\">\n" +
+        "  <small>\n" +
+        "  &nbsp;<input type=\"submit\" value=\"{9}\">&nbsp;{10}&nbsp;<input
type=\"text\" name=\"expire\" size=\"5\" value=\"{11}\">&nbsp;{12}&nbsp;\n" +
+        "  </small>\n" +
+        "  </form>\n" +
+        " </td>\n" +
         "</tr>\n";
 
     private static final String STOPPED_DEPLOYED_APPS_ROW_BUTTON_SECTION =
-        " <td class=\"row-left\" bgcolor=\"{8}\">\n" +
+        " <td class=\"row-left\" bgcolor=\"{13}\" rowspan=\"2\">\n" +
         "  <small>\n" +
         "  &nbsp;<a href=\"{0}\" onclick=\"return(confirm('''Are you sure?'''))\">{1}</a>&nbsp;\n"
+
         "  &nbsp;{3}&nbsp;\n" +
@@ -947,7 +1009,7 @@
         "</tr>\n";
 
     private static final String STARTED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION =
-        " <td class=\"row-left\" bgcolor=\"{8}\">\n" +
+        " <td class=\"row-left\" bgcolor=\"{13}\" rowspan=\"2\">\n" +
         "  <small>\n" +
         "  &nbsp;{1}&nbsp;\n" +
         "  &nbsp;<a href=\"{2}\" onclick=\"return(confirm('''Are you sure?'''))\">{3}</a>&nbsp;\n"
+
@@ -958,7 +1020,7 @@
         "</tr>\n";
 
     private static final String STOPPED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION =
-        " <td class=\"row-left\" bgcolor=\"{8}\">\n" +
+        " <td class=\"row-left\" bgcolor=\"{13}\" rowspan=\"2\">\n" +
         "  <small>\n" +
         "  &nbsp;<a href=\"{0}\" onclick=\"return(confirm('''Are you sure?'''))\">{1}</a>&nbsp;\n"
+
         "  &nbsp;{3}&nbsp;\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 &ge;
+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 &ge;
+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 <code>users</code>
  *     resource reference.
  * <li><b>/serverinfo</b> - Display system OS and JVM properties.
- * <li><b>/sessions?path=/xxx</b> - List session information about the
web
- *     application attached to context path <code>/xxx</code> for this
+ * <li><b>/expire?path=/xxx</b> - List session idle timeinformation about
the
+ *     web application attached to context path <code>/xxx</code> for this
  *     virtual host.</li>
+ * <li><b>/expire?path=/xxx&idle=mm</b> - Expire sessions
+ *     for the context path <code>/xxx</code> which were idle for at
+ *     least mm minutes.</li>
  * <li><b>/start?path=/xxx</b> - Start the web application attached to
  *     context path <code>/xxx</code> for this virtual host.</li>
  * <li><b>/stop?path=/xxx</b> - 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 &ge; 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


Mime
View raw message