You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/12/31 18:32:48 UTC

svn commit: r730420 - /incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/SessionMonitor.java

Author: ajaquith
Date: Wed Dec 31 09:32:48 2008
New Revision: 730420

URL: http://svn.apache.org/viewvc?rev=730420&view=rev
Log:
SessionMonitor now calls WikiEngine.shutdown() when the webapp context is unloaded. It didn't before, which meant containers would accumulate threads and eventually exhaust memory.

Modified:
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/SessionMonitor.java

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/SessionMonitor.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/SessionMonitor.java?rev=730420&r1=730419&r2=730420&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/SessionMonitor.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/SessionMonitor.java Wed Dec 31 09:32:48 2008
@@ -23,6 +23,8 @@
 import java.security.Principal;
 import java.util.*;
 
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
@@ -45,7 +47,7 @@
  *  web.xml for the wiki web application.
  *  </p>
  */
-public class SessionMonitor implements HttpSessionListener
+public class SessionMonitor implements HttpSessionListener, ServletContextListener
 {
     private static Logger log = LoggerFactory.getLogger( SessionMonitor.class );
 
@@ -283,4 +285,28 @@
             }
         }
     }
+
+    /**
+     * No-op.
+     * @param sce the servlet context event
+     */
+    public void contextInitialized( ServletContextEvent sce )
+    {
+    }
+
+    /**
+     * When the servlet context is destroyed, this method
+     * obtains the associated WikiEngine and executes its
+     * {@link com.ecyrd.jspwiki.WikiEngine#shutdown()}
+     * method.
+     * @param sce the servlet context event
+     */
+    public void contextDestroyed( ServletContextEvent sce )
+    {
+        WikiEngine engine = WikiEngine.getInstance( sce.getServletContext(), null );
+        if ( engine != null )
+        {
+            engine.shutdown();
+        }
+    }
 }