Package io.smallrye.faulttolerance.api
Interface TypedGuard.Builder<T>
- Type Parameters:
T- type of value of the guarded action
- Enclosing interface:
TypedGuard<T>
public static interface TypedGuard.Builder<T>
A builder for configuring fault tolerance strategies. A fault tolerance strategy is included in the resulting
set if the corresponding
with[Strategy] method is called. Each strategy has its own builder to configure
the necessary attributes, and each such builder has a done() method that returns back to this builder.
In general, all builders in this API accept multiple invocations of the same method, but only the last invocation is meaningful. Any previous invocations are forgotten.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceConfigures a bulkhead.static interfaceConfigures a circuit breaker.static interfaceConfigures a fallback.static interfaceConfigures a rate limit.static interfaceConfigures a retry.static interfaceConfigures a timeout. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Returns a ready-to-use instance ofTypedGuard.default TypedGuard.Builder<T> with(Consumer<TypedGuard.Builder<T>> consumer) Syntactic sugar for calling the builder methods conditionally without breaking the invocation chain.Adds a bulkhead strategy.Adds a circuit breaker strategy.withDescription(String value) Assigns a description to the resulting set of configured fault tolerance strategies.Adds a fallback strategy.Adds a rate limit strategy.Adds a retry strategy.withThreadOffload(boolean value) Configures whether an asynchronous guarded action should be offloaded to another thread.withThreadOffloadExecutor(Executor executor) Configures the executor to use when offloading the guarded action to another thread.Adds a timeout strategy.
-
Method Details
-
withDescription
Assigns a description to the resulting set of configured fault tolerance strategies. The description is used in logging messages and exception messages, and also as an identifier for metrics.The description may be an arbitrary string. Duplicates are permitted.
If no description is set, no metrics are emitted and a random UUID is used for other purposes.
- Parameters:
value- a description, must not benull- Returns:
- this fault tolerance builder
-
withBulkhead
TypedGuard.Builder.BulkheadBuilder<T> withBulkhead()Adds a bulkhead strategy. In this API, bulkhead is a simple concurrency limiter.- Returns:
- a builder to configure the bulkhead strategy
- See Also:
-
withCircuitBreaker
TypedGuard.Builder.CircuitBreakerBuilder<T> withCircuitBreaker()Adds a circuit breaker strategy.- Returns:
- a builder to configure the circuit breaker strategy
- See Also:
-
withFallback
TypedGuard.Builder.FallbackBuilder<T> withFallback()Adds a fallback strategy.- Returns:
- a builder to configure the fallback strategy
- See Also:
-
withRateLimit
TypedGuard.Builder.RateLimitBuilder<T> withRateLimit()Adds a rate limit strategy.- Returns:
- a builder to configure the rate limit strategy
- See Also:
-
withRetry
TypedGuard.Builder.RetryBuilder<T> withRetry()Adds a retry strategy. Retry uses constant backoff between attempts by default, but may be configured to use exponential backoff, Fibonacci backoff, or custom backoff.- Returns:
- a builder to configure the retry strategy
- See Also:
-
withTimeout
TypedGuard.Builder.TimeoutBuilder<T> withTimeout()Adds a timeout strategy.- Returns:
- a builder to configure the timeout strategy
- See Also:
-
withThreadOffload
Configures whether an asynchronous guarded action should be offloaded to another thread.- Parameters:
value- whether an asynchronous guarded action should be offloaded to another thread- Returns:
- this fault tolerance builder
- See Also:
-
withThreadOffloadExecutor
Configures the executor to use when offloading the guarded action to another thread.If this method is not called but thread offload is enabled using
withThreadOffload(boolean), an asynchronous guarded action is offloaded to the default executor provided by the integrator.- Parameters:
executor- the executor to which the guarded action should be offloaded- Returns:
- this fault tolerance builder
-
build
TypedGuard<T> build()Returns a ready-to-use instance ofTypedGuard. -
with
Syntactic sugar for calling the builder methods conditionally without breaking the invocation chain. For example:TypedGuard.create(...) .withRetry() ... .done() .with(builder -> { if (useTimeout) { builder.withTimeout() ... .done(); } }) .build();- Parameters:
consumer- block of code to execute with this builder- Returns:
- this fault tolerance builder
-