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 CircuitBreakerBuilderbuilder()Returns a newCircuitBreakerBuilder.static CircuitBreakerBuilderReturns a newCircuitBreakerBuilderthat has the specified name.booleanDeprecated.Returns the currentCircuitState.voidenterState(CircuitState circuitState) Enters the specifiedCircuitState.name()Returns the name of the circuit breaker.static CircuitBreakerCreates a newCircuitBreakerthat has the specified name and the default configurations.static CircuitBreakerCreates a newCircuitBreakerthat has a default name and the default configurations.voidReports a remote invocation failure.voidReports a remote invocation success.default booleanDecides whether a request should be sent or failed depending on the current circuit state.
-
Method Details
-
builder
Returns a newCircuitBreakerBuilder. -
builder
Returns a newCircuitBreakerBuilderthat has the specified name.- Parameters:
name- the name of the circuit breaker.
-
of
Creates a newCircuitBreakerthat has the specified name and the default configurations.- Parameters:
name- the name of the circuit breaker
-
ofDefaultName
Creates a newCircuitBreakerthat 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.OPENandCircuitBreakerBuilder.circuitOpenWindow(Duration)has passed, the state will enterCircuitState.HALF_OPEN. -
circuitState
CircuitState circuitState()Returns the currentCircuitState. -
enterState
Enters the specifiedCircuitState. Note that even if theCircuitBreakeris already in the specifiedCircuitState, the internal state will be reinitialized. For instance, calling this method withCircuitState.OPENwill 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().