Interface TypedGuard<T>
- Type Parameters:
T- type of value of the guarded action
An instance of this interface represents a configured set of fault tolerance strategies. It can be used to
guard a Callable or Supplier invocation, or adapt an unguarded
Callable or Supplier to a guarded one.
The create(Class) methods return a builder that allows configuring the supported fault tolerance strategies.
Order of builder method invocations does not matter, the fault tolerance strategies are always applied
in a predefined order: fallback > retry > circuit breaker > rate limit > timeout > bulkhead >
thread offload > guarded action.
Note that bulkheads, circuit breakers and rate limits are stateful, so there's a big difference between guarding
multiple actions using the same TypedGuard object and using a separate TypedGuard object for each
action. Using a single TypedGuard instance to guard multiple actions means that a single bulkhead,
circuit breaker and/or rate limit will be shared among all those actions.
This API is essentially a programmatic equivalent to the declarative, annotation-based API of MicroProfile Fault Tolerance and SmallRye Fault Tolerance. It shares the set of fault tolerance strategies, their invocation order and behavior, their configuration properties, etc. Notable differences are:
- asynchronous actions of type
Futureare 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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA builder for configuring fault tolerance strategies. -
Method Summary
Modifier and TypeMethodDescriptionadaptCallable(Callable<T> action) Adapts givenactionto an action guarded by this configured set of fault tolerance strategies.adaptSupplier(Supplier<T> action) Adapts givenactionto an action guarded by this configured set of fault tolerance strategies.Calls givenactionand guards the call by this configured set of fault tolerance strategies.static <T> TypedGuard.Builder<T> create(jakarta.enterprise.util.TypeLiteral<T> type) Creates a builder for producing aTypedGuardobject representing a set of configured fault tolerance strategies that guard giventype.static <T> TypedGuard.Builder<T> Creates a builder for producing aTypedGuardobject representing a set of configured fault tolerance strategies that guard giventype.Calls givenactionand guards the call by this configured set of fault tolerance strategies.
-
Method Details
-
create
Creates a builder for producing aTypedGuardobject representing a set of configured fault tolerance strategies that guard giventype. It can be used to execute actions usingcall(Callable)orget(Supplier).The given
typeis also used to determine if the guarded actions are synchronous or asynchronous. Casting to another type is not possible. -
create
Creates a builder for producing aTypedGuardobject representing a set of configured fault tolerance strategies that guard giventype. It can be used to execute actions usingcall()orget().The given
typeis also used to determine if the guarded actions are synchronous or asynchronous. -
call
Calls givenactionand guards the call by this configured set of fault tolerance strategies.If this
TypedGuardinstance was created using a synchronous type, the action is synchronous and is always executed on the same thread that calls this method. If thisTypedGuardinstance was created using an asynchronous type, the action is asynchronous and may be offloaded to another thread depending on how the builder was configured.- Throws:
Exception
-
get
Calls givenactionand guards the call by this configured set of fault tolerance strategies.If this
TypedGuardinstance was created using a synchronous type, the action is synchronous and is always executed on the same thread that calls this method. If thisTypedGuardinstance was created using an asynchronous type, the action is asynchronous and may be offloaded to another thread depending on how the builder was configured. -
adaptCallable
Adapts givenactionto an action guarded by this configured set of fault tolerance strategies. Useful when the action has to be called multiple times.Equivalent to
() -> call(action).- See Also:
-
adaptSupplier
Adapts givenactionto an action guarded by this configured set of fault tolerance strategies. Useful when the action has to be called multiple times.Equivalent to
() -> get(action).- See Also:
-