KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > infra > CustomClickstreamListener


1 package org.javabb.infra;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import javax.servlet.ServletContextEvent JavaDoc;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 import com.opensymphony.clickstream.Clickstream;
12 import com.opensymphony.clickstream.ClickstreamListener;
13
14 /**
15  * The listener that keeps track of all clickstreams in the container as well as the creating new
16  * Clickstream objects and initiating logging when the clickstream dies (session has been
17  * invalidated).
18  * @author <a HREF="plightbo@hotmail.com">Patrick Lightbody </a>
19  * @author <a HREF="yoavs@apache.org">Yoav Shapira </a>
20  */

21 public class CustomClickstreamListener extends ClickstreamListener {
22     private final Log log = LogFactory.getLog(getClass());
23
24     /**
25      * Notification that the ServletContext has been destroyed.
26      * @param evt The context event
27      */

28     public void contextDestroyed(ServletContextEvent JavaDoc evt) {
29         Map JavaDoc clickstreams = (Map JavaDoc) evt.getServletContext().getAttribute(CLICKSTREAMS_ATTRIBUTE_KEY);
30
31         if(clickstreams == null) {
32
33             return;
34
35         }
36
37         // invalidates all sessions, to force them to be recreated on context re-initialization.
38
Iterator JavaDoc it = clickstreams.keySet().iterator();
39         while (it.hasNext()) {
40             String JavaDoc key = (String JavaDoc) it.next();
41             Clickstream stream = (Clickstream) clickstreams.get(key);
42
43             if (log.isDebugEnabled()) {
44                 log.debug("Invalidating session: " + key);
45             }
46
47             stream.getSession().invalidate();
48             clickstreams.remove(key);
49         }
50
51         super.contextDestroyed(evt);
52     }
53 }
Popular Tags