View Javadoc
1   package org.apache.commons.jcs.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.jcs.JCS;
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
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.jcs.utils.servlet.JCSServletContextListener
39   *  &lt;/listener-class&gt;
40   *  &lt;/listener&gt;
41   * </pre>
42   * @author Aaron Smuts
43   */
44  public class JCSServletContextListener
45      implements ServletContextListener
46  {
47      /** The logger */
48      private static final Log log = LogFactory.getLog( JCSServletContextListener.class );
49  
50      /**
51       * This does nothing. We don't want to initialize the cache here.
52       * <p>
53       * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
54       */
55      @Override
56      public void contextInitialized( ServletContextEvent arg0 )
57      {
58          if ( log.isDebugEnabled() )
59          {
60              log.debug( "contextInitialized" );
61          }
62      }
63  
64      /**
65       * Shutdown JCS.
66       * <p>
67       * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
68       */
69      @Override
70      public void contextDestroyed( ServletContextEvent arg0 )
71      {
72          if ( log.isDebugEnabled() )
73          {
74              log.debug( "contextDestroyed, shutting down JCS." );
75          }
76  
77          JCS.shutdown();
78      }
79  }