01: /**
02: * Copyright 2003-2007 Luck Consulting Pty Ltd
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */package net.sf.ehcache.exceptionhandler;
16:
17: import net.sf.ehcache.Ehcache;
18:
19: /**
20: * A handler which may be registered with an Ehcache, to handle exception on Cache operations.
21: * <p/>
22: * Handlers may be registered at configuration time in ehcache.xml, using a CacheExceptionHandlerFactory, or
23: * set at runtime (a strategy).
24: * <p/>
25: * If an exception handler is registered, the default behaviour of throwing the exception will not occur. The handler
26: * method <code>onException</code> will be called. Of course, if the handler decides to throw the exception, it will
27: * propagate up through the call stack. If the handler does not, it won't.
28: * <p/>
29: * Some common Exceptions thrown, and which therefore should be considered when implementing this class are listed below:
30: * <ul>
31: * <li>{@link IllegalStateException} if the cache is not {@link net.sf.ehcache.Status#STATUS_ALIVE}
32: * <li>{@link IllegalArgumentException} if an attempt is made to put a null element into a cache
33: * <li>{@link net.sf.ehcache.distribution.RemoteCacheException} if an issue occurs in remote synchronous replication
34: * <li>
35: * <li>
36: * </ul>
37: *
38: * @author <a href="mailto:gluck@gregluck.com">Greg Luck</a>
39: * @version $Id: CacheExceptionHandler.java 525 2007-07-31 22:41:54Z gregluck $
40: */
41: public interface CacheExceptionHandler {
42:
43: /**
44: * Called if an Exception occurs in a Cache method. This method is not called
45: * if an <code>Error</code> occurs.
46: *
47: * @param ehcache the cache in which the Exception occurred
48: * @param key the key used in the operation, or null if the operation does not use a key or the key was null
49: * @param exception the exception caught
50: */
51: void onException(Ehcache ehcache, Object key, Exception exception);
52: }
|