Interface FallbackHandler<T>

  • All Known Implementing Classes:
    Fallback.DEFAULT

    public interface FallbackHandler<T>
    The handler instance used by the container to service a fallback invocation is a non-contextual instance created using the CDI SPI. The instance exists to service a single invocation only. The type parameter of the handler instance must be assignable to the return type of the method, where the Fallback is specified. The container must ensure this type safety. Otherwise, IllegalArgumentException should be thrown.

    Usage

     public class MyService {
      @Inject OtherService otherService;
     
      @Timeout(3000)
      @Fallback(MyFallback.class) 
      Long getAmount() {
          return otherService.getAmount() * 2;
      }
    }
    
    The fallback handler implementation is shown below. The type parameter must be assignable to Long.
     public class MyFallback implements FallbackHandler<Long> {
     Long handle(ExecutionContext context) {
       return 42;
     }
    }
    
    • Method Detail

      • handle

        T handle​(ExecutionContext context)
        Handle the previous calling failure and then call alternative methods or perform any alternative operations.
        Parameters:
        context - the execution context
        Returns:
        the result of the fallback