Class FaultToleranceUtils


  • public class FaultToleranceUtils
    extends Object
    Utility Methods for the Fault Tolerance Interceptors.
    Author:
    Andrew Pielage, Jan Bernitt (2.0)
    • Constructor Detail

      • FaultToleranceUtils

        public FaultToleranceUtils()
    • Method Detail

      • getAnnotation

        public static <A extends Annotation> A getAnnotation​(Stereotypes sterotypes,
                                                             Class<A> annotationClass,
                                                             jakarta.interceptor.InvocationContext context)
        Gets the annotation from the method that triggered the interceptor.
        Type Parameters:
        A - The annotation type to return
        Parameters:
        sterotypes - The invoking interceptor's context on sterotype annotations
        annotationClass - The class of the annotation to get
        context - The context of the method invocation
        Returns:
        The annotation that triggered the interceptor.
      • getOverrideValue

        public static <A extends Annotation,​T> T getOverrideValue​(org.eclipse.microprofile.config.Config config,
                                                                        Class<A> annotationType,
                                                                        String parameterName,
                                                                        jakarta.interceptor.InvocationContext context,
                                                                        Class<T> parameterType,
                                                                        T defaultValue)
        Gets overriding config parameter values if they're present from an invocation context.
        Type Parameters:
        A - The annotation type
        Parameters:
        config - The config to get the overriding parameter values from
        annotationType - The annotation class
        parameterName - The name of the parameter to get the override value of
        context - The context of the invoking request
        parameterType - The type of the parameter to get the override value of
        Returns:
      • getEnabledOverrideValue

        public static <A extends Annotation> boolean getEnabledOverrideValue​(org.eclipse.microprofile.config.Config config,
                                                                             Class<A> annotationType,
                                                                             jakarta.interceptor.InvocationContext context,
                                                                             boolean defaultValue)
        Gets overriding config enabled parameter value if it's present from an invocation context. This follows a different priority logic than other parameter overrides.
        Type Parameters:
        A - The annotation type
        Parameters:
        config - The config to get the overriding enabled value from
        annotationType - The annotation class
        context - The context of the invoking request
        Returns:
      • getAnnotatedMethodClass

        public static <A extends AnnotationClass<?> getAnnotatedMethodClass​(jakarta.interceptor.InvocationContext context,
                                                                              Class<A> annotationClass)
        Returns either the CDI Proxy class (for cases where a class extends another without overriding the target method), or the actual declaring class if the annotation isn't present on the proxy class.
        Type Parameters:
        A - The class of the annotation
        Parameters:
        context - The context of the method invocation
        annotationClass - The class of the annotation
        Returns:
        The class of the annotated method
      • getPlainCanonicalName

        public static <A extends AnnotationString getPlainCanonicalName​(Class<?> type)
        Helper method that gets the canonical name of an annotated class. This is used to strip out any Weld proxy naming that gets appended to the real class name.
        Type Parameters:
        A - The class of the annotation
        Parameters:
        type - The class of the annotation
        Returns:
        The canonical name of the annotated method's class
      • getCanonicalMethodName

        public static String getCanonicalMethodName​(jakarta.interceptor.InvocationContext context)
        Gets the full method signature from an invocation context, stripping out any Weld proxy name gubbins.
        Parameters:
        context - The context of the method invocation
        Returns:
        full canonical name of the method as in my.pack.MyClass.myMethod
      • isAnnotatedWithFaultToleranceAnnotations

        public static boolean isAnnotatedWithFaultToleranceAnnotations​(jakarta.enterprise.inject.spi.Annotated element)
      • toClassArray

        public static <T> Class<? extends T>[] toClassArray​(String classNames,
                                                            String attributeName,
                                                            Class<? extends T>[] defaultValue)