001package org.apache.commons.jcs.utils.servlet; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import javax.servlet.ServletContextEvent; 023import javax.servlet.ServletContextListener; 024 025import org.apache.commons.jcs.JCS; 026import org.apache.commons.logging.Log; 027import org.apache.commons.logging.LogFactory; 028 029/** 030 * If you add this to the context listeners section of your web.xml file, this will shutdown JCS 031 * gracefully. 032 * <p> 033 * Add the following to the top of your web.xml file. 034 * 035 * <pre> 036 * <listener> 037 * <listener-class> 038 * org.apache.commons.jcs.utils.servlet.JCSServletContextListener 039 * </listener-class> 040 * </listener> 041 * </pre> 042 * @author Aaron Smuts 043 */ 044public class JCSServletContextListener 045 implements ServletContextListener 046{ 047 /** The logger */ 048 private static final Log log = LogFactory.getLog( JCSServletContextListener.class ); 049 050 /** 051 * This does nothing. We don't want to initialize the cache here. 052 * <p> 053 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) 054 */ 055 @Override 056 public void contextInitialized( ServletContextEvent arg0 ) 057 { 058 if ( log.isDebugEnabled() ) 059 { 060 log.debug( "contextInitialized" ); 061 } 062 } 063 064 /** 065 * Shutdown JCS. 066 * <p> 067 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) 068 */ 069 @Override 070 public void contextDestroyed( ServletContextEvent arg0 ) 071 { 072 if ( log.isDebugEnabled() ) 073 { 074 log.debug( "contextDestroyed, shutting down JCS." ); 075 } 076 077 JCS.shutdown(); 078 } 079}