Package io.github.resilience4j.fallback
Class FallbackMethod
- java.lang.Object
-
- io.github.resilience4j.fallback.FallbackMethod
-
public class FallbackMethod extends java.lang.ObjectReflection utility for invoking a fallback method. Fallback method should have same return type and parameter types of original method but the last additional parameter. The last additional parameter should be a subclass ofThrowable. Whenfallback(Throwable)is invoked,Throwablewill be passed to that last parameter. If there are multiple fallback method, one of the methods that has most closest superclass parameter of thrown object will be invoked.For example, there are two fallback methods
String fallbackMethod(String parameter, RuntimeException exception) String fallbackMethod(String parameter, IllegalArgumentException exception)and if try to fallback fromNumberFormatException,String fallbackMethod(String parameter, IllegalArgumentException exception)will be invoked.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FallbackMethodcreate(java.lang.String fallbackMethodName, java.lang.reflect.Method originalMethod, java.lang.Object[] args, java.lang.Object target)java.lang.Objectfallback(java.lang.Throwable thrown)try to fallback fromThrowablejava.lang.Class<?>getReturnType()get return type of fallbackMethod method
-
-
-
Method Detail
-
create
public static FallbackMethod create(java.lang.String fallbackMethodName, java.lang.reflect.Method originalMethod, java.lang.Object[] args, java.lang.Object target) throws java.lang.NoSuchMethodException
- Parameters:
fallbackMethodName- the configured fallback method nameoriginalMethod- the original method which has fallback method configuredargs- the original method argumentstarget- the target class that own the original method and fallback method- Returns:
- FallbackMethod instance
- Throws:
java.lang.NoSuchMethodException
-
fallback
@Nullable public java.lang.Object fallback(java.lang.Throwable thrown) throws java.lang.Throwabletry to fallback fromThrowable- Parameters:
thrown-Throwablethat should be fallback- Returns:
- fallback value
- Throws:
java.lang.Throwable- if throwable is unrecoverable, throwable will be thrown
-
getReturnType
public java.lang.Class<?> getReturnType()
get return type of fallbackMethod method- Returns:
- return type of fallbackMethod method
-
-