View Javadoc
1   package org.apache.commons.jcs3.utils.servlet;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import javax.servlet.ServletContextEvent;
23  import javax.servlet.ServletContextListener;
24  
25  import org.apache.commons.jcs3.JCS;
26  import org.apache.commons.jcs3.log.Log;
27  import org.apache.commons.jcs3.log.LogManager;
28  
29  /**
30   * If you add this to the context listeners section of your web.xml file, this will shutdown JCS
31   * gracefully.
32   * <p>
33   * Add the following to the top of your web.xml file.
34   *
35   * <pre>
36   *  &lt;listener&gt;
37   *  &lt;listener-class&gt;
38   *  org.apache.commons.jcs3.utils.servlet.JCSServletContextListener
39   *  &lt;/listener-class&gt;
40   *  &lt;/listener&gt;
41   * </pre>
42   */
43  public class JCSServletContextListener
44      implements ServletContextListener
45  {
46      /** The logger */
47      private static final Log log = LogManager.getLog( JCSServletContextListener.class );
48  
49      /**
50       * This does nothing. We don't want to initialize the cache here.
51       * <p>
52       * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
53       */
54      @Override
55      public void contextInitialized( final ServletContextEvent arg0 )
56      {
57          log.debug( "contextInitialized" );
58      }
59  
60      /**
61       * Shutdown JCS.
62       * <p>
63       * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
64       */
65      @Override
66      public void contextDestroyed( final ServletContextEvent arg0 )
67      {
68          log.debug( "contextDestroyed, shutting down JCS." );
69  
70          JCS.shutdown();
71      }
72  }