public final class FaultTolerancePolicy extends Object implements Serializable
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.| Modifier and Type | Field and Description |
|---|---|
AsynchronousPolicy |
asynchronous |
BulkheadPolicy |
bulkhead |
CircuitBreakerPolicy |
circuitBreaker |
FallbackPolicy |
fallback |
boolean |
isMetricsEnabled |
boolean |
isNonFallbackEnabled |
boolean |
isPresent |
RetryPolicy |
retry |
TimeoutPolicy |
timeout |
| Constructor and Description |
|---|
FaultTolerancePolicy(boolean isNonFallbackEnabled,
boolean isMetricsEnabled,
AsynchronousPolicy asynchronous,
BulkheadPolicy bulkhead,
CircuitBreakerPolicy circuitBreaker,
FallbackPolicy fallback,
RetryPolicy retry,
TimeoutPolicy timeout) |
| Modifier and Type | Method and Description |
|---|---|
static FaultTolerancePolicy |
asAnnotated(Class<?> target,
Method annotated) |
static void |
clean()
Removes all expired policies from the cache.
|
static FaultTolerancePolicy |
get(javax.interceptor.InvocationContext context,
Supplier<FaultToleranceConfig> configSpplier)
Returns the
FaultTolerancePolicy to use for the method invoked in the current context. |
boolean |
isAsynchronous() |
boolean |
isBulkheadPresent() |
boolean |
isCircuitBreakerPresent() |
boolean |
isFallbackPresent() |
boolean |
isRetryPresent() |
boolean |
isTimeoutPresent() |
Object |
proceed(javax.interceptor.InvocationContext context,
FaultToleranceService service)
Wraps
InvocationContext.proceed() with fault tolerance behaviour. |
public final boolean isPresent
public final boolean isNonFallbackEnabled
public final boolean isMetricsEnabled
public final AsynchronousPolicy asynchronous
public final BulkheadPolicy bulkhead
public final CircuitBreakerPolicy circuitBreaker
public final FallbackPolicy fallback
public final RetryPolicy retry
public final TimeoutPolicy timeout
public FaultTolerancePolicy(boolean isNonFallbackEnabled,
boolean isMetricsEnabled,
AsynchronousPolicy asynchronous,
BulkheadPolicy bulkhead,
CircuitBreakerPolicy circuitBreaker,
FallbackPolicy fallback,
RetryPolicy retry,
TimeoutPolicy timeout)
public static void clean()
public static FaultTolerancePolicy asAnnotated(Class<?> target, Method annotated)
public static FaultTolerancePolicy get(javax.interceptor.InvocationContext context, Supplier<FaultToleranceConfig> configSpplier) throws org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException
FaultTolerancePolicy to use for the method invoked in the current context.context - current contextconfigSpplier - supplies the configuration (if needed, in case returned policy needs to be created with help
of the FaultToleranceConfig)org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException - in case the effective policy contains illegal valuespublic boolean isAsynchronous()
public boolean isBulkheadPresent()
public boolean isCircuitBreakerPresent()
public boolean isFallbackPresent()
public boolean isRetryPresent()
public boolean isTimeoutPresent()
public Object proceed(javax.interceptor.InvocationContext context, FaultToleranceService service) throws Exception
InvocationContext.proceed() with fault tolerance behaviour.
Processing has 6 stages:
1) Asynchronous 2) Fallback 3) Retry 4) Circuit Breaker 5) Timeout 6) BulkheadThe 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).context - intercepted call contextservice - the environment used to execute the FT behaviourInvocationContext.proceed() after applying FT behaviourException - as thrown by the wrapped invocation or a FaultToleranceExceptionCopyright © 2019. All rights reserved.