01: /*
02: Copyright 2004 Philip Jacob <phil@whirlycott.com>
03: Seth Fitzsimmons <seth@note.amherst.edu>
04:
05: Licensed under the Apache License, Version 2.0 (the "License");
06: you may not use this file except in compliance with the License.
07: You may obtain a copy of the License at
08:
09: 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;
21: import javax.servlet.ServletContextListener;
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: * Shuts down cache whenever the context reloads.
32: * @author Seth Fitzsimmons
33: */
34: public class CacheManagerListener implements ServletContextListener {
35:
36: /**
37: * Logger.
38: */
39: private static final Log log = LogFactory
40: .getLog(CacheManagerListener.class);
41:
42: /**
43: * Executes on context initialization.
44: */
45: public void contextInitialized(
46: final ServletContextEvent servletContextEvent) {
47: }
48:
49: /**
50: * Executes on context shutdown.
51: */
52: public void contextDestroyed(
53: final ServletContextEvent servletContextEvent) {
54: try {
55: log
56: .debug(Messages
57: .getString("CacheManagerListener.shutting_down_whirlycache_due_to_servlet_destruction")); //$NON-NLS-1$
58: CacheManager.getInstance().shutdown();
59: } catch (final CacheException e) {
60: log.error(e.getMessage(), e);
61: }
62: }
63: }
|