1 package org.apache.jcs.utils.servlet;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.servlet.ServletContextEvent;
23 import javax.servlet.ServletContextListener;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.jcs.engine.control.CompositeCacheManager;
28
29 /***
30 * If you add this to the context listeners section of your web.xml file, this will shutdown JCS
31 * gracefully.
32 * <p>
33 * Add the following to the top of your web.xml file.
34 *
35 * <pre>
36 * <listener>
37 * <listener-class>
38 * org.apache.jcs.utils.servlet.JCSServletContextListener
39 * </listener-class>
40 * </listener>
41 * </pre>
42 *
43 * @author Aaron Smuts
44 */
45 public class JCSServletContextListener
46 implements ServletContextListener
47 {
48 private static final Log log = LogFactory.getLog( JCSServletContextListener.class );
49
50 /***
51 * This does nothing. We don't want to initialize the cache here.
52 * <p>
53 * (non-Javadoc)
54 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
55 */
56 public void contextInitialized( ServletContextEvent arg0 )
57 {
58 if ( log.isInfoEnabled() )
59 {
60 log.info( "contextInitialized" );
61 }
62 }
63
64 /***
65 * This gets the singleton instance of the CompositeCacheManager and calls shutdown.
66 * <p>
67 * (non-Javadoc)
68 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
69 */
70 public void contextDestroyed( ServletContextEvent arg0 )
71 {
72 if ( log.isInfoEnabled() )
73 {
74 log.info( "contextDestroyed, shutting down JCS." );
75 }
76 CompositeCacheManager.getInstance().shutDown();
77 }
78
79 }