View Javadoc

1   /*
2    * SessionListener.java
3    *
4    * Created on 23 Август 2005 г., 16:13
5    *
6    * To change this template, choose Tools | Options and locate the template under
7    * the Source Creation and Management node. Right-click the template and choose
8    * Open. You can then make changes to the template in the Source Editor.
9    */
10  
11  package org.weda.servlet;
12  
13  import java.util.Enumeration;
14  import javax.servlet.http.HttpSessionEvent;
15  import javax.servlet.http.HttpSessionListener;
16  import org.apache.commons.logging.Log;
17  import org.apache.commons.logging.LogFactory;
18  import org.weda.cache.CacheService;
19  
20  /**Цель: освобождение ресурсов занимаемых сервисом {@link tim.docarch.service.CacheService}
21   *
22   * @author tim
23   */
24  public class SessionListener implements HttpSessionListener{
25      private final static Log log = LogFactory.getLog(SessionListener.class);
26      
27      public void sessionDestroyed(HttpSessionEvent event) {
28          //printSessionAttributes(event.getSession());
29          Enumeration it = event.getSession().getAttributeNames();
30          while (it.hasMoreElements()){
31              String attr = (String)it.nextElement();
32              Object obj = event.getSession().getAttribute(attr);
33              if (obj instanceof CacheService) {
34                  log.debug("Reliasing cache.");
35                  ((CacheService)obj).releaseAll();
36              }
37          }
38      }        
39  
40      public void sessionCreated(HttpSessionEvent event) {
41      }
42          
43  }