Interface Guard.Builder.CircuitBreakerBuilder

Enclosing interface:
Guard.Builder

public static interface Guard.Builder.CircuitBreakerBuilder
Configures a circuit breaker.
See Also:
  • @CircuitBreaker
  • Method Details

    • failOn

      Sets the set of exception types considered failure. Defaults to all exceptions (Throwable).
      Parameters:
      value - collection of exception types, must not be null
      Returns:
      this circuit breaker builder
      See Also:
      • @CircuitBreaker.failOn
    • failOn

      Equivalent to failOn(Set.of(value)).
      Parameters:
      value - an exception class, must not be null
      Returns:
      this circuit breaker builder
    • skipOn

      Sets the set of exception types considered success. Defaults to no exception (empty set).
      Parameters:
      value - collection of exception types, must not be null
      Returns:
      this circuit breaker builder
      See Also:
      • @CircuitBreaker.skipOn
    • skipOn

      Equivalent to skipOn(Set.of(value)).
      Parameters:
      value - an exception class, must not be null
      Returns:
      this circuit breaker builder
    • when

      Sets a predicate to determine when an exception should be considered failure by the circuit breaker. This is a more general variant of failOn. Note that there is no generalized skipOn, because all exceptions that do not match this predicate are implicitly considered success.

      If this method is called, failOn and skipOn may not be called.

      Parameters:
      value - the predicate, must not be null
      Returns:
      this circuit breaker builder
    • delay

      Sets the delay after which an open circuit moves to half-open. Defaults to 5 seconds.
      Parameters:
      value - the delay length, must be >= 0
      unit - the delay unit, must not be null
      Returns:
      this circuit breaker builder
      See Also:
      • @CircuitBreaker.delay
      • @CircuitBreaker.delayUnit
    • requestVolumeThreshold

      Guard.Builder.CircuitBreakerBuilder requestVolumeThreshold(int value)
      Sets the size of the circuit breaker's rolling window.
      Parameters:
      value - the size of the circuit breaker's rolling window, must be >= 1
      Returns:
      this circuit breaker builder
      See Also:
      • @CircuitBreaker.requestVolumeThreshold
    • failureRatio

      Guard.Builder.CircuitBreakerBuilder failureRatio(double value)
      Sets the failure ratio that, once reached, will move a closed circuit breaker to open. Defaults to 0.5.
      Parameters:
      value - the failure ratio, must be >= 0 and <= 1
      Returns:
      this circuit breaker builder
      See Also:
      • @CircuitBreaker.failureRatio
    • successThreshold

      Guard.Builder.CircuitBreakerBuilder successThreshold(int value)
      Sets the number of successful executions that, once reached, will move a half-open circuit breaker to closed. Defaults to 1.
      Parameters:
      value - the number of successful executions, must be >= 1
      Returns:
      this circuit breaker builder
      See Also:
      • @CircuitBreaker.successThreshold
    • name

      Sets a circuit breaker name. Required to use the CircuitBreakerMaintenance methods. Defaults to unnamed. It is an error to use the same name for multiple circuit breakers.

      If a circuit breaker is not given a name, its state will not be affected by CircuitBreakerMaintenance.resetAll(). This is unlike unnamed circuit breakers declared using @CircuitBreaker, because there's a fixed number of circuit breakers created using the declarative API, but a potentially unbounded number of circuit breakers created using the programmatic API. In other words, automatically remembering all circuit breakers created using the programmatic API would easily lead to a memory leak.

      Parameters:
      value - the circuit breaker name, must not be null
      Returns:
      this circuit breaker builder
      See Also:
    • onStateChange

      Sets a callback that will be invoked upon each state change of this circuit breaker.

      The callback must be fast and non-blocking and must not throw an exception.

      Parameters:
      callback - the state change callback, must not be null
      Returns:
      this circuit breaker builder
    • onSuccess

      Sets a callback that will be invoked when this circuit breaker treats a finished invocation as success.

      The callback must be fast and non-blocking and must not throw an exception.

      Parameters:
      callback - the success callback, must not be null
      Returns:
      this circuit breaker builder
    • onFailure

      Sets a callback that will be invoked when this circuit breaker treats a finished invocation as failure.

      The callback must be fast and non-blocking and must not throw an exception.

      Parameters:
      callback - the failure callback, must not be null
      Returns:
      this circuit breaker builder
    • onPrevented

      Sets a callback that will be invoked when this circuit breaker prevents an invocation, because it is in the open or half-open state.

      The callback must be fast and non-blocking and must not throw an exception.

      Parameters:
      callback - the prevented callback, must not be null
      Returns:
      this circuit breaker builder
    • done

      Returns the original fault tolerance builder.
      Returns:
      the original fault tolerance builder
    • with