Class FaultTolerancePolicy

  • All Implemented Interfaces:
    Serializable

    public final class FaultTolerancePolicy
    extends Object
    implements Serializable
    The FaultTolerancePolicy describes the effective aggregated policies to use for a particular Method when adding fault tolerant behaviour to it. The policies are extracted from FT annotations and the FaultToleranceConfig. In contrast to the plain annotations the policies do consider configuration overrides and include validation of the effective values. The policy class also reduces the need to analyse FT annotations for each invocation and works as a consistent source of truth throughout the processing of FT behaviour that is convenient to pass around as a single immutable value.
    Author:
    Jan Bernitt
    See Also:
    Serialized Form
    • Method Detail

      • clean

        public static void clean()
        Removes all expired policies from the cache.
      • clean

        public static void clean​(ClassLoader appClassLoader)
        Removes all expired policies from the cache and all policies related to this classloader
      • get

        public static FaultTolerancePolicy get​(jakarta.interceptor.InvocationContext context,
                                               Supplier<FaultToleranceConfig> configSpplier)
                                        throws org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException
        Returns the FaultTolerancePolicy to use for the method invoked in the current context.
        Parameters:
        context - current context
        configSpplier - supplies the configuration (if needed, in case returned policy needs to be created with help of the FaultToleranceConfig)
        Returns:
        the policy to apply
        Throws:
        org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException - in case the effective policy contains illegal values
      • isAsynchronous

        public boolean isAsynchronous()
      • isBulkheadPresent

        public boolean isBulkheadPresent()
      • isCircuitBreakerPresent

        public boolean isCircuitBreakerPresent()
      • isFallbackPresent

        public boolean isFallbackPresent()
      • isRetryPresent

        public boolean isRetryPresent()
      • isTimeoutPresent

        public boolean isTimeoutPresent()
      • proceed

        public Object proceed​(jakarta.interceptor.InvocationContext context,
                              Supplier<FaultToleranceMethodContext> ftmContextSupplier)
                       throws Exception
        Wraps InvocationContext.proceed() with fault tolerance behaviour. Processing has 6 stages:
         1) Asynchronous
         2) Fallback
         3) Retry
         4) Circuit Breaker
         5) Timeout
         6) Bulkhead
         
        The call chain goes from 1) down to 6) skipping stages that are not requested by this policy. Asynchronous execution branches to new threads in stage 1) and 3) each executed by the FaultToleranceService#runAsynchronous(CompletableFuture, Callable).
        Parameters:
        context - intercepted call context
        ftmContextSupplier - the environment used to execute the FT behaviour
        Returns:
        the result of InvocationContext.proceed() after applying FT behaviour
        Throws:
        Exception - as thrown by the wrapped invocation or a FaultToleranceException