Package com.shri.restinpeace
Class CircuitBreakerConfig.Builder
java.lang.Object
com.shri.restinpeace.CircuitBreakerConfig.Builder
- Enclosing class:
- CircuitBreakerConfig
Builds a
CircuitBreakerConfig.-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the config.failureRateThreshold(int failureRateThreshold) Sets the failure-rate threshold that trips the breaker open.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).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.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. a404from an existence check, the same kind of outcome negative caching already treats as a valid answer rather than an error).slidingWindowSize(int size) Selects a count-based window ofsizecalls - the default shape.slidingWindowSize(Duration duration) Selects a time-based window of the lastduration- for a consumer who specifically wants "rate over the last N seconds regardless of call volume" rather than the count-based default.waitDurationInOpenState(Duration waitDurationInOpenState) Sets how long the breaker stays open before trialing recovery via a half-open state.
-
Method Details
-
slidingWindowSize
Selects a count-based window ofsizecalls - the default shape. Overrides any earlierslidingWindowSize(Duration)call.- Parameters:
size- the number of most-recent calls to track; must be at least 1- Returns:
- this builder
-
slidingWindowSize
Selects a time-based window of the lastduration- for a consumer who specifically wants "rate over the last N seconds regardless of call volume" rather than the count-based default. Overrides any earlierslidingWindowSize(int)call.- Parameters:
duration- how far back the window looks; must be positive- Returns:
- this builder
-
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
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
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
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. a404from 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
Builds the config.- Returns:
- the built config
-