01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.oscache.web;
06:
07: import javax.servlet.ServletContext;
08: import javax.servlet.ServletContextEvent;
09: import javax.servlet.ServletContextListener;
10:
11: /**
12: * Class for a clean startup and shutdown of the ServletCacheAdministrator and its application scoped cache.
13: * @author <a href="mailto:chris@swebtec.com">Chris Miller</a>
14: */
15: public class CacheContextListener implements ServletContextListener {
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(
27: ServletContextEvent servletContextEvent) {
28: ServletContext context = servletContextEvent
29: .getServletContext();
30: ServletCacheAdministrator.getInstance(context);
31: }
32:
33: /**
34: * This notification occurs when the servlet context is about to be shut down.
35: * We use this hook to cleanly shut down the cache.
36: */
37: public void contextDestroyed(ServletContextEvent servletContextEvent) {
38: ServletContext context = servletContextEvent
39: .getServletContext();
40: ServletCacheAdministrator.destroyInstance(context);
41: }
42:
43: }
|