Interface FaultTolerance.Builder<T,R>

Type Parameters:
T - type of value of the guarded action
R - type of result of this builder, depends on how this builder was created
Enclosing interface:
FaultTolerance<T>

public static interface FaultTolerance.Builder<T,R>
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.

  • Method Details

    • withDescription

      FaultTolerance.Builder<T,R> withDescription(String value)
      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, a random UUID is used.

      Parameters:
      value - a description, must not be null
      Returns:
      this fault tolerance builder
    • withBulkhead

      Adds a bulkhead strategy. In this API, bulkhead is a simple concurrency limiter.
      Returns:
      a builder to configure the bulkhead strategy
      See Also:
      • @Bulkhead
    • withCircuitBreaker

      Adds a circuit breaker strategy.
      Returns:
      a builder to configure the circuit breaker strategy
      See Also:
      • @CircuitBreaker
    • withFallback

      Adds a fallback strategy.
      Returns:
      a builder to configure the fallback strategy
      See Also:
      • @Fallback
    • withRateLimit

      Adds a rate limit strategy.
      Returns:
      a builder to configure the rate limit strategy
      See Also:
    • 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:
      • @Retry
    • withTimeout

      Adds a timeout strategy.
      Returns:
      a builder to configure the timeout strategy
      See Also:
      • @Timeout
    • withThreadOffload

      FaultTolerance.Builder<T,R> withThreadOffload(boolean value)
      Configures whether the guarded action should be offloaded to another thread. Thread offload is only possible for asynchronous actions. If this builder was not created using createAsync, attempting to enable thread offload throws an exception.
      Parameters:
      value - whether the guarded action should be offloaded to another thread
      Returns:
      this fault tolerance builder
      See Also:
    • withThreadOffloadExecutor

      FaultTolerance.Builder<T,R> withThreadOffloadExecutor(Executor executor)
      Configures the executor to use when offloading the guarded action to another thread. Thread offload is only possible for asynchronous actions. If this builder was not created using createAsync, this method throws an exception.

      If this method is not called, the 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

      R build()
      Returns a ready-to-use instance of FaultTolerance or guarded Callable, depending on how this builder was created.
    • with

      Syntactic sugar for calling the builder methods conditionally without breaking the invocation chain. For example:
      
       FaultTolerance.create(this::doSomething)
           .withFallback() ... .done()
           .with(builder -> {
               if (useTimeout) {
                   builder.withTimeout() ... .done();
               }
           })
           .build();
       
      Parameters:
      consumer - block of code to execute with this builder
      Returns:
      this fault tolerance builder