Annotation Type ApplyGuard


@Inherited @Documented @Retention(RUNTIME) @Target({METHOD,TYPE}) @InterceptorBinding @Experimental("second attempt at providing reusable fault tolerance strategies") public @interface ApplyGuard
An interceptor binding annotation to apply preconfigured fault tolerance. If @ApplyGuard("<identifier>") is present on a business method, then a bean of type Guard or TypedGuard with qualifier @Identifier("<identifier>") must exist. Such bean serves as a preconfigured set of fault tolerance strategies and is used to guard invocations of the annotated business method(s).

It is customary to create such bean by declaring a static producer field. That removes all scoping concerns, because only one instance ever exists. Using a non-static producer field or a producer method means that scoping must be carefully considered, especially if stateful fault tolerance strategies are configured.

The @ApplyGuard annotation may also be present on a bean class, in which case it applies to all business methods declared by the class. If the annotation is present both on the method and the class declaring the method, the one on the method takes precedence.

When @ApplyGuard applies to a business method, all other fault tolerance annotations that would also apply to that method are ignored, except:

If @Fallback is present, it is used both by Guard and TypedGuard and it overrides the possible fallback configuration of TypedGuard. Further, the thread offload configuration of Guard or TypedGuard is ignored if the annotated method is asynchronous as determined from the method signature and possible annotations (@Asynchronous and @AsynchronousNonBlocking). The thread offload configuration of Guard or TypedGuard is only honored when the method cannot be determined to be asynchronous, but it still declares an asynchronous return type.

A single preconfigured fault tolerance can be applied to multiple methods. If the preconfigured fault tolerance is a TypedGuard, then all methods must have the same return type, which must be equal to the type the TypedGuard was created with. If the preconfigured fault tolerance is of type Guard, no such requirement applies.

Note that this annotation has the same differences to standard MicroProfile Fault Tolerance as Guard / TypedGuard:

  • asynchronous actions of type Future are not supported;
  • the fallback, circuit breaker and retry strategies always inspect the cause chain of exceptions, following the behavior of SmallRye Fault Tolerance in the non-compatible mode.
If multiple beans of type Guard or TypedGuard with the same identifier exist, a deployment problem occurs.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The identifier of a preconfigured Guard or TypedGuard instance.