Annotation Interface Fallback
@Documented
@Retention(RUNTIME)
@Target(METHOD)
@Inherited
@InterceptorBinding
public @interface Fallback
The fallback annotation to define the fallback handler class so that
a failure can be handled properly. The criteria are as follows:
- If value is specified, use
FallbackHandler.handle(ExecutionContext)
on the specified handler to execute the fallback. - If fallbackMethod is specified, invoke the method specified by the fallbackMethod on the same class.
- If both are specified, the
FaultToleranceDefinitionException
must be thrown.
When a method returns and the fallback policy is present, the following rules are applied:
- If the method returns normally (doesn't throw), the result is simply returned.
- Otherwise, if the thrown object is assignable to any value in the
skipOn()
parameter, the thrown object will be rethrown. - Otherwise, if the thrown object is assignable to any value in the
applyOn()
parameter, the fallback policy, detailed above, will be applied. - Otherwise the thrown object will be rethrown.
Throwable
which is not an Error
or Exception
, non-portable behavior results.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Create a default class so the value is not required to be set all the time. -
Optional Element Summary
Modifier and TypeOptional ElementDescriptionThe list of exception types which should trigger FallbackSpecify the method name to fallback to.The list of exception types which should not trigger FallbackClass<? extends FallbackHandler<?>>
Specify the fallback class to be used.
-
Element Details
-
value
Class<? extends FallbackHandler<?>> valueSpecify the fallback class to be used. A new instance of the fallback class is returned. The instance is unmanaged. The type parameter of the fallback class must be assignable to the return type of the annotated method. Otherwise,FaultToleranceDefinitionException
occurs.- Returns:
- the fallback class
- Default:
- org.eclipse.microprofile.faulttolerance.Fallback.DEFAULT.class
-
fallbackMethod
String fallbackMethodSpecify the method name to fallback to. This method belongs to the same class as the method to fallback. The method must have the exact same arguments as the method being annotated. The method return type must be assignable to the return type of the method the fallback is for. Otherwise,FaultToleranceDefinitionException
must be thrown.- Returns:
- the local method to fallback to
- Default:
- ""
-
applyOn
The list of exception types which should trigger FallbackNote that if a method throws a
Throwable
which is not anError
orException
, non-portable behavior results.- Returns:
- the exception types which should trigger Fallback
- Default:
- {java.lang.Throwable.class}
-
skipOn
The list of exception types which should not trigger FallbackThis list takes priority over the types listed in
applyOn()
Note that if a method throws a
Throwable
which is not anError
orException
, non-portable behavior results.- Returns:
- the exception types which should not trigger Fallback
- Default:
- {}
-