Interface Guard.Builder

Enclosing interface:
Guard

public static interface Guard.Builder
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

      Guard.Builder 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, no metrics are emitted and a random UUID is used for other purposes.

      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
    • 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

      Guard.Builder withThreadOffload(boolean value)
      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

      Guard.Builder withThreadOffloadExecutor(Executor executor)
      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

      Guard build()
      Returns a ready-to-use instance of Guard.
    • with

      default Guard.Builder with(Consumer<Guard.Builder> consumer)
      Syntactic sugar for calling the builder methods conditionally without breaking the invocation chain. For example:
      
       Guard.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