Class CircuitBreakerConfig.Builder

java.lang.Object
com.shri.restinpeace.CircuitBreakerConfig.Builder
Enclosing class:
CircuitBreakerConfig

public static final class CircuitBreakerConfig.Builder extends Object
  • Method Details

    • slidingWindowSize

      public CircuitBreakerConfig.Builder slidingWindowSize(int size)
      Selects a count-based window of size calls - the default shape. Overrides any earlier slidingWindowSize(Duration) call.
      Parameters:
      size - the number of most-recent calls to track; must be at least 1
      Returns:
      this builder
    • slidingWindowSize

      public CircuitBreakerConfig.Builder slidingWindowSize(Duration duration)
      Selects a time-based window of the last duration - for a consumer who specifically wants "rate over the last N seconds regardless of call volume" rather than the count-based default. Overrides any earlier slidingWindowSize(int) call.
      Parameters:
      duration - how far back the window looks; must be positive
      Returns:
      this builder
    • minimumNumberOfCalls

      public CircuitBreakerConfig.Builder minimumNumberOfCalls(int minimumNumberOfCalls)
      Sets the minimum number of calls that must be in the window before a failure rate is ever evaluated, so the breaker never trips off a statistically meaningless sample (e.g. 1 failure out of 2 calls is technically 50%, but shouldn't trip a breaker tuned for a 20-call window).
      Parameters:
      minimumNumberOfCalls - the minimum sample size; must be at least 1
      Returns:
      this builder
    • failureRateThreshold

      public CircuitBreakerConfig.Builder failureRateThreshold(int failureRateThreshold)
      Sets the failure-rate threshold that trips the breaker open.
      Parameters:
      failureRateThreshold - the failure rate, as a percentage from 1 to 100
      Returns:
      this builder
    • waitDurationInOpenState

      public CircuitBreakerConfig.Builder waitDurationInOpenState(Duration waitDurationInOpenState)
      Sets how long the breaker stays open before trialing recovery via a half-open state.
      Parameters:
      waitDurationInOpenState - the open-state cooldown; must be positive
      Returns:
      this builder
    • permittedCallsInHalfOpenState

      public CircuitBreakerConfig.Builder permittedCallsInHalfOpenState(int permittedCallsInHalfOpenState)
      Sets how many trial calls are let through while half-open, once the open-state cooldown elapses, before deciding whether to close (recovered) or re-open (still failing) based on their own failure rate.
      Parameters:
      permittedCallsInHalfOpenState - the number of trial calls; must be at least 1
      Returns:
      this builder
    • recordFailureForStatus

      public CircuitBreakerConfig.Builder recordFailureForStatus(IntPredicate recordFailureForStatus)
      Sets which HTTP status codes count as a breaker failure - a genuine downstream failure (5xx, the default), not an application-level expected outcome (e.g. a 404 from an existence check, the same kind of outcome negative caching already treats as a valid answer rather than an error). A transport-level failure (connection refused, timeout - no response at all) always counts as a failure regardless of this predicate, since there's no status code to test it against.
      Parameters:
      recordFailureForStatus - the status-code failure predicate
      Returns:
      this builder
    • build

      public CircuitBreakerConfig build()
      Builds the config.
      Returns:
      the built config