KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > oscache > web > CacheContextListener


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.oscache.web;
6
7 import javax.servlet.ServletContext JavaDoc;
8 import javax.servlet.ServletContextEvent JavaDoc;
9 import javax.servlet.ServletContextListener JavaDoc;
10
11 /**
12  * Class for a clean startup and shutdown of the ServletCacheAdministrator and its application scoped cache.
13  * @author <a HREF="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
14  */

15 public class CacheContextListener implements ServletContextListener JavaDoc {
16
17     /**
18      * This notification occurs when the webapp is ready to process requests.<p>
19      * We use this hook to cleanly start up the {@link ServletCacheAdministrator}
20      * and create the application scope cache (which will consequentially
21      * initialize any listeners configured for it that implement <code>LifecycleAware</code>.)<p>
22      *
23      * As of Servlet 2.4, this is guaranteed to be called before any Servlet.init()
24      * methods.
25      */

26     public void contextInitialized(ServletContextEvent JavaDoc servletContextEvent) {
27         ServletContext JavaDoc context = servletContextEvent.getServletContext();
28         ServletCacheAdministrator.getInstance(context);
29     }
30
31     /**
32      * This notification occurs when the servlet context is about to be shut down.
33      * We use this hook to cleanly shut down the cache.
34      */

35     public void contextDestroyed(ServletContextEvent JavaDoc servletContextEvent) {
36         ServletContext JavaDoc context = servletContextEvent.getServletContext();
37         ServletCacheAdministrator.destroyInstance(context);
38     }
39
40 }
Popular Tags