Package io.github.resilience4j.fallback
Class FallbackMethod
java.lang.Object
io.github.resilience4j.fallback.FallbackMethod
Reflection 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 of
Throwable
. When fallback(Throwable)
is invoked, Throwable
will 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 methodsString 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
-
Method Details
-
create
public static FallbackMethod create(String fallbackMethodName, Method originalMethod, Object[] args, Object target) throws 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:
NoSuchMethodException
-
fallback
try to fallback fromThrowable
-
getReturnType
get return type of fallbackMethod method- Returns:
- return type of fallbackMethod method
-