Interface FaultTolerance.Builder.CircuitBreakerBuilder<T,​R>

  • Enclosing interface:
    FaultTolerance.Builder<T,​R>

    public static interface FaultTolerance.Builder.CircuitBreakerBuilder<T,​R>
    Configures a circuit breaker.
    See Also:
    @CircuitBreaker
    • Method Detail

      • failOn

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> failOn​(Collection<Class<? extends Throwable>> value)
        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
      • when

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> when​(Predicate<Throwable> value)
        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

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> delay​(long value,
                                                                      ChronoUnit unit)
        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

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> 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

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> 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

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> 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

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> name​(String value)
        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:
        @CircuitBreakerName
      • onStateChange

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> onStateChange​(Consumer<CircuitBreakerState> callback)
        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

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> onSuccess​(Runnable callback)
        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

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> onFailure​(Runnable callback)
        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

        FaultTolerance.Builder.CircuitBreakerBuilder<T,​R> onPrevented​(Runnable callback)
        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

        FaultTolerance.Builder<T,​R> done()
        Returns the original fault tolerance builder.
        Returns:
        the original fault tolerance builder