public class RecoverAnnotationRecoveryHandler<T> extends java.lang.Object implements MethodInvocationRecoverer<T>
@Recover annotation. A
suitable recovery method is one with a Throwable type as the first parameter and the
same return type and arguments as the method that failed. The Throwable first argument
is optional and if omitted the method is treated as a default (called when there are no
other matches). Generally the best matching method is chosen based on the type of the
first parameter and the type of the exception being handled. The closest match in the
class hierarchy is chosen, so for instance if an IllegalArgumentException is being
handled and there is a method whose first argument is RuntimeException, then it will be
preferred over a method whose first argument is Throwable.| Modifier and Type | Class and Description |
|---|---|
private static class |
RecoverAnnotationRecoveryHandler.SimpleMetadata |
| Modifier and Type | Field and Description |
|---|---|
private SubclassClassifier<java.lang.Throwable,java.lang.reflect.Method> |
classifier |
private java.util.Map<java.lang.reflect.Method,RecoverAnnotationRecoveryHandler.SimpleMetadata> |
methods |
private java.lang.Object |
target |
| Constructor and Description |
|---|
RecoverAnnotationRecoveryHandler(java.lang.Object target,
java.lang.reflect.Method method) |
| Modifier and Type | Method and Description |
|---|---|
private int |
calculateDistance(java.lang.Class<? extends java.lang.Throwable> cause,
java.lang.Class<? extends java.lang.Throwable> type) |
private java.lang.reflect.Method |
findClosestMatch(java.lang.Class<? extends java.lang.Throwable> cause) |
private void |
init(java.lang.Object target,
java.lang.reflect.Method method) |
T |
recover(java.lang.Object[] args,
java.lang.Throwable cause)
Recover gracefully from an error.
|
private SubclassClassifier<java.lang.Throwable,java.lang.reflect.Method> classifier
private java.util.Map<java.lang.reflect.Method,RecoverAnnotationRecoveryHandler.SimpleMetadata> methods
private java.lang.Object target
public RecoverAnnotationRecoveryHandler(java.lang.Object target,
java.lang.reflect.Method method)
public T recover(java.lang.Object[] args, java.lang.Throwable cause)
MethodInvocationRecovererrecover in interface MethodInvocationRecoverer<T>args - the arguments for the method invocation that failed.cause - the cause of the failure that led to this recovery.private java.lang.reflect.Method findClosestMatch(java.lang.Class<? extends java.lang.Throwable> cause)
private int calculateDistance(java.lang.Class<? extends java.lang.Throwable> cause,
java.lang.Class<? extends java.lang.Throwable> type)
private void init(java.lang.Object target,
java.lang.reflect.Method method)