KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > whirlycott > cache > servlet > CacheManagerListener


1 /*
2 Copyright 2004 Philip Jacob <phil@whirlycott.com>
3                     Seth Fitzsimmons <seth@note.amherst.edu>
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 */

17
18 package com.whirlycott.cache.servlet;
19
20 import javax.servlet.ServletContextEvent JavaDoc;
21 import javax.servlet.ServletContextListener JavaDoc;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 import com.whirlycott.cache.CacheException;
27 import com.whirlycott.cache.CacheManager;
28 import com.whirlycott.cache.Messages;
29
30
31
32 /**
33  * Shuts down cache whenever the context reloads.
34  * @author Seth Fitzsimmons
35  */

36 public class CacheManagerListener implements ServletContextListener JavaDoc {
37     
38     /**
39      * Logger.
40      */

41     private static final Log log = LogFactory.getLog(CacheManagerListener.class);
42     
43     /**
44      * Executes on context initialization.
45      */

46     public void contextInitialized(final ServletContextEvent JavaDoc servletContextEvent) {
47     }
48     
49     /**
50      * Executes on context shutdown.
51      */

52     public void contextDestroyed(final ServletContextEvent JavaDoc servletContextEvent) {
53         try {
54             log.debug(Messages.getString("CacheManagerListener.shutting_down_whirlycache_due_to_servlet_destruction")); //$NON-NLS-1$
55
CacheManager.getInstance().shutdown();
56         } catch (final CacheException e) {
57             log.error(e.getMessage(), e);
58         }
59     }
60 }
61
Popular Tags