Class FaultTolerancePolicy
- java.lang.Object
-
- fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy
-
- All Implemented Interfaces:
Serializable
public final class FaultTolerancePolicy extends Object implements Serializable
TheFaultTolerancePolicy
describes the effective aggregated policies to use for a particularMethod
when adding fault tolerant behaviour to it. The policies are extracted from FT annotations and theFaultToleranceConfig
. 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
-
-
Field Summary
Fields Modifier and Type Field Description AsynchronousPolicy
asynchronous
BulkheadPolicy
bulkhead
CircuitBreakerPolicy
circuitBreaker
FallbackPolicy
fallback
boolean
isMetricsEnabled
boolean
isNonFallbackEnabled
boolean
isPresent
RetryPolicy
retry
TimeoutPolicy
timeout
-
Constructor Summary
Constructors Constructor Description FaultTolerancePolicy(boolean isNonFallbackEnabled, boolean isMetricsEnabled, AsynchronousPolicy asynchronous, BulkheadPolicy bulkhead, CircuitBreakerPolicy circuitBreaker, FallbackPolicy fallback, RetryPolicy retry, TimeoutPolicy timeout)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FaultTolerancePolicy
asAnnotated(Class<?> target, Method annotated)
static void
clean()
Removes all expired policies from the cache.static void
clean(ClassLoader appClassLoader)
Removes all expired policies from the cache and all policies related to this classloaderstatic FaultTolerancePolicy
get(jakarta.interceptor.InvocationContext context, Supplier<FaultToleranceConfig> configSpplier)
Returns theFaultTolerancePolicy
to use for the method invoked in the current context.boolean
isAsynchronous()
boolean
isBulkheadPresent()
boolean
isCircuitBreakerPresent()
boolean
isFallbackPresent()
boolean
isRetryPresent()
boolean
isTimeoutPresent()
Object
proceed(jakarta.interceptor.InvocationContext context, Supplier<FaultToleranceMethodContext> ftmContextSupplier)
WrapsInvocationContext.proceed()
with fault tolerance behaviour.
-
-
-
Field Detail
-
isPresent
public final boolean isPresent
-
isNonFallbackEnabled
public final boolean isNonFallbackEnabled
-
isMetricsEnabled
public final boolean isMetricsEnabled
-
asynchronous
public final AsynchronousPolicy asynchronous
-
bulkhead
public final BulkheadPolicy bulkhead
-
circuitBreaker
public final CircuitBreakerPolicy circuitBreaker
-
fallback
public final FallbackPolicy fallback
-
retry
public final RetryPolicy retry
-
timeout
public final TimeoutPolicy timeout
-
-
Constructor Detail
-
FaultTolerancePolicy
public FaultTolerancePolicy(boolean isNonFallbackEnabled, boolean isMetricsEnabled, AsynchronousPolicy asynchronous, BulkheadPolicy bulkhead, CircuitBreakerPolicy circuitBreaker, FallbackPolicy fallback, RetryPolicy retry, TimeoutPolicy timeout)
-
-
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
-
asAnnotated
public static FaultTolerancePolicy asAnnotated(Class<?> target, Method annotated)
-
get
public static FaultTolerancePolicy get(jakarta.interceptor.InvocationContext context, Supplier<FaultToleranceConfig> configSpplier) throws org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException
Returns theFaultTolerancePolicy
to use for the method invoked in the current context.- Parameters:
context
- current contextconfigSpplier
- supplies the configuration (if needed, in case returned policy needs to be created with help of theFaultToleranceConfig
)- 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
WrapsInvocationContext.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 theFaultToleranceService#runAsynchronous(CompletableFuture, Callable)
.- Parameters:
context
- intercepted call contextftmContextSupplier
- 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 aFaultToleranceException
-
-