View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16      
17  package net.sf.ehcache.exceptionhandler;
18  
19  import net.sf.ehcache.Ehcache;
20  
21  /***
22   * A handler which may be registered with an Ehcache, to handle exceptions on Cache operations.
23   * <p/>
24   * Handlers may be registered at configuration time in ehcache.xml, using a CacheExceptionHandlerFactory, or
25   *  set at runtime (a strategy).
26   * <p/>
27   * If an exception handler is registered, the default behaviour of throwing the exception will not occur. The handler
28   * method <code>onException</code> will be called. Of course, if the handler decides to throw the exception, it will
29   * propagate up through the call stack. If the handler does not, it won't.
30   * <p/>
31   * Some common Exceptions thrown, and which therefore should be considered when implementing this class are listed below:
32   * <ul>
33   * <li>{@link IllegalStateException} if the cache is not {@link net.sf.ehcache.Status#STATUS_ALIVE}
34   * <li>{@link IllegalArgumentException} if an attempt is made to put a null element into a cache
35   * <li>{@link net.sf.ehcache.distribution.RemoteCacheException} if an issue occurs in remote synchronous replication
36   * <li>
37   * <li>
38   * </ul>
39   *
40   * @author <a href="mailto:gluck@gregluck.com">Greg Luck</a>
41   * @version $Id: CacheExceptionHandler.html 13146 2011-08-01 17:12:39Z oletizi $
42   */
43  public interface CacheExceptionHandler {
44  
45      /***
46       * Called if an Exception occurs in a Cache method. This method is not called
47       * if an <code>Error</code> occurs.
48       *
49       * @param ehcache   the cache in which the Exception occurred
50       * @param key       the key used in the operation, or null if the operation does not use a key or the key was null
51       * @param exception the Exception caught. 
52       */
53      void onException(Ehcache ehcache, Object key, Exception exception);
54  }
55