Interface CircuitBreaker
public interface CircuitBreaker
A circuit breaker, which tracks the number of
success/failure requests and detects a remote service failure.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CircuitBreakerBuilder
builder()
Returns a newCircuitBreakerBuilder
.static CircuitBreakerBuilder
Returns a newCircuitBreakerBuilder
that has the specified name.boolean
Deprecated.Returns the currentCircuitState
.void
enterState
(CircuitState circuitState) Enters the specifiedCircuitState
.name()
Returns the name of the circuit breaker.static CircuitBreaker
Creates a newCircuitBreaker
that has the specified name and the default configurations.static CircuitBreaker
Creates a newCircuitBreaker
that has a default name and the default configurations.void
Reports a remote invocation failure.void
Reports a remote invocation success.default boolean
Decides whether a request should be sent or failed depending on the current circuit state.
-
Method Details
-
builder
Returns a newCircuitBreakerBuilder
. -
builder
Returns a newCircuitBreakerBuilder
that has the specified name.- Parameters:
name
- the name of the circuit breaker.
-
of
Creates a newCircuitBreaker
that has the specified name and the default configurations.- Parameters:
name
- the name of the circuit breaker
-
ofDefaultName
Creates a newCircuitBreaker
that has a default name and the default configurations. -
name
String name()Returns the name of the circuit breaker. -
onSuccess
void onSuccess()Reports a remote invocation success. -
onFailure
void onFailure()Reports a remote invocation failure. -
canRequest
Deprecated.UsetryRequest()
.Decides whether a request should be sent or failed depending on the current circuit state. -
tryRequest
default boolean tryRequest()Decides whether a request should be sent or failed depending on the current circuit state. If the current state isCircuitState.OPEN
andCircuitBreakerBuilder.circuitOpenWindow(Duration)
has passed, the state will enterCircuitState.HALF_OPEN
. -
circuitState
CircuitState circuitState()Returns the currentCircuitState
. -
enterState
Enters the specifiedCircuitState
. Note that even if theCircuitBreaker
is already in the specifiedCircuitState
, the internal state will be reinitialized. For instance, calling this method withCircuitState.OPEN
will always reset the timeout toCircuitBreakerBuilder.circuitOpenWindow(Duration)
.This method should be only used if users want extra control over the
CircuitBreaker
's state. Normally state transitions are handled internally.
-
tryRequest()
.