001package org.apache.commons.jcs3.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.jcs3.JCS;
026import org.apache.commons.jcs3.log.Log;
027import org.apache.commons.jcs3.log.LogManager;
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 *  &lt;listener&gt;
037 *  &lt;listener-class&gt;
038 *  org.apache.commons.jcs3.utils.servlet.JCSServletContextListener
039 *  &lt;/listener-class&gt;
040 *  &lt;/listener&gt;
041 * </pre>
042 */
043public class JCSServletContextListener
044    implements ServletContextListener
045{
046    /** The logger */
047    private static final Log log = LogManager.getLog( JCSServletContextListener.class );
048
049    /**
050     * This does nothing. We don't want to initialize the cache here.
051     * <p>
052     * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
053     */
054    @Override
055    public void contextInitialized( final ServletContextEvent arg0 )
056    {
057        log.debug( "contextInitialized" );
058    }
059
060    /**
061     * Shutdown JCS.
062     * <p>
063     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
064     */
065    @Override
066    public void contextDestroyed( final ServletContextEvent arg0 )
067    {
068        log.debug( "contextDestroyed, shutting down JCS." );
069
070        JCS.shutdown();
071    }
072}