Annotation Interface Fallback


The fallback annotation to define the fallback handler class so that a failure can be handled properly. Below is the criteria:
  1. If value is specified, use FallbackHandler.handle(ExecutionContext) on the specified handler to execute the fallback.
  2. If fallbackMethod is specified, invoke the method specified by the fallbackMethod on the same class.
  3. If both are specified, the FaultToleranceDefinitionException must be thrown.

When a method returns and the Fallback policy is present, the following rules are applied:

  1. If the method returns normally (doesn't throw), the result is simply returned.
  2. Otherwise, if the thrown object is assignable to any value in the skipOn() parameter, the thrown object will be rethrown.
  3. Otherwise, if the thrown object is assignable to any value in the applyOn() parameter, the Fallback policy, detailed above, will be applied.
  4. Otherwise the thrown object will be rethrown.
If a method throws a Throwable which is not an Error or Exception, non-portable behavior results.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Create a default class so the value is not required to be set all the time.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Class<? extends Throwable>[]
    The list of exception types which should trigger Fallback
    Specify the method name to be fallbacked to.
    Class<? extends Throwable>[]
    The list of exception types which should not trigger Fallback
    Class<? extends FallbackHandler<?>>
    Specify the fallback class to be used.
  • Element Details

    • value

      Class<? extends FallbackHandler<?>> value
      Specify the fallback class to be used. An 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 fallbackMethod
      Specify the method name to be fallbacked to. This method belongs to the same class as the method to fallback. The method must have the exactly 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

      Class<? extends Throwable>[] applyOn
      The list of exception types which should trigger Fallback

      Note that if a method throws a Throwable which is not an Error or Exception, non-portable behavior results.

      Returns:
      the exception types which should trigger Fallback
      Default:
      {java.lang.Throwable.class}
    • skipOn

      Class<? extends Throwable>[] skipOn
      The list of exception types which should not trigger Fallback

      This list takes priority over the types listed in applyOn()

      Note that if a method throws a Throwable which is not an Error or Exception, non-portable behavior results.

      Returns:
      the exception types which should not trigger Fallback
      Default:
      {}