R
- result typepublic class CircuitBreakerBuilder<R> extends DelayablePolicyBuilder<CircuitBreakerBuilder<R>,CircuitBreakerConfig<R>,R> implements PolicyListeners<CircuitBreakerBuilder<R>,R>
CircuitBreaker
instances.
handle
conditions. The default exception handling condition will only be overridden by
another condition that handles exceptions such as FailurePolicyBuilder.handle(Class)
or FailurePolicyBuilder.handleIf(CheckedBiPredicate)
.
Specifying a condition that only handles results, such as FailurePolicyBuilder.handleResult(Object)
or
FailurePolicyBuilder.handleResultIf(CheckedPredicate)
will not replace the default exception handling condition.handle
conditions are specified, any condition that matches an execution result or exception
will trigger policy handling.Note:
DelayablePolicyBuilder
and FailurePolicyBuilder
which offer additional configuration.config
Modifier and Type | Method and Description |
---|---|
CircuitBreaker<R> |
build()
Builds a new
CircuitBreaker using the builder's configuration. |
CircuitBreakerBuilder<R> |
onClose(EventListener<CircuitBreakerStateChangedEvent> listener)
Calls the
listener when the circuit is closed. |
CircuitBreakerBuilder<R> |
onHalfOpen(EventListener<CircuitBreakerStateChangedEvent> listener)
Calls the
listener when the circuit is half-opened. |
CircuitBreakerBuilder<R> |
onOpen(EventListener<CircuitBreakerStateChangedEvent> listener)
Calls the
listener when the circuit is opened. |
CircuitBreakerBuilder<R> |
withDelay(Duration delay)
Sets the
delay to wait in OPEN state before transitioning to half-open. |
CircuitBreakerBuilder<R> |
withFailureRateThreshold(int failureRateThreshold,
int failureExecutionThreshold,
Duration failureThresholdingPeriod)
Configures time based failure rate thresholding by setting the percentage rate of failures, from 1 to 100, that
must occur within the rolling
failureThresholdingPeriod when in a CLOSED state in order to open the
circuit. |
CircuitBreakerBuilder<R> |
withFailureThreshold(int failureThreshold)
Configures count based failure thresholding by setting the number of consecutive failures that must occur when in a
CLOSED state in order to open the circuit.
|
CircuitBreakerBuilder<R> |
withFailureThreshold(int failureThreshold,
Duration failureThresholdingPeriod)
Configures time based failure thresholding by setting the number of failures that must occur within the
failureThresholdingPeriod when in a CLOSED state in order to open the circuit. |
CircuitBreakerBuilder<R> |
withFailureThreshold(int failureThreshold,
int failureThresholdingCapacity)
Configures count based failure thresholding by setting the ratio of failures to executions that must occur when in
a CLOSED state in order to open the circuit.
|
CircuitBreakerBuilder<R> |
withFailureThreshold(int failureThreshold,
int failureExecutionThreshold,
Duration failureThresholdingPeriod)
Configures time based failure thresholding by setting the number of failures that must occur within the
failureThresholdingPeriod when in a CLOSED state in order to open the circuit. |
CircuitBreakerBuilder<R> |
withSuccessThreshold(int successThreshold)
Configures count based success thresholding by setting the number of consecutive successful executions that must
occur when in a HALF_OPEN state in order to close the circuit, else the circuit is re-opened when a failure
occurs.
|
CircuitBreakerBuilder<R> |
withSuccessThreshold(int successThreshold,
int successThresholdingCapacity)
Configures count based success thresholding by setting the ratio of successful executions that must occur when in a
HALF_OPEN state in order to close the circuit.
|
withDelayFn, withDelayFnOn, withDelayFnWhen
handle, handle, handle, handleIf, handleIf, handleResult, handleResultIf
onFailure, onSuccess
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onFailure, onSuccess
public CircuitBreaker<R> build()
CircuitBreaker
using the builder's configuration.public CircuitBreakerBuilder<R> onClose(EventListener<CircuitBreakerStateChangedEvent> listener)
listener
when the circuit is closed.
Note: Any exceptions that are thrown from within the listener
are ignored.
NullPointerException
- if listener
is nullpublic CircuitBreakerBuilder<R> onHalfOpen(EventListener<CircuitBreakerStateChangedEvent> listener)
listener
when the circuit is half-opened.
Note: Any exceptions that are thrown within the listener
are ignored.
NullPointerException
- if listener
is nullpublic CircuitBreakerBuilder<R> onOpen(EventListener<CircuitBreakerStateChangedEvent> listener)
listener
when the circuit is opened.
Note: Any exceptions that are thrown within the listener
are ignored.
NullPointerException
- if listener
is nullpublic CircuitBreakerBuilder<R> withDelay(Duration delay)
delay
to wait in OPEN state before transitioning to half-open.withDelay
in class DelayablePolicyBuilder<CircuitBreakerBuilder<R>,CircuitBreakerConfig<R>,R>
NullPointerException
- if delay
is nullIllegalArgumentException
- if delay
< 0public CircuitBreakerBuilder<R> withFailureThreshold(int failureThreshold)
If a success threshold
is not configured, the failureThreshold
will also
be used when the circuit breaker is in a HALF_OPEN state to determine whether to transition back to OPEN or
CLOSED.
failureThreshold
- The number of consecutive failures that must occur in order to open the circuitIllegalArgumentException
- if failureThreshold
< 1CircuitBreakerConfig.getFailureThreshold()
public CircuitBreakerBuilder<R> withFailureThreshold(int failureThreshold, int failureThresholdingCapacity)
If a success threshold
is not configured, the failureThreshold
and
failureThresholdingCapacity
will also be used when the circuit breaker is in a HALF_OPEN state to determine
whether to transition back to OPEN or CLOSED.
failureThreshold
- The number of failures that must occur in order to open the circuitfailureThresholdingCapacity
- The capacity for storing execution results when performing failure thresholdingIllegalArgumentException
- if failureThreshold
< 1, failureThresholdingCapacity
< 1, or
failureThreshold
> failureThresholdingCapacity
CircuitBreakerConfig.getFailureThreshold()
,
CircuitBreakerConfig.getFailureExecutionThreshold()
public CircuitBreakerBuilder<R> withFailureThreshold(int failureThreshold, Duration failureThresholdingPeriod)
failureThresholdingPeriod
when in a CLOSED state in order to open the circuit.
If a success threshold
is not configured, the failureThreshold
will also
be used when the circuit breaker is in a HALF_OPEN state to determine whether to transition back to OPEN or
CLOSED.
failureThreshold
- The number of failures that must occur within the failureThresholdingPeriod
in
order to open the circuitfailureThresholdingPeriod
- The period during which failures are compared to the failureThreshold
NullPointerException
- if failureThresholdingPeriod
is nullIllegalArgumentException
- if failureThreshold
< 1 or failureThresholdingPeriod
< 10 msCircuitBreakerConfig.getFailureThreshold()
,
CircuitBreakerConfig.getFailureThresholdingPeriod()
public CircuitBreakerBuilder<R> withFailureThreshold(int failureThreshold, int failureExecutionThreshold, Duration failureThresholdingPeriod)
failureThresholdingPeriod
when in a CLOSED state in order to open the circuit. The number of executions must also
exceed the failureExecutionThreshold
within the failureThresholdingPeriod
when in the CLOSED state
before the circuit can be opened.
If a success threshold
is not configured, the failureThreshold
will also
be used when the circuit breaker is in a HALF_OPEN state to determine whether to transition back to OPEN or
CLOSED.
failureThreshold
- The number of failures that must occur within the failureThresholdingPeriod
in
order to open the circuitfailureExecutionThreshold
- The minimum number of executions that must occur within the failureThresholdingPeriod
when in the CLOSED state before the circuit can be openedfailureThresholdingPeriod
- The period during which failures are compared to the failureThreshold
NullPointerException
- if failureThresholdingPeriod
is nullIllegalArgumentException
- if failureThreshold
< 1, failureExecutionThreshold
< 1, failureThreshold
> failureExecutionThreshold
, or failureThresholdingPeriod
< 10 msCircuitBreakerConfig.getFailureThreshold()
,
CircuitBreakerConfig.getFailureExecutionThreshold()
,
CircuitBreakerConfig.getFailureThresholdingPeriod()
public CircuitBreakerBuilder<R> withFailureRateThreshold(int failureRateThreshold, int failureExecutionThreshold, Duration failureThresholdingPeriod)
failureThresholdingPeriod
when in a CLOSED state in order to open the
circuit. The number of executions must also exceed the failureExecutionThreshold
within the failureThresholdingPeriod
before the circuit can be opened.
If a success threshold
is not configured, the failureExecutionThreshold
will also be used when the circuit breaker is in a HALF_OPEN state to determine whether to transition back to open
or closed.
failureRateThreshold
- The percentage rate of failures, from 1 to 100, that must occur in order to open the
circuitfailureExecutionThreshold
- The minimum number of executions that must occur within the failureThresholdingPeriod
when in the CLOSED state before the circuit can be opened, or in the HALF_OPEN state
before it can be re-opened or closedfailureThresholdingPeriod
- The period during which failures are compared to the failureThreshold
NullPointerException
- if failureThresholdingPeriod
is nullIllegalArgumentException
- if failureRateThreshold
< 1 or > 100, failureExecutionThreshold
<
1, or failureThresholdingPeriod
< 10 msCircuitBreakerConfig.getFailureRateThreshold()
,
CircuitBreakerConfig.getFailureExecutionThreshold()
,
CircuitBreakerConfig.getFailureThresholdingPeriod()
public CircuitBreakerBuilder<R> withSuccessThreshold(int successThreshold)
successThreshold
- The number of consecutive successful executions that must occur in order to open the
circuitIllegalArgumentException
- if successThreshold
< 1CircuitBreakerConfig.getSuccessThreshold()
public CircuitBreakerBuilder<R> withSuccessThreshold(int successThreshold, int successThresholdingCapacity)
successThreshold
- The number of successful executions that must occur in order to open the circuitsuccessThresholdingCapacity
- The capacity for storing execution results when performing success thresholdingIllegalArgumentException
- if successThreshold
< 1, successThresholdingCapacity
< 1, or
successThreshold
> successThresholdingCapacity
CircuitBreakerConfig.getSuccessThreshold()
,
CircuitBreakerConfig.getSuccessThresholdingCapacity()
Copyright © 2022. All rights reserved.